View source
<?php
namespace Drupal\Tests\views_aggregator\Functional\Plugin;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Entity\View;
class ViewsAggregatorResultsTest extends ViewTestBase {
public static $testViews = [
'va_test_style_table',
];
public static $modules = [
'views',
'views_aggregator',
'views_aggregator_test_config',
];
protected $defaultTheme = 'stark';
protected $strictConfigSchema = FALSE;
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this
->enableViewsTestModule();
ViewTestData::createTestViews(get_class($this), [
'views_aggregator_test_config',
]);
}
public function testPagerSettings() {
$this
->drupalGet('va-test-style-table');
$view = View::load('va_test_style_table');
$display =& $view
->getDisplay('default');
$display['display_options']['pager']['type'] = 'full';
$display['display_options']['pager']['options']['items_per_page'] = 3;
$display['display_options']['pager']['options']['offset'] = 0;
$display['display_options']['pager']['options']['id'] = 0;
$display['display_options']['pager']['options']['total_pages'] = NULL;
$view
->save();
$this
->drupalGet('va-test-style-table');
$this
->assertFieldByXPath('//thead/tr/td', '84');
$display =& $view
->getDisplay('default');
$display['display_options']['style']['options']['column_aggregation']['totals_per_page'] = '0';
$view
->save();
$this
->drupalGet('va-test-style-table');
$this
->assertFieldByXPath('//thead/tr/td', '136');
}
public function testTotalsSettings() {
$this
->drupalGet('va-test-style-table');
$this
->assertFieldByXPath('//thead/tr/td', 'TOTAL');
$this
->assertFieldByXPath('//tfoot/tr/td', 'TOTAL');
$view = View::load('va_test_style_table');
$display =& $view
->getDisplay('default');
$display['display_options']['style']['options']['column_aggregation']['totals_row_position']['1'] = '1';
$display['display_options']['style']['options']['column_aggregation']['totals_row_position']['2'] = '0';
$view
->save();
$this
->drupalGet('va-test-style-table');
$this
->assertFieldByXPath('//thead/tr/td', 'TOTAL');
$this
->assertNoFieldByXPath('//tfoot/tr/td', 'TOTAL');
$display =& $view
->getDisplay('default');
$display['display_options']['style']['options']['column_aggregation']['totals_row_position']['1'] = '0';
$display['display_options']['style']['options']['column_aggregation']['totals_row_position']['2'] = '2';
$view
->save();
$this
->drupalGet('va-test-style-table');
$this
->assertNoFieldByXPath('//thead/tr/td', 'TOTAL');
$this
->assertFieldByXPath('//tfoot/tr/td', 'TOTAL');
}
public function testGroupResultFunctions() {
$this
->drupalGet('va-test-style-table');
$view = View::load('va_test_style_table');
$display =& $view
->getDisplay('default');
$this
->assertNoUniqueText('Singer');
$this
->assertNoFieldByXPath('//tbody/tr/td[@headers="view-age-table-column" and @class="views-field views-field-age"]', '52');
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();
$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');
$this
->assertRaw('George (1)<br />John (1)');
$this
->assertUniqueText('Singer');
$this
->assertFieldByXPath('//tbody/tr/td[@headers="view-age-table-column" and @class="views-field views-field-age"]', '52');
$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');
$this
->assertRaw('George<br />John');
$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');
$this
->assertFieldByXpath('//tbody/tr/td[@headers="view-name-table-column" and @class="views-field views-field-name"]', '2');
}
public function testColumnResultFunctions() {
$this
->drupalGet('va-test-style-table');
$this
->assertFieldByXPath('//thead/tr/td', '136');
$this
->assertFieldByXPath('//thead/tr/td', 'TOTAL');
$view = View::load('va_test_style_table');
$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');
$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');
$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');
$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>');
$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');
$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');
$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');
$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');
$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');
}
}