You are here

public function StyleTableTest::testAccessibilitySettings in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Functional/Plugin/StyleTableTest.php \Drupal\Tests\views\Functional\Plugin\StyleTableTest::testAccessibilitySettings()
  2. 9 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 41

Class

StyleTableTest
Tests the table style views plugin.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testAccessibilitySettings() {
  $this
    ->drupalGet('test-table');
  $result = $this
    ->xpath('//caption/child::text()');
  $this
    ->assertNotEmpty($result, 'The caption appears on the table.');
  $this
    ->assertEquals('caption-text', trim($result[0]
    ->getText()));
  $result = $this
    ->xpath('//summary/child::text()');
  $this
    ->assertNotEmpty($result, 'The summary appears on the table.');
  $this
    ->assertEquals('summary-text', trim($result[0]
    ->getText()));

  // Check that the summary has the right accessibility settings.
  $summary = $this
    ->xpath('//summary')[0];
  $this
    ->assertTrue($summary
    ->hasAttribute('role'));
  $this
    ->assertTrue($summary
    ->hasAttribute('aria-expanded'));
  $result = $this
    ->xpath('//caption/details/child::text()[normalize-space()]');
  $this
    ->assertNotEmpty($result, 'The table description appears on the table.');
  $this
    ->assertEquals('description-text', trim($result[0]
    ->getText()));

  // 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');
  $result = $this
    ->xpath('//caption/child::text()');
  $this
    ->assertEmpty(trim($result[0]
    ->getText()), 'Ensure that the caption disappears.');

  // Remove the table summary.
  $display =& $view
    ->getDisplay('default');
  $display['display_options']['style']['options']['summary'] = '';
  $view
    ->save();
  $this
    ->drupalGet('test-table');
  $result = $this
    ->xpath('//summary/child::text()');
  $this
    ->assertEmpty($result, 'Ensure that the summary disappears.');

  // Remove the table description.
  $display =& $view
    ->getDisplay('default');
  $display['display_options']['style']['options']['description'] = '';
  $view
    ->save();
  $this
    ->drupalGet('test-table');
  $result = $this
    ->xpath('//caption/details/child::text()[normalize-space()]');
  $this
    ->assertEmpty($result, 'Ensure that the description disappears.');
}