Commit c2f26d33 authored by Dries's avatar Dries
Browse files

- Patch #653940 by sun: tests weren't reporting all errors.

parent 3016bcbd
......@@ -807,20 +807,16 @@ function drupal_http_request($url, array $options = array()) {
$result = new stdClass();
// Parse the URL and make sure we can handle the schema.
$uri = @parse_url($url);
if ($uri == FALSE) {
// Validate the passed URL. FILTER_VALIDATE_URL uses parse_url() internally,
// but unlike parse_url() itself, it will not throw a run-time notice for
// bogus URLs.
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
$result->error = 'unable to parse URL';
$result->code = -1001;
return $result;
}
if (!isset($uri['scheme'])) {
$result->error = 'missing schema';
$result->code = -1002;
return $result;
}
$uri = parse_url($url);
timer_start(__FUNCTION__);
......
......@@ -500,7 +500,12 @@ public function rmdir($uri, $options) {
public function url_stat($uri, $flags) {
$this->uri = $uri;
if ($flags & STREAM_URL_STAT_QUIET) {
return @stat($this->getLocalPath());
if (file_exists($this->getLocalPath())) {
return stat($this->getLocalPath());
}
else {
return FALSE;
}
}
else {
return stat($this->getLocalPath());
......
......@@ -21,8 +21,11 @@ class CommentHelperCase extends DrupalWebTestCase {
* @param string $comment Comment body.
* @param string $subject Comment subject.
* @param mixed $contact Set to NULL for no contact info, TRUE to ignore success checking, and array of values to set contact info.
*
* This needs to be static to be invoked via CommentHelperCase::postComment()
* in other tests.
*/
function postComment($node, $comment, $subject = '', $contact = NULL) {
public static function postComment($node, $comment, $subject = '', $contact = NULL) {
$edit = array();
$edit['comment'] = $comment;
......
......@@ -487,7 +487,11 @@ function field_sql_storage_field_storage_query($field_id, $conditions, $options)
foreach ($conditions as $condition) {
// A condition is either a (column, value, operator) triple, or a
// (column, value) pair with implied operator.
@list($column, $value, $operator) = $condition;
list($column, $value) = $condition;
$operator = NULL;
if (isset($condition[2])) {
$operator = $condition[2];
}
// Translate operator and value if needed.
switch ($operator) {
case 'STARTS_WITH':
......
......@@ -91,32 +91,28 @@ class ListFieldTestCase extends DrupalWebTestCase {
/**
* List module UI tests.
*/
class ListFieldUITestCase extends DrupalWebTestCase {
public static function getInfo() {
class ListFieldUITestCase extends FieldUITestCase {
public static function getInfo() {
return array(
'name' => 'List field UI tests',
'description' => 'Test the List field UI functionality.',
'group' => 'Field types',
);
}
function setUp() {
FieldUITestCase::setUp();
}
/**
* Tests that allowed values are properly validated in the UI.
*/
function testAllowedValues() {
$element_name = "field[settings][allowed_values]";
//Test 'List' field type.
$admin_path = $this->createListFieldAndEdit('list');
//Check that non-integer keys are rejected.
$edit = array($element_name => "1.1|one\n");
$this->drupalPost($admin_path, $edit, t('Save settings'));
$this->assertText("keys must be integers", t('Form vaildation failed.'));
// Test 'List (number)' field type.
$admin_path = $this->createListFieldAndEdit('list_number');
//Check that non-numeric keys are rejected.
......
......@@ -17,8 +17,9 @@ class FieldTestCase extends DrupalWebTestCase {
*/
function setUp() {
// Call parent::setUp().
// @see http://www.php.net/manual/en/function.call-user-func-array.php#73105
$args = func_get_args();
call_user_func_array(array('parent', 'setUp'), $args);
call_user_func_array(array($this, 'parent::setUp'), $args);
// Set default storage backend.
variable_set('field_storage_default', $this->default_storage);
}
......
......@@ -468,7 +468,8 @@ function filter_default_format($account = NULL) {
}
// Get a list of formats for this user, ordered by weight. The first one
// available is the user's default format.
$format = array_shift(filter_formats($account));
$formats = filter_formats($account);
$format = reset($formats);
return $format->format;
}
......@@ -825,10 +826,12 @@ function _filter_tips($format_id, $long = FALSE) {
* A DOMDocument that represents the loaded (X)HTML snippet.
*/
function filter_dom_load($text) {
// Ignore warnings during HTML soup loading.
$dom_document = @DOMDocument::loadHTML('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>' . $text . '</body></html>');
// Suppress all libxml warnings during loading of HTML.
libxml_use_internal_errors(TRUE);
$document = new DOMDocument();
$document->loadHTML('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>' . $text . '</body></html>');
return $dom_document;
return $document;
}
/**
......
......@@ -84,14 +84,17 @@ class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase {
// Make the default scheme neither "public" nor "private" to verify the
// functions work for other than the default scheme.
variable_set('file_default_scheme', 'temporary');
file_prepare_directory($d = 'temporary://', FILE_CREATE_DIRECTORY);
$d = 'temporary://';
file_prepare_directory($d, FILE_CREATE_DIRECTORY);
// Create the directories for the styles.
$status = file_prepare_directory($d = $scheme . '://styles/' . $this->style_name, FILE_CREATE_DIRECTORY);
$d = $scheme . '://styles/' . $this->style_name;
$status = file_prepare_directory($d, FILE_CREATE_DIRECTORY);
$this->assertNotIdentical(FALSE, $status, t('Created the directory for the generated images for the test style.' ));
// Create a working copy of the file.
$file = reset($this->drupalGetTestFiles('image'));
$files = $this->drupalGetTestFiles('image');
$file = reset($files);
$image_info = image_get_info($file->uri);
$original_uri = file_unmanaged_copy($file->uri, $scheme . '://', FILE_EXISTS_RENAME);
$this->assertNotIdentical(FALSE, $original_uri, t('Created the generated image file.'));
......@@ -273,7 +276,8 @@ class ImageAdminStylesUnitTest extends DrupalWebTestCase {
// First, we need to make sure we have an image in our testing
// file directory. Copy over an image on the first run.
if (!isset($file_path)) {
$file = reset($this->drupalGetTestFiles('image'));
$files = $this->drupalGetTestFiles('image');
$file = reset($files);
$file_path = file_unmanaged_copy($file->uri);
}
......
......@@ -100,7 +100,9 @@ function locale_uninstall() {
}
}
// Delete the JavaScript translations directory if empty.
@rmdir($locale_js_directory);
if (!file_scan_directory($locale_js_directory, '/.*/')) {
rmdir($locale_js_directory);
}
// Clear variables.
variable_del('language_default');
......
......@@ -424,29 +424,26 @@ public function run() {
}
/**
* 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 @@ function __construct($test_id = NULL) {
$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 @@ function setUp() {
}
}
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 @@ protected function setUp() {
// 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 @@ protected function curlClose() {
*/
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) {
......
......@@ -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)));
......
......@@ -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());
}
......
......@@ -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');
......
......@@ -2137,6 +2137,7 @@ function _system_rebuild_module_data() {
// Include the install profile in modules that are loaded.
$profile = drupal_get_profile();
$modules[$profile] = new stdClass;
$modules[$profile]->name = $profile;
$modules[$profile]->uri = 'profiles/' . $profile . '/' . $profile . '.profile';
$modules[$profile]->filename = $profile . '.profile';
......
......@@ -235,7 +235,7 @@ class ModuleVersionTestCase extends ModuleTestCase {
);
}
function setup() {
function setUp() {
parent::setUp('module_test');
}
......
......@@ -903,7 +903,8 @@ function taxonomy_vocabulary_load_multiple($vids = array(), $conditions = array(
* Results are statically cached.
*/
function taxonomy_vocabulary_load($vid) {
return reset(taxonomy_vocabulary_load_multiple(array($vid)));
$vocabularies = taxonomy_vocabulary_load_multiple(array($vid));
return reset($vocabularies);
}
/**
......
......@@ -441,7 +441,8 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
// Create the term to edit.
$this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->vid . '/add', $edit, t('Save'));
$term = reset(taxonomy_get_term_by_name($edit['name']));
$terms = taxonomy_get_term_by_name($edit['name']);
$term = reset($terms);
$this->assertNotNull($term, t('Term found in database'));
// Submitting a term takes us to the add page; we need the List page.
......@@ -672,7 +673,8 @@ class TaxonomyHooksTestCase extends TaxonomyWebTestCase {
'antonym' => 'Long',
);
$this->drupalPost('admin/structure/taxonomy/' . $vocabulary->vid . '/add', $edit, t('Save'));
$term = reset(taxonomy_get_term_by_name($edit['name']));
$terms = taxonomy_get_term_by_name($edit['name']);
$term = reset($terms);
$this->assertEqual($term->antonym, $edit['antonym'], t('Antonym was loaded into the term object'));
// Update the term with a different antonym.
......
......@@ -26,7 +26,8 @@ class UserRegistrationTestCase extends DrupalWebTestCase {
$edit['mail'] = $mail = $edit['name'] . '@example.com';
$this->drupalPost('user/register', $edit, t('Create new account'));
$this->assertText(t('Your password and further instructions have been sent to your e-mail address.'), t('User registered successfully.'));
$new_user = reset(user_load_multiple(array(), array('name' => $name, 'mail' => $mail)));
$accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
$new_user = reset($accounts);
$this->assertTrue($new_user->status, t('New account is active after registration.'));
// Allow registration by site visitors, but require administrator approval.
......@@ -35,7 +36,8 @@ class UserRegistrationTestCase extends DrupalWebTestCase {
$edit['name'] = $name = $this->randomName();
$edit['mail'] = $mail = $edit['name'] . '@example.com';
$this->drupalPost('user/register', $edit, t('Create new account'));
$new_user = reset(user_load_multiple(array(), array('name' => $name, 'mail' => $mail)));
$accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
$new_user = reset($accounts);
$this->assertFalse($new_user->status, t('New account is blocked until approved by an administrator.'));
}
......@@ -59,7 +61,8 @@ class UserRegistrationTestCase extends DrupalWebTestCase {
$edit['pass[pass1]'] = $new_pass = $this->randomName();
$edit['pass[pass2]'] = $new_pass;
$this->drupalPost('user/register', $edit, t('Create new account'));
$new_user = reset(user_load_multiple(array(), array('name' => $name, 'mail' => $mail)));
$accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
$new_user = reset($accounts);
$this->assertText(t('Registration successful. You are now logged in.'), t('Users are logged in after registering.'));
$this->drupalLogout();
......@@ -82,7 +85,8 @@ class UserRegistrationTestCase extends DrupalWebTestCase {
$this->assertText(t('The username @name has not been activated or is blocked.', array('@name' => $name)), t('User cannot login yet.'));
// Activate the new account.
$new_user = reset(user_load_multiple(array(), array('name' => $name, 'mail' => $mail)));
$accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
$new_user = reset($accounts);
$admin_user = $this->drupalCreateUser(array('administer users'));
$this->drupalLogin($admin_user);
$edit = array(
......@@ -115,7 +119,8 @@ class UserRegistrationTestCase extends DrupalWebTestCase {
$this->drupalPost('user/register', $edit, t('Create new account'));
// Check user fields.
$new_user = reset(user_load_multiple(array(), array('name' => $name, 'mail' => $mail)));
$accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
$new_user = reset($accounts);
$this->assertEqual($new_user->name, $name, t('Username matches.'));
$this->assertEqual($new_user->mail, $mail, t('E-mail address matches.'));
$this->assertEqual($new_user->theme, '', t('Correct theme field.'));
......@@ -371,7 +376,8 @@ class UserCancelTestCase extends DrupalWebTestCase {
$bogus_timestamp = $timestamp - 86400 - 60;
$this->drupalGet("user/$account->uid/cancel/confirm/$bogus_timestamp/" . user_pass_rehash($account->pass, $bogus_timestamp, $account->login));
$this->assertText(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), t('Expired cancel account request rejected.'));
$this->assertTrue(reset(user_load_multiple(array($account->uid), array('status' => 1))), t('User account was not canceled.'));
$accounts = user_load_multiple(array($account->uid), array('status' => 1));
$this->assertTrue(reset($accounts), t('User account was not canceled.'));
// Confirm user's content has not been altered.
$test_node = node_load($node->nid, NULL, TRUE);
......@@ -725,7 +731,8 @@ class UserPictureTestCase extends DrupalWebTestCase {
// Images are sorted first by size then by name. We need an image
// bigger than 1 KB so we'll grab the last one.
$image = end($this->drupalGetTestFiles('image'));
$files = $this->drupalGetTestFiles('image');
$image = end($files);
$info = image_get_info($image->uri);
// Set new variables: valid dimensions, invalid filesize.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment