function SelectTest::testSimpleSelectMultipleFields

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/SelectTest.php \Drupal\KernelTests\Core\Database\SelectTest::testSimpleSelectMultipleFields()
  2. 10 core/tests/Drupal/KernelTests/Core/Database/SelectTest.php \Drupal\KernelTests\Core\Database\SelectTest::testSimpleSelectMultipleFields()
  3. 11.x core/tests/Drupal/KernelTests/Core/Database/SelectTest.php \Drupal\KernelTests\Core\Database\SelectTest::testSimpleSelectMultipleFields()

Tests adding multiple fields to a SELECT statement at the same time.

File

core/tests/Drupal/KernelTests/Core/Database/SelectTest.php, line 168

Class

SelectTest
Tests the Select query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testSimpleSelectMultipleFields() {
  $record = $this->connection
    ->select('test')
    ->fields('test', [
    'id',
    'name',
    'age',
    'job',
  ])
    ->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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.