You are here

public function ViewsAggregatorResultsTest::testColumnResultFunctions in Views Aggregator Plus 8

Test the column functions.

File

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

Class

ViewsAggregatorResultsTest
Tests the views aggregator results.

Namespace

Drupal\Tests\views_aggregator\Functional\Plugin

Code

public function testColumnResultFunctions() {
  $this
    ->drupalGet('va-test-style-table');

  // We have 'Sum' selected as column aggregation on column 'age'.
  $this
    ->assertFieldByXPath('//thead/tr/td', '136');

  // And 'Label' as column aggregation on column 'ID'.
  $this
    ->assertFieldByXPath('//thead/tr/td', 'TOTAL');
  $view = View::load('va_test_style_table');

  // Function 'Average'.
  $display =& $view
    ->getDisplay('default');
  $display['display_options']['style']['options']['caption'] = 'Test column - Average';
  $display['display_options']['style']['options']['info']['age']['aggr_column'] = 'views_aggregator_average';
  $view
    ->save();
  $this
    ->drupalGet('va-test-style-table');
  $this
    ->assertFieldByXpath('//thead/tr/td[@id="view-age-table-column" and @class="views-field views-field-age"]', '27.2');

  // Function 'Count'.
  $display =& $view
    ->getDisplay('default');
  $display['display_options']['style']['options']['caption'] = 'Test column - Count';
  $display['display_options']['style']['options']['info']['age']['aggr_column'] = 'views_aggregator_count';
  $view
    ->save();
  $this
    ->drupalGet('va-test-style-table');
  $this
    ->assertFieldByXPath('//thead/tr/td', '5');

  // Function 'Count unique'.
  $display =& $view
    ->getDisplay('default');
  $display['display_options']['style']['options']['caption'] = 'Test column - Count unique';
  $display['display_options']['style']['options']['info']['job']['aggr_column'] = 'views_aggregator_count_unique';
  $display['display_options']['style']['options']['info']['job']['has_aggr_column'] = 1;
  $view
    ->save();
  $this
    ->drupalGet('va-test-style-table');
  $this
    ->assertFieldByXpath('//thead/tr/td[@id="view-job-table-column" and @class="views-field views-field-job"]', '4');

  // Function 'Enumerate raw'.
  $display =& $view
    ->getDisplay('default');
  $display['display_options']['style']['options']['caption'] = 'Test column - Enumerate';
  $display['display_options']['style']['options']['info']['job']['aggr_column'] = 'views_aggregator_enumerate_raw';
  $display['display_options']['style']['options']['info']['job']['has_aggr_column'] = 1;
  $view
    ->save();
  $this
    ->drupalGet('va-test-style-table');
  $this
    ->assertRaw('Speaker<br />Songwriter<br />Drummer<br />Singer<br />Singer</td>');

  // Function 'Enumerate (sort, no dupl.)'.
  $display =& $view
    ->getDisplay('default');
  $display['display_options']['style']['options']['caption'] = 'Test column - Enumerate (sort., no dupl.)';
  $display['display_options']['style']['options']['info']['job']['aggr_column'] = 'views_aggregator_enumerate';
  $display['display_options']['style']['options']['info']['job']['has_aggr_column'] = 1;
  $view
    ->save();
  $this
    ->drupalGet('va-test-style-table');
  $this
    ->assertRaw('Drummer<br />Singer<br />Songwriter<br />Speaker');

  // Function 'Maximum'.
  $display =& $view
    ->getDisplay('default');
  $display['display_options']['style']['options']['caption'] = 'Test column - Maximum';
  $display['display_options']['style']['options']['info']['age']['aggr_column'] = 'views_aggregator_maximum';
  $view
    ->save();
  $this
    ->drupalGet('va-test-style-table');
  $this
    ->assertFieldByXpath('//thead/tr/td[@id="view-age-table-column" and @class="views-field views-field-age"]', '30');

  // Function 'Median'.
  $display =& $view
    ->getDisplay('default');
  $display['display_options']['style']['options']['caption'] = 'Test column - Median';
  $display['display_options']['style']['options']['info']['age']['aggr_column'] = 'views_aggregator_median';
  $view
    ->save();
  $this
    ->drupalGet('va-test-style-table');
  $this
    ->assertFieldByXpath('//thead/tr/td[@id="view-age-table-column" and @class="views-field views-field-age"]', '27');

  // Function 'Minimum'.
  $display =& $view
    ->getDisplay('default');
  $display['display_options']['style']['options']['caption'] = 'Test column - Minimum';
  $display['display_options']['style']['options']['info']['age']['aggr_column'] = 'views_aggregator_minimum';
  $view
    ->save();
  $this
    ->drupalGet('va-test-style-table');
  $this
    ->assertFieldByXpath('//thead/tr/td[@id="view-age-table-column" and @class="views-field views-field-age"]', '25');

  // Function 'Range'.
  $display =& $view
    ->getDisplay('default');
  $display['display_options']['style']['options']['caption'] = 'Test column - Range';
  $display['display_options']['style']['options']['info']['age']['aggr_column'] = 'views_aggregator_range';
  $view
    ->save();
  $this
    ->drupalGet('va-test-style-table');
  $this
    ->assertFieldByXpath('//thead/tr/td[@id="view-age-table-column" and @class="views-field views-field-age"]', '25 - 30');
}