summaryrefslogtreecommitdiff
path: root/modules/simpletest
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest')
-rw-r--r--modules/simpletest/drupal_web_test_case.php54
-rw-r--r--modules/simpletest/tests/common.test8
-rw-r--r--modules/simpletest/tests/file.test28
-rw-r--r--modules/simpletest/tests/session.test2
4 files changed, 54 insertions, 38 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 59413e584..09c192376 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -424,29 +424,26 @@ abstract class DrupalTestCase {
}
/**
- * Handle errors.
+ * Handle errors during test runs.
*
* Because this is registered in set_error_handler(), it has to be public.
* @see set_error_handler
- *
*/
public function errorHandler($severity, $message, $file = NULL, $line = NULL) {
- if ($severity & error_reporting()) {
- $error_map = array(
- E_STRICT => 'Run-time notice',
- E_WARNING => 'Warning',
- E_NOTICE => 'Notice',
- E_CORE_ERROR => 'Core error',
- E_CORE_WARNING => 'Core warning',
- E_USER_ERROR => 'User error',
- E_USER_WARNING => 'User warning',
- E_USER_NOTICE => 'User notice',
- E_RECOVERABLE_ERROR => 'Recoverable error',
- );
+ $error_map = array(
+ E_STRICT => 'Run-time notice',
+ E_WARNING => 'Warning',
+ E_NOTICE => 'Notice',
+ E_CORE_ERROR => 'Core error',
+ E_CORE_WARNING => 'Core warning',
+ E_USER_ERROR => 'User error',
+ E_USER_WARNING => 'User warning',
+ E_USER_NOTICE => 'User notice',
+ E_RECOVERABLE_ERROR => 'Recoverable error',
+ );
- $backtrace = debug_backtrace();
- $this->error($message, $error_map[$severity], _drupal_get_last_caller($backtrace));
- }
+ $backtrace = debug_backtrace();
+ $this->error($message, $error_map[$severity], _drupal_get_last_caller($backtrace));
return TRUE;
}
@@ -532,13 +529,18 @@ class DrupalUnitTestCase extends DrupalTestCase {
$this->skipClasses[__CLASS__] = TRUE;
}
- function setUp() {
+ protected function setUp() {
global $db_prefix, $conf;
// Store necessary current values before switching to prefixed database.
$this->originalPrefix = $db_prefix;
$this->originalFileDirectory = file_directory_path();
+ // Log fatal errors.
+ ini_set('log_errors', 1);
+ // Make all errors visible.
+ error_reporting(E_ALL);
+
// Reset all statics so that test is performed with a clean environment.
drupal_static_reset();
@@ -556,7 +558,7 @@ class DrupalUnitTestCase extends DrupalTestCase {
}
}
- function tearDown() {
+ protected function tearDown() {
global $db_prefix, $conf;
if (preg_match('/simpletest\d+/', $db_prefix)) {
$conf['file_public_path'] = $this->originalFileDirectory;
@@ -1055,6 +1057,8 @@ class DrupalWebTestCase extends DrupalTestCase {
// Log fatal errors.
ini_set('log_errors', 1);
ini_set('error_log', $directory . '/error.log');
+ // Make all errors visible.
+ error_reporting(E_ALL);
// Reset all statics so that test is performed with a clean environment.
drupal_static_reset();
@@ -1357,14 +1361,16 @@ class DrupalWebTestCase extends DrupalTestCase {
*/
protected function parse() {
if (!$this->elements) {
- // DOM can load HTML soup. But, HTML soup can throw warnings, suppress
- // them.
- @$htmlDom = DOMDocument::loadHTML($this->content);
- if ($htmlDom) {
+ // Suppress all libxml warnings during loading of HTML.
+ // @todo Remove this when core produces XHTML valid output.
+ libxml_use_internal_errors(TRUE);
+ $document = new DOMDocument();
+ $result = $document->loadHTML($this->content);
+ if ($result) {
$this->pass(t('Valid HTML found on "@path"', array('@path' => $this->getUrl())), t('Browser'));
// It's much easier to work with simplexml than DOM, luckily enough
// we can just simply import our DOM tree.
- $this->elements = simplexml_import_dom($htmlDom);
+ $this->elements = simplexml_import_dom($document);
}
}
if (!$this->elements) {
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index 35a2a7f87..b2223d579 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -801,8 +801,8 @@ class DrupalHTTPRequestTestCase extends DrupalWebTestCase {
// Parse URL schema.
$missing_scheme = drupal_http_request('example.com/path');
- $this->assertEqual($missing_scheme->code, -1002, t('Returned with "-1002" error code.'));
- $this->assertEqual($missing_scheme->error, 'missing schema', t('Returned with "missing schema" error message.'));
+ $this->assertEqual($missing_scheme->code, -1001, t('Returned with "-1001" error code.'));
+ $this->assertEqual($missing_scheme->error, 'unable to parse URL', t('Returned with "unable to parse URL" error message.'));
$unable_to_parse = drupal_http_request('http:///path');
$this->assertEqual($unable_to_parse->code, -1001, t('Returned with "-1001" error code.'));
@@ -860,8 +860,8 @@ class DrupalHTTPRequestTestCase extends DrupalWebTestCase {
$this->assertFalse(isset($redirect_301->redirect_code), t('drupal_http_request does not follow 301 redirect if max_redirects = 0.'));
$redirect_invalid = drupal_http_request(url('system-test/redirect-noscheme', array('absolute' => TRUE)), array('max_redirects' => 1));
- $this->assertEqual($redirect_invalid->code, -1002, t('301 redirect to invalid URL returned with error code !error.', array('!error' => $redirect_invalid->error)));
- $this->assertEqual($redirect_invalid->error, 'missing schema', t('301 redirect to invalid URL returned with error message "!error".', array('!error' => $redirect_invalid->error)));
+ $this->assertEqual($redirect_invalid->code, -1001, t('301 redirect to invalid URL returned with error code !error.', array('!error' => $redirect_invalid->error)));
+ $this->assertEqual($redirect_invalid->error, 'unable to parse URL', t('301 redirect to invalid URL returned with error message "!error".', array('!error' => $redirect_invalid->error)));
$redirect_invalid = drupal_http_request(url('system-test/redirect-noparse', array('absolute' => TRUE)), array('max_redirects' => 1));
$this->assertEqual($redirect_invalid->code, -1001, t('301 redirect to invalid URL returned with error message code "!error".', array('!error' => $redirect_invalid->error)));
diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test
index 46c24508b..08263668c 100644
--- a/modules/simpletest/tests/file.test
+++ b/modules/simpletest/tests/file.test
@@ -288,16 +288,22 @@ class FileSpaceUsedTest extends FileTestCase {
parent::setUp();
// Create records for a couple of users with different sizes.
- drupal_write_record('file', $file = array('uid' => 2, 'uri' => 'public://example1.txt', 'filesize' => 50, 'status' => FILE_STATUS_PERMANENT));
- drupal_write_record('file', $file = array('uid' => 2, 'uri' => 'public://example2.txt', 'filesize' => 20, 'status' => FILE_STATUS_PERMANENT));
- drupal_write_record('file', $file = array('uid' => 3, 'uri' => 'public://example3.txt', 'filesize' => 100, 'status' => FILE_STATUS_PERMANENT));
- drupal_write_record('file', $file = array('uid' => 3, 'uri' => 'public://example4.txt', 'filesize' => 200, 'status' => FILE_STATUS_PERMANENT));
+ $file = array('uid' => 2, 'uri' => 'public://example1.txt', 'filesize' => 50, 'status' => FILE_STATUS_PERMANENT);
+ drupal_write_record('file', $file);
+ $file = array('uid' => 2, 'uri' => 'public://example2.txt', 'filesize' => 20, 'status' => FILE_STATUS_PERMANENT);
+ drupal_write_record('file', $file);
+ $file = array('uid' => 3, 'uri' => 'public://example3.txt', 'filesize' => 100, 'status' => FILE_STATUS_PERMANENT);
+ drupal_write_record('file', $file);
+ $file = array('uid' => 3, 'uri' => 'public://example4.txt', 'filesize' => 200, 'status' => FILE_STATUS_PERMANENT);
+ drupal_write_record('file', $file);
// Now create some with other statuses. These values were chosen arbitrarily
// for the sole purpose of testing that bitwise operators were used
// correctly on the field.
- drupal_write_record('file', $file = array('uid' => 2, 'uri' => 'public://example5.txt', 'filesize' => 1, 'status' => 2 | 8));
- drupal_write_record('file', $file = array('uid' => 3, 'uri' => 'public://example6.txt', 'filesize' => 3, 'status' => 2 | 4));
+ $file = array('uid' => 2, 'uri' => 'public://example5.txt', 'filesize' => 1, 'status' => 2 | 8);
+ drupal_write_record('file', $file);
+ $file = array('uid' => 3, 'uri' => 'public://example6.txt', 'filesize' => 3, 'status' => 2 | 4);
+ drupal_write_record('file', $file);
}
/**
@@ -722,7 +728,9 @@ class FileDirectoryTest extends FileTestCase {
// Remove .htaccess file to then test that it gets re-created.
$directory = file_directory_path();
- @unlink($directory . '/.htaccess');
+ if (file_exists($directory . '/.htaccess')) {
+ unlink($directory . '/.htaccess');
+ }
$this->assertFalse(is_file($directory . '/.htaccess'), t('Successfully removed the .htaccess file in the files directory.'), 'File');
file_ensure_htaccess();
$this->assertTrue(is_file($directory . '/.htaccess'), t('Successfully re-created the .htaccess file in the files directory.'), 'File');
@@ -1582,7 +1590,8 @@ class FileLoadTest extends FileHookTestCase {
* Try to load a non-existent file by URI.
*/
function testLoadMissingFilepath() {
- $this->assertFalse(reset(file_load_multiple(array(), array('uri' => 'foobar://misc/druplicon.png'))), t("Try to load a file that doesn't exist in the database fails."));
+ $files = file_load_multiple(array(), array('uri' => 'foobar://misc/druplicon.png'));
+ $this->assertFalse(reset($files), t("Try to load a file that doesn't exist in the database fails."));
$this->assertFileHooksCalled(array());
}
@@ -1590,7 +1599,8 @@ class FileLoadTest extends FileHookTestCase {
* Try to load a non-existent file by status.
*/
function testLoadInvalidStatus() {
- $this->assertFalse(reset(file_load_multiple(array(), array('status' => -99))), t("Trying to load a file with an invalid status fails."));
+ $files = file_load_multiple(array(), array('status' => -99));
+ $this->assertFalse(reset($files), t("Trying to load a file with an invalid status fails."));
$this->assertFileHooksCalled(array());
}
diff --git a/modules/simpletest/tests/session.test b/modules/simpletest/tests/session.test
index 70bf70565..ec16207f5 100644
--- a/modules/simpletest/tests/session.test
+++ b/modules/simpletest/tests/session.test
@@ -345,7 +345,7 @@ class SessionHttpsTestCase extends DrupalWebTestCase {
// Check that user login form action is secure.
$this->drupalGet('user');
- $form = &$this->xpath('//form[@id="user-login"]');
+ $form = $this->xpath('//form[@id="user-login"]');
$this->assertEqual(substr($form[0]['action'], 0, 6), 'https:', 'Login form action is secure');
$form[0]['action'] = $this->httpsUrl('user');