You are here

function SelectTest::testSimpleSelectAllFields in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Database/SelectTest.php \Drupal\system\Tests\Database\SelectTest::testSimpleSelectAllFields()

Tests adding all fields from a given table to a SELECT statement.

File

core/modules/system/src/Tests/Database/SelectTest.php, line 192
Contains \Drupal\system\Tests\Database\SelectTest.

Class

SelectTest
Tests the Select query builder.

Namespace

Drupal\system\Tests\Database

Code

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, 'ID field is present.');
  $this
    ->assertNotNull($record->name, 'Name field is present.');
  $this
    ->assertNotNull($record->age, 'Age field is present.');
  $this
    ->assertNotNull($record->job, '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, 'ID field has the correct value.');
  $this
    ->assertEqual($record->name, 'George', 'Name field has the correct value.');
  $this
    ->assertEqual($record->age, 27, 'Age field has the correct value.');
  $this
    ->assertEqual($record->job, 'Singer', 'Job field has the correct value.');
}