summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/database_test.test
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2008-10-25 04:26:30 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2008-10-25 04:26:30 +0000
commita406555460b07e87a5f3e0bee5be2fbf65868de2 (patch)
tree3c97ed6018b47dd6aa10025491232133dd2a68e0 /modules/simpletest/tests/database_test.test
parenta7481a7cfa3a34f27c1f3fafaaced5a5540c99a7 (diff)
downloadbrdo-a406555460b07e87a5f3e0bee5be2fbf65868de2.tar.gz
brdo-a406555460b07e87a5f3e0bee5be2fbf65868de2.tar.bz2
#318440 by Crell: Make it easier to add multiple fields in a dynamic SELECT statement.
Diffstat (limited to 'modules/simpletest/tests/database_test.test')
-rw-r--r--modules/simpletest/tests/database_test.test49
1 files changed, 48 insertions, 1 deletions
diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test
index adc94a39e..fa17db442 100644
--- a/modules/simpletest/tests/database_test.test
+++ b/modules/simpletest/tests/database_test.test
@@ -1042,6 +1042,54 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
$this->assertEqual($record->$name_field, 'George', t('Fetched name is correct.'));
$this->assertEqual($record->$age_field, 27*2, t('Fetched age expression is correct.'));
}
+
+ /**
+ * Test adding multiple fields to a select statement at the same time.
+ */
+ function testSimpleSelectMultipleFields() {
+
+ $record = db_select('test')
+ ->fields('test', array('id', 'name', 'age', 'job'))
+ ->condition('age', 27)
+ ->execute()->fetchObject();
+
+ // Check that all fields we asked for are present.
+ $this->assertNotNull($record->id, t('ID field is present.'));
+ $this->assertNotNull($record->name, t('Name field is present.'));
+ $this->assertNotNull($record->age, t('Age field is present.'));
+ $this->assertNotNull($record->job, t('Job field is present.'));
+
+ // Ensure that we got the right record.
+ // Check that all fields we asked for are present.
+ $this->assertEqual($record->id, 2, t('ID field has the correct value.'));
+ $this->assertEqual($record->name, 'George', t('Name field has the correct value.'));
+ $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 adding all fields from a given table to a select statement.
+ */
+ function testSimpleSelectAllFields() {
+
+ $record = db_select('test')
+ ->fields('test')
+ ->condition('age', 27)
+ ->execute()->fetchObject();
+
+ // Check that all fields we asked for are present.
+ $this->assertNotNull($record->id, t('ID field is present.'));
+ $this->assertNotNull($record->name, t('Name field is present.'));
+ $this->assertNotNull($record->age, t('Age field is present.'));
+ $this->assertNotNull($record->job, t('Job field is present.'));
+
+ // Ensure that we got the right record.
+ // Check that all fields we asked for are present.
+ $this->assertEqual($record->id, 2, t('ID field has the correct value.'));
+ $this->assertEqual($record->name, 'George', t('Name field has the correct value.'));
+ $this->assertEqual($record->age, 27, t('Age field has the correct value.'));
+ $this->assertEqual($record->job, 'Singer', t('Job field has the correct value.'));
+ }
}
/**
@@ -1119,7 +1167,6 @@ class DatabaseSelectOrderedTestCase extends DatabaseTestCase {
}
}
-
/**
* Test order by descending.
*/