From a406555460b07e87a5f3e0bee5be2fbf65868de2 Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Sat, 25 Oct 2008 04:26:30 +0000 Subject: #318440 by Crell: Make it easier to add multiple fields in a dynamic SELECT statement. --- modules/simpletest/tests/database_test.test | 49 ++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'modules/simpletest/tests/database_test.test') 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. */ -- cgit v1.2.3