You are here

public function ViewsAggregatorStyleTableTest::testFieldInColumns in Views Aggregator Plus 8

Test table fields in columns.

File

tests/src/Functional/Plugin/ViewsAggregatorStyleTableTest.php, line 96

Class

ViewsAggregatorStyleTableTest
Tests the views aggregator result table style plugin.

Namespace

Drupal\Tests\views_aggregator\Functional\Plugin

Code

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

  // Ensure that both columns are in separate tds.
  // Check for class " views-field-job ", because just "views-field-job" won't
  // do: "views-field-job-1" would also contain "views-field-job".
  // @see Drupal\system\Tests\Form\ElementTest::testButtonClasses().
  $result = $this
    ->xpath('//tbody/tr/td[contains(concat(" ", @class, " "), " views-field-job ")]');
  $this
    ->assertTrue(count($result) > 0, 'Ensure there is a td with the class views-field-job');
  $result = $this
    ->xpath('//tbody/tr/td[contains(concat(" ", @class, " "), " views-field-job-1 ")]');
  $this
    ->assertTrue(count($result) > 0, 'Ensure there is a td with the class views-field-job-1');

  // Combine the second job-column with the first one, with ', ' as separator.
  $view = View::load('va_test_style_table');
  $display =& $view
    ->getDisplay('default');
  $display['display_options']['style']['options']['columns']['job_1'] = 'job';
  $display['display_options']['style']['options']['info']['job']['separator'] = ', ';
  $view
    ->save();

  // Ensure that both columns are properly combined.
  $this
    ->drupalGet('va-test-style-table');
  $result = $this
    ->xpath('//tbody/tr/td[contains(concat(" ", @class, " "), " views-field-job views-field-job-1 ")]');
  $this
    ->assertTrue(count($result) > 0, 'Ensure that the job column class names are joined into a single column');
  $result = $this
    ->xpath('//tbody/tr/td[contains(., "Drummer, Drummer")]');
  $this
    ->assertTrue(count($result) > 0, 'Ensure the job column values are joined into a single column');
}