GroupByTest.php in Drupal 9
File
core/modules/views_ui/tests/src/Functional/GroupByTest.php
View source
<?php
namespace Drupal\Tests\views_ui\Functional;
class GroupByTest extends UITestBase {
public static $testViews = [
'test_views_groupby_save',
];
protected $defaultTheme = 'stark';
public function testGroupBySave() {
$this
->drupalGet('admin/structure/views/view/test_views_groupby_save/edit');
$edit_groupby_url = 'admin/structure/views/nojs/handler-group/test_views_groupby_save/default/field/id';
$this
->assertSession()
->linkByHrefNotExists($edit_groupby_url, 0, 'No aggregation link found.');
$edit = [
'group_by' => TRUE,
];
$this
->drupalGet('admin/structure/views/nojs/display/test_views_groupby_save/default/group_by');
$this
->submitForm($edit, 'Apply');
$this
->assertSession()
->linkByHrefExists($edit_groupby_url, 0, 'Aggregation link found.');
$this
->drupalGet($edit_groupby_url);
$this
->submitForm([
'options[group_type]' => 'count',
], 'Apply');
$this
->assertSession()
->linkExists('COUNT(Views test: ID)', 0, 'The count setting is displayed in the UI');
$this
->submitForm([], 'Save');
$view = $this->container
->get('entity_type.manager')
->getStorage('view')
->load('test_views_groupby_save');
$display = $view
->getDisplay('default');
$this
->assertTrue($display['display_options']['group_by'], 'The groupby setting was saved on the view.');
$this
->assertEquals('count', $display['display_options']['fields']['id']['group_type'], 'Count groupby_type was saved on the view.');
}
}