You are here

function AlterTest::testAlterChangeFields in Zircon Profile 8

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

Tests that we can alter the fields of a query.

File

core/modules/system/src/Tests/Database/AlterTest.php, line 84
Contains \Drupal\system\Tests\Database\AlterTest.

Class

AlterTest
Tests the hook_query_alter capabilities of the Select builder.

Namespace

Drupal\system\Tests\Database

Code

function testAlterChangeFields() {
  $query = db_select('test');
  $name_field = $query
    ->addField('test', 'name');
  $age_field = $query
    ->addField('test', 'age', 'age');
  $query
    ->orderBy('name');
  $query
    ->addTag('database_test_alter_change_fields');
  $record = $query
    ->execute()
    ->fetch();
  $this
    ->assertEqual($record->{$name_field}, 'George', 'Correct data retrieved.');
  $this
    ->assertFalse(isset($record->{$age_field}), 'Age field not found, as intended.');
}