Public Member Functions | |
setUp () | |
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. | |
testInternalBrowser () | |
Test the internal browsers functionality. | |
testWebTestRunner () | |
Make sure that tests selected through the web interface are run and that the results are displayed correctly. | |
stubTest () | |
Test to be run and the results confirmed. | |
assertNothing () | |
Assert nothing. | |
confirmStubTestResults () | |
Confirm that the stub test produced the desired results. | |
getTestIdFromResults () | |
Fetch the test id from the test results. | |
assertAssertion ($message, $type, $status, $file, $function) | |
Assert that an assertion with the specified values is displayed in the test results. | |
getTestResults () | |
Get the results from a test and store them in the class array $results. | |
getResultFieldSet () | |
Get the fieldset containing the results for group this test is in. | |
asText (SimpleXMLElement $element) | |
Extract the text contained by the element. | |
inCURL () | |
Check if the test is being run from inside a CURL request. | |
testUserAccess () | |
Tests SimpleTest's environment cleanup functionality by creating a dirty environment then checking that simpletest_clean_environment() will work as advertised. | |
testUserAccessCache () | |
Static Public Member Functions | |
static | getInfo () |
Protected Attributes | |
$childTestResults | |
The results array that has been parsed by getTestResults(). | |
$test_ids = array() | |
Store the test ID from each test run for comparison, to ensure they are incrementing. |
Definition at line 11 of file simpletest.test.
SimpleTestFunctionalTest::assertAssertion | ( | $ | message, | |
$ | type, | |||
$ | status, | |||
$ | file, | |||
$ | function | |||
) |
Assert that an assertion with the specified values is displayed in the test results.
string | $message Assertion message. | |
string | $type Assertion type. | |
string | $status Assertion status. | |
string | $file File where the assertion originated. | |
string | $functuion Function where the assertion originated. |
Definition at line 188 of file simpletest.test.
References DrupalWebTestCase::assertTrue().
00188 { 00189 $message = trim(strip_tags($message)); 00190 $found = FALSE; 00191 foreach ($this->childTestResults['assertions'] as $assertion) { 00192 if ((strpos($assertion['message'], $message) !== FALSE) && 00193 $assertion['type'] == $type && 00194 $assertion['status'] == $status && 00195 $assertion['file'] == $file && 00196 $assertion['function'] == $function) { 00197 $found = TRUE; 00198 break; 00199 } 00200 } 00201 return $this->assertTrue($found, t('Found assertion {"@message", "@type", "@status", "@file", "@function"}.', array('@message' => $message, '@type' => $type, '@status' => $status, "@file" => $file, "@function" => $function))); 00202 }
SimpleTestFunctionalTest::assertNothing | ( | ) |
Assert nothing.
Definition at line 136 of file simpletest.test.
References DrupalWebTestCase::pass().
00136 { 00137 $this->pass("This is nothing."); 00138 }
SimpleTestFunctionalTest::asText | ( | SimpleXMLElement $ | element | ) |
Extract the text contained by the element.
$element | Element to extract text from. |
Definition at line 258 of file simpletest.test.
References DrupalWebTestCase::fail().
00258 { 00259 if (!is_object($element)) { 00260 return $this->fail('The element is not an element.'); 00261 } 00262 return trim(html_entity_decode(strip_tags($element->asXML()))); 00263 }
SimpleTestFunctionalTest::confirmStubTestResults | ( | ) |
Confirm that the stub test produced the desired results.
Definition at line 143 of file simpletest.test.
References $test_id, assertAssertion(), DrupalWebTestCase::assertTrue(), DrupalWebTestCase::fail(), getTestIdFromResults(), and DrupalWebTestCase::pass().
00143 { 00144 $this->assertAssertion($this->pass, 'Other', 'Pass', 'simpletest.test', 'SimpleTestFunctionalTest->stubTest()'); 00145 $this->assertAssertion($this->fail, 'Other', 'Fail', 'simpletest.test', 'SimpleTestFunctionalTest->stubTest()'); 00146 00147 $this->assertAssertion(t('Created permissions: @perms', array('@perms' => $this->valid_permission)), 'Role', 'Pass', 'simpletest.test', 'SimpleTestFunctionalTest->stubTest()'); 00148 $this->assertAssertion(t('Invalid permission %permission.', array('%permission' => $this->invalid_permission)), 'Role', 'Fail', 'simpletest.test', 'SimpleTestFunctionalTest->stubTest()'); 00149 00150 // Check that a warning is catched by simpletest. 00151 $this->assertAssertion('Division by zero', 'Warning', 'Fail', 'simpletest.test', 'SimpleTestFunctionalTest->stubTest()'); 00152 00153 // Check that the backtracing code works for specific assert function. 00154 $this->assertAssertion('This is nothing.', 'Other', 'Pass', 'simpletest.test', 'SimpleTestFunctionalTest->stubTest()'); 00155 00156 // Check that errors that occur inside PHP internal functions are correctly reported. 00157 // The exact error message differs between PHP versions so we check only 00158 // the function name 'array_key_exists'. 00159 $this->assertAssertion('array_key_exists', 'Warning', 'Fail', 'simpletest.test', 'SimpleTestFunctionalTest->stubTest()'); 00160 00161 $this->test_ids[] = $test_id = $this->getTestIdFromResults(); 00162 $this->assertTrue($test_id, t('Found test ID in results.')); 00163 }
static SimpleTestFunctionalTest::getInfo | ( | ) | [static] |
Definition at line 23 of file simpletest.test.
00023 { 00024 return array( 00025 'name' => t('SimpleTest functionality'), 00026 'description' => t('Test SimpleTest\'s web interface: check that the intended tests were 00027 run and ensure that test reports display the intended results. Also 00028 test SimpleTest\'s internal browser and API\'s both explicitly and 00029 implicitly.'), 00030 'group' => t('SimpleTest') 00031 ); 00032 }
SimpleTestFunctionalTest::getResultFieldSet | ( | ) |
Get the fieldset containing the results for group this test is in.
Definition at line 239 of file simpletest.test.
References getInfo(), and DrupalWebTestCase::xpath().
00239 { 00240 $fieldsets = $this->xpath('//fieldset'); 00241 $info = $this->getInfo(); 00242 foreach ($fieldsets as $fieldset) { 00243 if ($fieldset->legend == $info['group']) { 00244 return $fieldset; 00245 } 00246 } 00247 return FALSE; 00248 }
SimpleTestFunctionalTest::getTestIdFromResults | ( | ) |
Fetch the test id from the test results.
Definition at line 168 of file simpletest.test.
00168 { 00169 foreach($this->childTestResults['assertions'] as $assertion) { 00170 if (preg_match('@^Test ID is ([0-9]*)\.$@', $assertion['message'], $matches)) { 00171 return $matches[1]; 00172 } 00173 } 00174 return NULL; 00175 }
SimpleTestFunctionalTest::getTestResults | ( | ) |
Get the results from a test and store them in the class array $results.
Definition at line 207 of file simpletest.test.
References DrupalWebTestCase::$results, asText(), getResultFieldSet(), and DrupalWebTestCase::parse().
00207 { 00208 $results = array(); 00209 00210 if ($this->parse()) { 00211 if ($fieldset = $this->getResultFieldSet()) { 00212 // Code assumes this is the only test in group. 00213 $results['summary'] = $this->asText($fieldset->div); 00214 $results['name'] = $this->asText($fieldset->fieldset->legend); 00215 00216 $results['assertions'] = array(); 00217 $tbody = $fieldset->fieldset->table->tbody; 00218 foreach ($tbody->tr as $row) { 00219 $assertion = array(); 00220 $assertion['message'] = $this->asText($row->td[0]); 00221 $assertion['type'] = $this->asText($row->td[1]); 00222 $assertion['file'] = $this->asText($row->td[2]); 00223 $assertion['line'] = $this->asText($row->td[3]); 00224 $assertion['function'] = $this->asText($row->td[4]); 00225 $ok_url = (url('misc/watchdog-ok.png') == 'misc/watchdog-ok.png') ? 'misc/watchdog-ok.png' : (base_path() . 'misc/watchdog-ok.png'); 00226 $assertion['status'] = ($row->td[5]->img['src'] == $ok_url) ? 'Pass' : 'Fail'; 00227 $results['assertions'][] = $assertion; 00228 } 00229 } 00230 } 00231 $this->childTestResults = $results; 00232 }
SimpleTestFunctionalTest::inCURL | ( | ) |
Check if the test is being run from inside a CURL request.
Definition at line 270 of file simpletest.test.
SimpleTestFunctionalTest::setUp | ( | ) |
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules.
After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix. A temporary files directory is created with the same name as the database prefix.
... | List of modules to enable for the duration of the test. |
Reimplemented from DrupalWebTestCase.
Definition at line 34 of file simpletest.test.
References DrupalWebTestCase::drupalCreateUser(), DrupalWebTestCase::drupalLogin(), and inCURL().
00034 { 00035 if (!$this->inCURL()) { 00036 parent::setUp('simpletest'); 00037 00038 // Create and login user 00039 $admin_user = $this->drupalCreateUser(array('administer unit tests')); 00040 $this->drupalLogin($admin_user); 00041 } 00042 else { 00043 parent::setUp(); 00044 } 00045 }
SimpleTestFunctionalTest::stubTest | ( | ) |
Test to be run and the results confirmed.
Definition at line 114 of file simpletest.test.
References assertNothing(), DrupalWebTestCase::drupalCreateUser(), DrupalWebTestCase::fail(), and DrupalWebTestCase::pass().
00114 { 00115 $this->pass($this->pass); 00116 $this->fail($this->fail); 00117 00118 $this->drupalCreateUser(array($this->valid_permission)); 00119 $this->drupalCreateUser(array($this->invalid_permission)); 00120 00121 $this->pass(t('Test ID is @id.', array('@id' => $this->testId))); 00122 00123 // Generates a warning. 00124 $i = 1 / 0; 00125 00126 // Call an assert function specific to that class. 00127 $this->assertNothing(); 00128 00129 // Generates a warning inside a PHP function. 00130 array_key_exists(NULL, NULL); 00131 }
SimpleTestFunctionalTest::testInternalBrowser | ( | ) |
Test the internal browsers functionality.
Definition at line 50 of file simpletest.test.
References DrupalWebTestCase::$headers, DrupalWebTestCase::assertEqual(), DrupalWebTestCase::assertFalse(), DrupalWebTestCase::assertNoTitle(), DrupalWebTestCase::assertResponse(), DrupalWebTestCase::assertTitle(), DrupalWebTestCase::assertTrue(), DrupalWebTestCase::drupalCreateUser(), DrupalWebTestCase::drupalGet(), DrupalWebTestCase::drupalGetHeader(), DrupalWebTestCase::drupalGetHeaders(), DrupalWebTestCase::drupalLogin(), DrupalWebTestCase::getUrl(), and inCURL().
00050 { 00051 global $conf; 00052 if (!$this->inCURL()) { 00053 $this->drupalGet('node'); 00054 $this->assertTrue($this->drupalGetHeader('Date'), t('An HTTP header was received.')); 00055 $this->assertTitle(variable_get('site_name', 'Drupal'), t('Site title matches.')); 00056 $this->assertNoTitle('Foo', t('Site title does not match.')); 00057 // Make sure that we are locked out of the installer when prefixing 00058 // using the user-agent header. This is an important security check. 00059 global $base_url; 00060 00061 $this->drupalGet($base_url . '/install.php', array('external' => TRUE)); 00062 $this->assertResponse(403, 'Cannot access install.php with a "simpletest" user-agent header.'); 00063 00064 $this->drupalLogin($this->drupalCreateUser()); 00065 $headers = $this->drupalGetHeaders(TRUE); 00066 $this->assertEqual(count($headers), 2, t('There was one intermediate request.')); 00067 $this->assertTrue(strpos($headers[0][':status'], '302') !== FALSE, t('Intermediate response code was 302.')); 00068 $this->assertFalse(empty($headers[0]['location']), t('Intermediate request contained a Location header.')); 00069 $this->assertEqual($this->getUrl(), $headers[0]['location'], t('HTTP redirect was followed')); 00070 $this->assertFalse($this->drupalGetHeader('Location'), t('Headers from intermediate request were reset.')); 00071 $this->assertResponse(200, t('Response code from intermediate request was reset.')); 00072 } 00073 }
SimpleTestFunctionalTest::testUserAccess | ( | ) |
Tests SimpleTest's environment cleanup functionality by creating a dirty environment then checking that simpletest_clean_environment() will work as advertised.
function testEnvironmentCleanup() { global $db_prefix;
$old_prefix = $db_prefix;
Create a prefixed table (note SimpleTest has probably already created a bunch of simpletest-prefixed tables, so we need to temporarily switch prefixes to test this) $db_prefix = 'simpletest' . mt_rand(1000, 1000000); $table = 'testcleanup'; $schema = drupal_get_schema(NULL, true); $ret = array(); $prefixed_table_names = array(); foreach ($schema as $name => $table) { db_create_table($ret, $name, $table); $prefixed_table_names[] = $db_prefix.$name; }
Check they were created $success = true; foreach ($schema as $name => $table) { $success &= db_table_exists($name); } $this->assertTrue($success, t('Checking cleanup test tables exists'));
Get any currently set messages $old_messages = $_SESSION['messages']; drupal_get_messages(null, true);
Run the cleanup $db_prefix_backup = $db_prefix; $db_prefix = ''; // technically should be the site's default prefix, but it's too risky to reinclude settings.php if (function_exists('simpletest_get_like_tables')) { // Drupal 6 $would_be_removed_tables = simpletest_get_like_tables('simpletest', false); } else if (function_exists('db_find_tables')) { // Drupal 7 $would_be_removed_tables = db_find_tables(Database::getConnection()->prefixTables('{simpletest}') . ''); } $missed_tables = array_diff($prefixed_table_names, $would_be_removed_tables); $this->assertTrue(empty($missed_tables), t('Checking for any missed tables that should have been cleaned up')); $db_prefix = $db_prefix_backup;
Remove our testing tables foreach ($schema as $name => $table) { db_drop_table($ret, $name); }
restore the original SimpleTest db prefix $db_prefix = $old_prefix; drupal_get_schema(null, true); }
Definition at line 335 of file simpletest.test.
References DrupalWebTestCase::assertTrue(), and DrupalWebTestCase::drupalCreateUser().
00336 { 00337 $user = $this->drupalCreateUser(array('administer unit tests')); 00338 $this->assertTrue(user_access('administer unit tests', $user), 'user_access() check successfull.'); 00339 }
SimpleTestFunctionalTest::testUserAccessCache | ( | ) |
Definition at line 341 of file simpletest.test.
References DrupalWebTestCase::assertTrue(), and DrupalWebTestCase::drupalCreateUser().
00342 { 00343 $user = $this->drupalCreateUser(array('administer nodes')); 00344 $this->assertTrue(user_access('administer nodes', $user), 'user_access() cache has been cleaned'); 00345 00346 }
SimpleTestFunctionalTest::testWebTestRunner | ( | ) |
Make sure that tests selected through the web interface are run and that the results are displayed correctly.
Definition at line 79 of file simpletest.test.
References DrupalWebTestCase::assertTrue(), confirmStubTestResults(), DrupalWebTestCase::drupalGet(), DrupalWebTestCase::drupalPost(), DrupalWebTestCase::fail(), getTestResults(), inCURL(), DrupalWebTestCase::pass(), and stubTest().
00079 { 00080 $this->pass = t('SimpleTest pass.'); 00081 $this->fail = t('SimpleTest fail.'); 00082 $this->valid_permission = 'access content'; 00083 $this->invalid_permission = 'invalid permission'; 00084 00085 if ($this->inCURL()) { 00086 // Only run following code if this test is running itself through a CURL request. 00087 $this->stubTest(); 00088 } 00089 else { 00090 00091 // Run twice so test_ids can be accumulated. 00092 for ($i = 0; $i < 2; $i++) { 00093 // Run this test from web interface. 00094 $this->drupalGet('admin/build/testing'); 00095 00096 $edit = array(); 00097 $edit['SimpleTestFunctionalTest'] = TRUE; 00098 $this->drupalPost(NULL, $edit, t('Run tests')); 00099 00100 // Parse results and confirm that they are correct. 00101 $this->getTestResults(); 00102 $this->confirmStubTestResults(); 00103 } 00104 00105 // Regression test for #290316. 00106 // Check that test_id is incrementing. 00107 $this->assertTrue($this->test_ids[0] != $this->test_ids[1], t('Test ID is incrementing.')); 00108 } 00109 }
SimpleTestFunctionalTest::$childTestResults [protected] |
The results array that has been parsed by getTestResults().
Definition at line 15 of file simpletest.test.
SimpleTestFunctionalTest::$test_ids = array() [protected] |
Store the test ID from each test run for comparison, to ensure they are incrementing.
Definition at line 21 of file simpletest.test.