diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-03-14 17:45:55 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-03-14 17:45:55 +0000 |
commit | 193ba01e1fbdc525249f8c7ec0592831e1b7ffe2 (patch) | |
tree | 5b82dc0766cd3d558fc53f541816fab928d1c650 /modules/simpletest/tests/database_test.test | |
parent | 38969b48ffd65d8bbf2b7c6722288c5341d7a4f6 (diff) | |
download | brdo-193ba01e1fbdc525249f8c7ec0592831e1b7ffe2.tar.gz brdo-193ba01e1fbdc525249f8c7ec0592831e1b7ffe2.tar.bz2 |
#343999 by Crell, chx, and Alexander Pas: Add facility for doing NULL / NOT NULL conditions to DBTNG.
Diffstat (limited to 'modules/simpletest/tests/database_test.test')
-rw-r--r-- | modules/simpletest/tests/database_test.test | 70 |
1 files changed, 68 insertions, 2 deletions
diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test index 16b6c99fe..bc9a84b3b 100644 --- a/modules/simpletest/tests/database_test.test +++ b/modules/simpletest/tests/database_test.test @@ -27,6 +27,18 @@ class DatabaseTestCase extends DrupalWebTestCase { $schema['test_two_blobs'] = drupal_get_schema('test_two_blobs'); $schema['test_task'] = drupal_get_schema('test_task'); + $this->installTables($schema); + + $this->addSampleData(); + } + + /** + * Set up several tables needed by a certain test. + * + * @param $schema + * An array of table definitions to install. + */ + function installTables($schema) { // This ends up being a test for table drop and create, too, which is nice. $ret = array(); foreach ($schema as $name => $data) { @@ -39,8 +51,30 @@ class DatabaseTestCase extends DrupalWebTestCase { foreach ($schema as $name => $data) { $this->assertTrue(db_table_exists($name), t('Table @name created successfully.', array('@name' => $name))); } + } - $this->addSampleData(); + /** + * Set up tables for NULL handling. + */ + function ensureSampleDataNull() { + $schema['test_null'] = drupal_get_schema('test_null'); + $this->installTables($schema); + + db_insert('test_null') + ->fields(array('name', 'age')) + ->values(array( + 'name' => 'Kermit', + 'age' => 25, + )) + ->values(array( + 'name' => 'Fozzie', + 'age' => NULL, + )) + ->values(array( + 'name' => 'Gonzo', + 'age' => 27, + )) + ->execute(); } /** @@ -641,6 +675,7 @@ class DatabaseUpdateTestCase extends DatabaseTestCase { $num_matches = db_query("SELECT COUNT(*) FROM {test} WHERE job = :job", array(':job' => 'Musician'))->fetchField(); $this->assertIdentical($num_matches, '1', t('Updated fields successfully.')); } + } /** @@ -1033,7 +1068,6 @@ class DatabaseMergeTestCase extends DatabaseTestCase { /** * Test the SELECT builder. - * */ class DatabaseSelectTestCase extends DatabaseTestCase { @@ -1169,6 +1203,38 @@ class DatabaseSelectTestCase extends DatabaseTestCase { $this->assertEqual($record->age, 27, t('Age field has the correct value.')); $this->assertEqual($record->job, 'Singer', t('Job field has the correct value.')); } + + /** + * Test that we can find a record with a NULL value. + */ + function testNullCondition() { + $this->ensureSampleDataNull(); + + $names = db_select('test_null', 'tn') + ->fields('tn', array('name')) + ->isNull('age') + ->execute()->fetchCol(); + + $this->assertEqual(count($names), 1, t('Correct number of records found with NULL age.')); + $this->assertEqual($names[0], 'Fozzie', t('Correct record returned for NULL age.')); + } + + /** + * Test that we can find a record without a NULL value. + */ + function testNotNullCondition() { + $this->ensureSampleDataNull(); + + $names = db_select('test_null', 'tn') + ->fields('tn', array('name')) + ->isNotNull('tn.age') + ->orderBy('name') + ->execute()->fetchCol(); + + $this->assertEqual(count($names), 2, t('Correct number of records found withNOT NULL age.')); + $this->assertEqual($names[0], 'Gonzo', t('Correct record returned for NOT NULL age.')); + $this->assertEqual($names[1], 'Kermit', t('Correct record returned for NOT NULL age.')); + } } /** |