function QueryGroupByTest::testGroupByBaseField

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Kernel/QueryGroupByTest.php \Drupal\Tests\views\Kernel\QueryGroupByTest::testGroupByBaseField()
  2. 10 core/modules/views/tests/src/Kernel/QueryGroupByTest.php \Drupal\Tests\views\Kernel\QueryGroupByTest::testGroupByBaseField()
  3. 11.x 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 223

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

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