You are here

protected function AssertTrait::assertStylesList in Style Switcher 8.2

Same name and namespace in other branches
  1. 3.0.x tests/src/Functional/AssertTrait.php \Drupal\Tests\styleswitcher\Functional\AssertTrait::assertStylesList()

Asserts that a block contains an expected list of styles.

Parameters

string[] $expected: Expected list of style labels.

string $block_selector: CSS selector of the Style Switcher block.

string $page_path: (optional) A path to a page with the block.

3 calls to AssertTrait::assertStylesList()
ConfigTest::testConfigCustomStyles in tests/src/Functional/ConfigTest.php
Tests the custom styles config.
ConfigTest::testConfigStylesSettings in tests/src/Functional/ConfigTest.php
Tests the styles settings config.
MultiThemeTest::testBlockLinks in tests/src/Functional/MultiThemeTest.php
Tests links in the Style Switcher block.

File

tests/src/Functional/AssertTrait.php, line 20

Class

AssertTrait
Provides test assertions for the Style Switcher.

Namespace

Drupal\Tests\styleswitcher\Functional

Code

protected function assertStylesList(array $expected, string $block_selector, string $page_path = '') {
  $assert = $this
    ->assertSession();
  $this
    ->drupalGet($page_path);
  if ($expected) {

    // First, test the block exists.
    $block = $assert
      ->elementExists('css', $block_selector);
    $actual = [];
    foreach ($block
      ->findAll('css', 'ul a') as $link) {
      $actual[] = $link
        ->getText();
    }
    $this
      ->assertSame(array_values($expected), $actual);
  }
  else {

    // Test the block doesn't exist.
    $assert
      ->elementNotExists('css', $block_selector);
  }
}