function StyleTableTest::testAccessibilitySettings

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

Tests table caption/summary/description.

File

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

Class

StyleTableTest
Tests the table style views plugin.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testAccessibilitySettings() {
    $this->drupalGet('test-table');
    $this->assertSession()
        ->elementExists('xpath', '//caption/child::text()');
    $this->assertSession()
        ->elementTextEquals('xpath', '//caption/child::text()', 'caption-text');
    $this->assertSession()
        ->elementExists('xpath', '//summary/child::text()');
    $this->assertSession()
        ->elementTextEquals('xpath', '//summary/child::text()', 'summary-text');
    // Check that the summary has the right accessibility settings.
    $this->assertSession()
        ->elementAttributeExists('xpath', '//summary', 'role');
    $this->assertSession()
        ->elementAttributeExists('xpath', '//summary', 'aria-expanded');
    $this->assertSession()
        ->elementExists('xpath', '//caption/details/child::text()[normalize-space()]');
    $this->assertSession()
        ->elementTextEquals('xpath', '//caption/details/child::text()[normalize-space()]', 'description-text');
    // Remove the caption and ensure the caption is not displayed anymore.
    $view = View::load('test_table');
    $display =& $view->getDisplay('default');
    $display['display_options']['style']['options']['caption'] = '';
    $view->save();
    $this->drupalGet('test-table');
    $this->assertSession()
        ->elementTextEquals('xpath', '//caption/child::text()', '');
    // Remove the table summary.
    $display =& $view->getDisplay('default');
    $display['display_options']['style']['options']['summary'] = '';
    $view->save();
    $this->drupalGet('test-table');
    $this->assertSession()
        ->elementNotExists('xpath', '//summary/child::text()');
    // Remove the table description.
    $display =& $view->getDisplay('default');
    $display['display_options']['style']['options']['description'] = '';
    $view->save();
    $this->drupalGet('test-table');
    $this->assertSession()
        ->elementNotExists('xpath', '//caption/details/child::text()[normalize-space()]');
}

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