You are here

public function ViewsAggregatorResultsTest::testGroupResultFunctions in Views Aggregator Plus 8

Test the group functions.

File

tests/src/Functional/Plugin/ViewsAggregatorResultsTest.php, line 123

Class

ViewsAggregatorResultsTest
Tests the views aggregator results.

Namespace

Drupal\Tests\views_aggregator\Functional\Plugin

Code

public function testGroupResultFunctions() {
  $this
    ->drupalGet('va-test-style-table');
  $view = View::load('va_test_style_table');
  $display =& $view
    ->getDisplay('default');

  // Make sure 'Singer' appears multiple times on the page.
  $this
    ->assertNoUniqueText('Singer');

  // Make sure 'age' is not grouped either.
  $this
    ->assertNoFieldByXPath('//tbody/tr/td[@headers="view-age-table-column" and @class="views-field views-field-age"]', '52');

  // Remove the 'job_1' column.
  unset($display['display_options']['fields']['job_1']);
  unset($display['display_options']['style']['options']['columns']['job_1']);
  unset($display['display_options']['style']['options']['info']['job_1']);
  $view
    ->save();

  // Set the 'Group and compress' and 'Tally members' functions.
  $display =& $view
    ->getDisplay('default');
  $display['display_options']['style']['options']['caption'] = 'Test group + compress and Tally';
  $display['display_options']['style']['options']['info']['job']['aggr'] = [];
  $display['display_options']['style']['options']['info']['job']['aggr']['views_aggregator_group_and_compress'] = 'views_aggregator_group_and_compress';
  $display['display_options']['style']['options']['info']['job']['has_aggr'] = 1;
  $display['display_options']['style']['options']['info']['name']['aggr'] = [];
  $display['display_options']['style']['options']['info']['name']['aggr']['views_aggregator_tally'] = 'views_aggregator_tally';
  $display['display_options']['style']['options']['info']['name']['has_aggr'] = 1;
  $view
    ->save();
  $this
    ->drupalGet('va-test-style-table');

  // Check if 'Tally members' function worked.
  $this
    ->assertRaw('George (1)<br />John (1)');

  // Check if 'Singer' is found only once.
  $this
    ->assertUniqueText('Singer');

  // Check that 'age' is grouped, compressed and sum is applied.
  $this
    ->assertFieldByXPath('//tbody/tr/td[@headers="view-age-table-column" and @class="views-field views-field-age"]', '52');

  // Set the 'Enumerate (sort., no dupl.)' function.
  $display =& $view
    ->getDisplay('default');
  $display['display_options']['style']['options']['caption'] = 'Test group & compress + Enumerate no dupl.';
  $display['display_options']['style']['options']['info']['name']['aggr'] = [];
  $display['display_options']['style']['options']['info']['name']['aggr']['views_aggregator_enumerate'] = 'views_aggregator_enumerate';
  $display['display_options']['style']['options']['info']['name']['has_aggr'] = 1;
  $view
    ->save();
  $this
    ->drupalGet('va-test-style-table');

  // Check if 'Enumerate (sort., no dupl.)' function worked.
  $this
    ->assertRaw('George<br />John');

  // Set the 'Count unique' function.
  $display =& $view
    ->getDisplay('default');
  $display['display_options']['style']['options']['caption'] = 'Test group & compress + Count unique';
  $display['display_options']['style']['options']['info']['name']['aggr'] = [];
  $display['display_options']['style']['options']['info']['name']['aggr']['views_aggregator_count_unique'] = 'views_aggregator_count_unique';
  $display['display_options']['style']['options']['info']['name']['has_aggr'] = 1;
  $view
    ->save();
  $this
    ->drupalGet('va-test-style-table');

  // Check if 'Count unique' function worked.
  $this
    ->assertFieldByXpath('//tbody/tr/td[@headers="view-name-table-column" and @class="views-field views-field-name"]', '2');
}