You are here

protected function UiPatternsLibraryOverviewTest::assertPatternFields in UI Patterns 8

Assert pattern table fields.

Parameters

string $root: CSS selector of element containing the table.

array $pattern: Expected pattern.

Throws

\Behat\Mink\Exception\ElementHtmlException

1 call to UiPatternsLibraryOverviewTest::assertPatternFields()
UiPatternsLibraryOverviewTest::assertPatternPreview in modules/ui_patterns_library/tests/src/FunctionalJavascript/UiPatternsLibraryOverviewTest.php
Assert pattern preview display.

File

modules/ui_patterns_library/tests/src/FunctionalJavascript/UiPatternsLibraryOverviewTest.php, line 142

Class

UiPatternsLibraryOverviewTest
Test patterns overview page.

Namespace

Drupal\Tests\ui_patterns_library\FunctionalJavascript

Code

protected function assertPatternFields($root, array $pattern) {
  $session = $this
    ->assertSession();

  // Assert table header.
  foreach ([
    'Field',
    'Label',
    'Type',
    'Description',
  ] as $index => $item) {
    $child = $index + 1;
    $session
      ->elementContains('css', "{$root} > table.pattern-preview__fields > thead > tr > th:nth-child({$child})", $item);
  }

  // Assert field table rows.
  foreach ($pattern['fields'] as $index => $field) {
    $child = $index + 1;
    $row_root = "{$root} > table.pattern-preview__fields > tbody > tr:nth-child({$child})";
    $session
      ->elementContains('css', "{$row_root} > td:nth-child(1)", $field['name']);
    $session
      ->elementContains('css', "{$row_root} > td:nth-child(2)", $field['label']);
    $session
      ->elementContains('css', "{$row_root} > td:nth-child(3)", $field['type']);
    $session
      ->elementContains('css', "{$row_root} > td:nth-child(4)", $field['description']);
  }
}