function StyleTableTest::testFieldInColumns

Same name in other branches
  1. 9 core/modules/views/tests/src/Functional/Plugin/StyleTableTest.php \Drupal\Tests\views\Functional\Plugin\StyleTableTest::testFieldInColumns()
  2. 10 core/modules/views/tests/src/Functional/Plugin/StyleTableTest.php \Drupal\Tests\views\Functional\Plugin\StyleTableTest::testFieldInColumns()
  3. 11.x core/modules/views/tests/src/Functional/Plugin/StyleTableTest.php \Drupal\Tests\views\Functional\Plugin\StyleTableTest::testFieldInColumns()

Test table fields in columns.

File

core/modules/views/tests/src/Functional/Plugin/StyleTableTest.php, line 92

Class

StyleTableTest
Tests the table style views plugin.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testFieldInColumns() {
    $this->drupalGet('test-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->assertGreaterThan(0, count($result), '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->assertGreaterThan(0, count($result), '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('test_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('test-table');
    $result = $this->xpath('//tbody/tr/td[contains(concat(" ", @class, " "), " views-field-job views-field-job-1 ")]');
    $this->assertGreaterThan(0, count($result), 'Ensure that the job column class names are joined into a single column');
    $result = $this->xpath('//tbody/tr/td[contains(., "Drummer, Drummer")]');
    $this->assertGreaterThan(0, count($result), 'Ensure the job column values are joined into a single column');
}

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