You are here

protected function WidgetJSTest::assertSelectOptions in Facets 8

Checks that the given select option elements have the selected properties.

Parameters

array[] $expected: An array of expected properties, each an array with the following values:

  • The expected option text.
  • The expected option value.
  • A boolean indicating whether the option is expected to be selected.

\Behat\Mink\Element\NodeElement[] $options: The list of options to check.

1 call to WidgetJSTest::assertSelectOptions()
WidgetJSTest::testDropdownWidget in tests/src/FunctionalJavascript/WidgetJSTest.php
Tests dropdown widget.

File

tests/src/FunctionalJavascript/WidgetJSTest.php, line 363

Class

WidgetJSTest
Tests for the JS that transforms widgets into form elements.

Namespace

Drupal\Tests\facets\FunctionalJavascript

Code

protected function assertSelectOptions(array $expected, array $options) : void {
  $this
    ->assertCount(count($expected), $options);
  foreach ($expected as $key => [
    $text,
    $value,
    $selected,
  ]) {
    $option = $options[$key];

    // There can be multiple spaces or newlines between the value text and the
    // number of results. Reduce them to a single space before asserting.
    $this
      ->assertEquals($text, preg_replace('/\\s+/', ' ', $option
      ->getText()));
    $this
      ->assertEquals($value, $option
      ->getValue());
    $this
      ->assertEquals($selected, $option
      ->isSelected());
  }
}