You are here

public function QueryGroupByTest::testGroupByBaseField in Zircon Profile 8

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

Tests grouping on base field.

File

core/modules/views/src/Tests/QueryGroupByTest.php, line 202
Contains \Drupal\views\Tests\QueryGroupByTest.

Class

QueryGroupByTest
Tests aggregate functionality of views, for example count.

Namespace

Drupal\views\Tests

Code

public function testGroupByBaseField() {
  $this
    ->setupTestEntities();
  $view = Views::getView('test_group_by_count');
  $view
    ->setDisplay();

  // This tests that the GROUP BY portion of the query is properly formatted
  // to include the base table to avoid ambiguous field errors.
  $view->displayHandlers
    ->get('default')->options['fields']['name']['group_type'] = 'min';
  unset($view->displayHandlers
    ->get('default')->options['fields']['id']['group_type']);
  $this
    ->executeView($view);
  $this
    ->assertTrue(strpos($view->build_info['query'], 'GROUP BY entity_test.id'), 'GROUP BY field includes the base table name when grouping on the base field.');
}