Commit 63e195eb authored by Dries's avatar Dries

- Patch #338239 by Damien Tournoud: clean-up DrupalWebTestCase.

parent 6e5851b3
This diff is collapsed.
......@@ -60,8 +60,6 @@ function simpletest_theme() {
* Menu callback for both running tests and listing possible tests
*/
function simpletest_test_form() {
global $db_prefix, $db_prefix_original;
$form = array();
// List out all tests in groups for selection.
......@@ -354,7 +352,6 @@ function simpletest_test_form_submit($form, &$form_state) {
* drupal being the default.
*/
function simpletest_run_tests($test_list, $reporter = 'drupal') {
global $db_prefix, $db_prefix_original;
cache_clear_all();
$test_id = db_insert('simpletest_test_id')->useDefaults(array('test_id'))->execute();
......@@ -415,7 +412,7 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) {
$info = $test->getInfo();
// Gather results and compose the report.
$test_results[$test_class] = $test->_results;
$test_results[$test_class] = $test->results;
foreach ($test_results[$test_class] as $key => $value) {
$test_results[$key] += $value;
}
......@@ -526,13 +523,12 @@ function simpletest_clean_environment() {
* Removed prefixed talbes from the database that are left over from crashed tests.
*/
function simpletest_clean_database() {
global $db_prefix;
$tables = db_find_tables(Database::getActiveConnection()->prefixTables('{simpletest}') . '%');
$schema = drupal_get_schema_unprocessed('simpletest');
$ret = array();
foreach (array_diff_key($tables, $schema) as $table) {
// Strip $db_prefix and skip tables without digits following "simpletest",
// e.g. {simpletest_tets_id}.
// Strip the prefix and skip tables without digits following "simpletest",
// e.g. {simpletest_test_id}.
if (preg_match('/simpletest\d+.*/', $table, $matches)) {
db_drop_table($ret, $matches[0]);
}
......
......@@ -5,7 +5,7 @@ class SimpleTestTestCase extends DrupalWebTestCase {
/**
* The results array that has been parsed by getTestResults().
*/
protected $results;
protected $childTestResults;
/**
* Store the test ID from each test run for comparison, to ensure they are
......@@ -100,7 +100,7 @@ class SimpleTestTestCase extends DrupalWebTestCase {
$this->drupalCreateUser(array($this->valid_permission));
$this->drupalCreateUser(array($this->invalid_permission));
$this->pass(t('Test ID is @id.', array('@id' => $this->test_id)));
$this->pass(t('Test ID is @id.', array('@id' => $this->testId)));
// Generates a warning.
$i = 1 / 0;
......@@ -146,7 +146,7 @@ class SimpleTestTestCase extends DrupalWebTestCase {
* Fetch the test id from the test results.
*/
function getTestIdFromResults() {
foreach($this->results['assertions'] as $assertion) {
foreach($this->childTestResults['assertions'] as $assertion) {
if (preg_match('@^Test ID is ([0-9]*)\.$@', $assertion['message'], $matches)) {
return $matches[1];
}
......@@ -168,7 +168,7 @@ class SimpleTestTestCase extends DrupalWebTestCase {
function assertAssertion($message, $type, $status, $file, $function) {
$message = trim(strip_tags($message));
$found = FALSE;
foreach ($this->results['assertions'] as $assertion) {
foreach ($this->childTestResults['assertions'] as $assertion) {
if ((strpos($assertion['message'], $message) !== FALSE) &&
$assertion['type'] == $type &&
$assertion['status'] == $status &&
......@@ -208,7 +208,7 @@ class SimpleTestTestCase extends DrupalWebTestCase {
}
}
}
$this->results = $results;
$this->childTestResults = $results;
}
/**
......
......@@ -146,11 +146,11 @@ class DrupalTagsHandlingTestCase extends DrupalWebTestCase {
$original = $this->validTags;
foreach ($tags as $tag) {
$key = array_search($tag, $original);
$this->_assert($key !== FALSE, t('Make sure tag %tag shows up in the final tags array (originally %original)', array('%tag' => $tag, '%original' => $key)));
$this->assertTrue($key, t('Make sure tag %tag shows up in the final tags array (originally %original)', array('%tag' => $tag, '%original' => $key)));
unset($original[$key]);
}
foreach ($original as $leftover) {
$this->_assert(FALSE, t('Leftover tag %leftover was left over.', array('%leftover' => $leftover)));
$this->fail(t('Leftover tag %leftover was left over.', array('%leftover' => $leftover)));
}
}
}
......@@ -238,11 +238,9 @@ class DrupalHTTPRequestTestCase extends DrupalWebTestCase {
$auth = str_replace('http://', 'http://' . $username . ':' . $password .'@', $url);
$result = drupal_http_request($auth);
// We use strpos directly.
// assertRaw() cannot be used because we are getting the data
// in a variable instead of $this->_content.
$this->assertTrue(strpos($result->data, $username) !== FALSE, t('$_SERVER[\'PHP_AUTH_USER\'] is passed correctly.'));
$this->assertTrue(strpos($result->data, $password) !== FALSE, t('$_SERVER[\'PHP_AUTH_PW\'] is passed correctly.'));
$this->drupalSetContent($result->data);
$this->assertRaw($username, t('$_SERVER["PHP_AUTH_USER"] is passed correctly.'));
$this->assertRaw($password, t('$_SERVER["PHP_AUTH_PW"] is passed correctly.'));
}
function testDrupalHTTPRequestRedirect() {
......
......@@ -2026,7 +2026,7 @@ class DatabaseTemporaryQueryTestCase extends DrupalWebTestCase {
*/
function testTemporaryQuery() {
$this->drupalGet('database_test_db_query_temporary');
$this->assertEqual(db_query('SELECT COUNT(*) FROM {system}')->fetchField(), $this->_content, t('The temporary table exists and contains the correct amount of rows.'));
$this->assertEqual(db_query('SELECT COUNT(*) FROM {system}')->fetchField(), $this->drupalGetContent(), t('The temporary table exists and contains the correct amount of rows.'));
$this->assertFalse(db_table_exists('temporary'), t('The temporary table is, indeed, temporary.'));
}
}
......@@ -169,9 +169,9 @@ class SessionTestCase extends DrupalWebTestCase {
$this->curlClose();
// Change cookie file for user.
$this->cookie_file = file_directory_temp() . '/cookie.' . $uid . '.txt';
$this->curl_options[CURLOPT_COOKIEFILE] = $this->cookie_file;
$this->curl_options[CURLOPT_COOKIESESSION] = TRUE;
$this->cookieFile = file_directory_temp() . '/cookie.' . $uid . '.txt';
$this->additionalCurlOptions[CURLOPT_COOKIEFILE] = $this->cookieFile;
$this->additionalCurlOptions[CURLOPT_COOKIESESSION] = TRUE;
$this->drupalGet('session-test/get');
$this->assertResponse(200, t('Session test module is correctly enabled.'), t('Session'));
}
......
......@@ -343,9 +343,9 @@ function simpletest_script_run_one_test($test_id, $test_class) {
$test->run();
$info = $test->getInfo();
$status = ((isset($test->_results['#fail']) && $test->_results['#fail'] > 0)
|| (isset($test->_results['#exception']) && $test->_results['#exception'] > 0) ? 'fail' : 'pass');
simpletest_script_print($info['name'] . ' ' . _simpletest_format_summary_line($test->_results) . "\n", simpletest_script_color_code($status));
$status = ((isset($test->results['#fail']) && $test->results['#fail'] > 0)
|| (isset($test->results['#exception']) && $test->results['#exception'] > 0) ? 'fail' : 'pass');
simpletest_script_print($info['name'] . ' ' . _simpletest_format_summary_line($test->results) . "\n", simpletest_script_color_code($status));
}
/**
......
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