Commit 5de34fb2 authored by Dries's avatar Dries
Browse files

- Patch #290316 by boombatower, Damien Tournoud et al: made simpletests work on PostgreSQL.

parent 28d2ee1a
......@@ -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;
}
......@@ -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(
......
......@@ -2,8 +2,17 @@
// $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().
*/
......@@ -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;
}
/**
......
Supports Markdown
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