function AggregationAjaxTest::testSwitchAggregationFunctionViaAjax

Same name and namespace in other branches
  1. 11.x core/modules/views_ui/tests/src/FunctionalJavascript/AggregationAjaxTest.php \Drupal\Tests\views_ui\FunctionalJavascript\AggregationAjaxTest::testSwitchAggregationFunctionViaAjax()

Tests switching a field's aggregation function via the AJAX dialog.

File

core/modules/views_ui/tests/src/FunctionalJavascript/AggregationAjaxTest.php, line 62

Class

AggregationAjaxTest
Tests editing a field's aggregation function via AJAX.

Namespace

Drupal\Tests\views_ui\FunctionalJavascript

Code

public function testSwitchAggregationFunctionViaAjax() : void {
  $page = $this->getSession()
    ->getPage();
  $assert_session = $this->assertSession();
  // Add an isolated runtime display with a single field.
  $view_name = static::$testViews[0];
  $view = Views::getView($view_name);
  $display_id = $view->storage
    ->addDisplay('page');
  $display =& $view->storage
    ->getDisplay($display_id);
  $display['display_options']['defaults']['fields'] = FALSE;
  $display['display_options']['fields'] = [
    'changed' => [
      'id' => 'changed',
      'table' => 'node_field_data',
      'field' => 'changed',
      'relationship' => 'none',
      'group_type' => 'group',
      'plugin_id' => 'field',
      'entity_type' => 'node',
      'entity_field' => 'changed',
    ],
  ];
  $view->save();
  $this->drupalGet('admin/structure/views/view/' . $view_name . '/edit/' . $display_id);
  // Enable aggregation for the display.
  $this->openDisplayOptionDialog('group_by');
  $page->checkField('group_by');
  $this->pressDialogButton('Apply');
  $this->assertNotEmpty($assert_session->waitForElementRemoved('css', '.views-ui-dialog'), 'The "Use aggregation" dialog is still open after applying the change.');
  // Configure the field's aggregation function for the first time.
  $this->setFieldAggregationFunction('count');
  // Re-open the same, already-configured handler and switch the
  // aggregation function from COUNT to COUNT DISTINCT.
  $this->setFieldAggregationFunction('count_distinct');
  // Verify that the link to the aggregation settings is still present.
  $assert_session->linkExists('Aggregation settings');
}

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