You are here

public function QueryGroupByTest::testGroupByBaseField in Drupal 9

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

Tests grouping on base field.

File

core/modules/views/tests/src/Kernel/QueryGroupByTest.php, line 203

Class

QueryGroupByTest
Tests aggregate functionality of views, for example count.

Namespace

Drupal\Tests\views\Kernel

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
    ->assertStringContainsString('GROUP BY entity_test.id', (string) $view->build_info['query'], 'GROUP BY field includes the base table name when grouping on the base field.');
}