diff options
-rw-r--r-- | modules/simpletest/simpletest.install | 50 | ||||
-rw-r--r-- | modules/simpletest/simpletest.module | 1 | ||||
-rw-r--r-- | modules/simpletest/simpletest.test | 51 |
3 files changed, 49 insertions, 53 deletions
diff --git a/modules/simpletest/simpletest.install b/modules/simpletest/simpletest.install index 2efb13c40..75f6c9fe2 100644 --- a/modules/simpletest/simpletest.install +++ b/modules/simpletest/simpletest.install @@ -149,7 +149,7 @@ function simpletest_schema() { 'type' => 'int', 'not null' => TRUE, 'default' => 0, - 'description' => t('Test id, messages belonging to the same id are reported together'), + 'description' => t('Test ID, messages belonging to the same ID are reported together'), ), 'test_class' => array( 'type' => 'varchar', @@ -204,54 +204,16 @@ function simpletest_schema() { ), ); $schema['simpletest_test_id'] = array( - 'description' => t('Stores simpletest test IDs.'), + 'description' => t('Stores simpletest test IDs, used to auto-incrament the test ID so that a fresh test ID is used.'), 'fields' => array( - 'message_id' => array( + 'test_id' => array( 'type' => 'serial', 'not null' => TRUE, - 'description' => t('Primary Key: Unique simpletest ID.'), + 'description' => t('Primary Key: Unique simpletest ID used to group test results together. Each time a set of tests + are run a new test ID is used.'), ), ), - 'primary key' => array('message_id'), + 'primary key' => array('test_id'), ); return $schema; } - -/** - * Create the simpletest tables. - */ -function simpletest_update_7000() { - $ret = array(); - $schema = array(); - - $schema['simpletest'] = array( - 'fields' => array( - 'message_id' => array('type' => 'serial', 'not null' => TRUE), - 'test_id' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), - 'test_class' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), - 'status' => array('type' => 'varchar', 'length' => 9, 'not null' => TRUE, 'default' => ''), - 'message' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), - 'message_group' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), - 'caller' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), - 'line' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), - 'file' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), - ), - 'primary key' => array('message_id'), - 'indexes' => array( - 'reporter' => array('test_class, message_id'), - ), - ); - - $schema['simpletest_test_id'] = array( - 'fields' => array( - 'message_id' => array('type' => 'serial', 'not null' => TRUE), - ), - 'primary key' => array('message_id'), - ); - - foreach ($schema as $name => $definition) { - db_create_table($ret, $name, $definition); - } - - return $ret; -} diff --git a/modules/simpletest/simpletest.module b/modules/simpletest/simpletest.module index 9c36d15d4..05907d454 100644 --- a/modules/simpletest/simpletest.module +++ b/modules/simpletest/simpletest.module @@ -62,6 +62,7 @@ function simpletest_test_form() { $uncategorized_tests = simpletest_get_all_tests(); $tests = simpletest_categorize_tests($uncategorized_tests); if (isset($_SESSION['test_id'])) { + // Select all results using the active test ID used to group them. $results = db_query("SELECT * FROM {simpletest} WHERE test_id = %d ORDER BY test_class, message_id", $_SESSION['test_id']); $summary = array( diff --git a/modules/simpletest/simpletest.test b/modules/simpletest/simpletest.test index f21b8d38b..c66a6dd55 100644 --- a/modules/simpletest/simpletest.test +++ b/modules/simpletest/simpletest.test @@ -2,9 +2,18 @@ // $Id$ class SimpleTestTestCase extends DrupalWebTestCase { + /** + * The results array that has been parsed by getTestResults(). + */ protected $results; /** + * Store the test ID from each test run for comparison, to ensure they are + * incramenting. + */ + protected $test_ids = array(); + + /** * Implementation of getInfo(). */ function getInfo() { @@ -66,16 +75,23 @@ class SimpleTestTestCase extends DrupalWebTestCase { $this->stubTest(); } else { - // Run this test from web interface. - $this->drupalGet('admin/build/testing'); - - $edit = array(); - $edit['SimpleTestTestCase'] = TRUE; - $this->drupalPost(NULL, $edit, t('Run tests')); - - $this->getTestResults(); + // Run twice so test_ids can be accumulated. + for ($i = 0; $i < 2; $i++) { + // Run this test from web interface. + $this->drupalGet('admin/build/testing'); + + $edit = array(); + $edit['SimpleTestTestCase'] = TRUE; + $this->drupalPost(NULL, $edit, t('Run tests')); + + // Parse results and confirm that they are correct. + $this->getTestResults(); + $this->confirmStubTestResults(); + } - $this->confirmStubTestResults(); + // Regression test for #290316. + // Check that test_id is incrementing. + $this->assertTrue($this->test_ids[0] != $this->test_ids[1], t('Test ID is incrementing.')); } } @@ -88,6 +104,8 @@ 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))); } /** @@ -99,6 +117,21 @@ class SimpleTestTestCase extends DrupalWebTestCase { $this->assertAssertion(t('Created permissions: @perms', array('@perms' => $this->valid_permission)), 'Role', 'Pass'); $this->assertAssertion(t('Invalid permission %permission.', array('%permission' => $this->invalid_permission)), 'Role', 'Fail'); + + $this->test_ids[] = $test_id = $this->getTestIdFromResults(); + $this->assertTrue($test_id, t('Found test ID in results.')); + } + + /** + * Fetch the test id from the test results. + */ + function getTestIdFromResults() { + foreach($this->results['assertions'] as $assertion) { + if (preg_match('@^Test ID is ([0-9]*)\.$@', $assertion['message'], $matches)) { + return $matches[1]; + } + } + return NULL; } /** |