You are here

public function FieldKernelTest::testQuery in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/Handler/FieldKernelTest.php \Drupal\views\Tests\Handler\FieldKernelTest::testQuery()

Tests all things related to the query.

File

core/modules/views/src/Tests/Handler/FieldKernelTest.php, line 73
Contains \Drupal\views\Tests\Handler\FieldKernelTest.

Class

FieldKernelTest
Tests the generic field handler.

Namespace

Drupal\views\Tests\Handler

Code

public function testQuery() {

  // Tests adding additional fields to the query.
  $view = Views::getView('test_view');
  $view
    ->initHandlers();
  $id_field = $view->field['id'];
  $id_field->additional_fields['job'] = 'job';

  // Choose also a field alias key which doesn't match to the table field.
  $id_field->additional_fields['created_test'] = array(
    'table' => 'views_test_data',
    'field' => 'created',
  );
  $view
    ->build();

  // Make sure the field aliases have the expected value.
  $this
    ->assertEqual($id_field->aliases['job'], 'views_test_data_job');
  $this
    ->assertEqual($id_field->aliases['created_test'], 'views_test_data_created');
  $this
    ->executeView($view);

  // Tests the getValue method with and without a field aliases.
  foreach ($this
    ->dataSet() as $key => $row) {
    $id = $key + 1;
    $result = $view->result[$key];
    $this
      ->assertEqual($id_field
      ->getValue($result), $id);
    $this
      ->assertEqual($id_field
      ->getValue($result, 'job'), $row['job']);
    $this
      ->assertEqual($id_field
      ->getValue($result, 'created_test'), $row['created']);
  }
}