You are here

protected function EntityReferenceAdminTest::assertFieldSelectOptions in Drupal 9

Same name in this branch
  1. 9 core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceAdminTest::assertFieldSelectOptions()
  2. 9 core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\FunctionalJavascript\EntityReference\EntityReferenceAdminTest::assertFieldSelectOptions()
Same name and namespace in other branches
  1. 8 core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\FunctionalJavascript\EntityReference\EntityReferenceAdminTest::assertFieldSelectOptions()

Checks if a select element contains the specified options.

Parameters

string $name: The field name.

array $expected_options: An array of expected options.

1 call to EntityReferenceAdminTest::assertFieldSelectOptions()
EntityReferenceAdminTest::testFieldAdminHandler in core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php
Tests the Entity Reference Admin UI.

File

core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php, line 356

Class

EntityReferenceAdminTest
Tests for the administrative UI.

Namespace

Drupal\Tests\field\FunctionalJavascript\EntityReference

Code

protected function assertFieldSelectOptions($name, array $expected_options) {
  $field = $this
    ->assertSession()
    ->selectExists($name);
  $options = $field
    ->findAll('xpath', 'option');
  $optgroups = $field
    ->findAll('xpath', 'optgroup');
  foreach ($optgroups as $optgroup) {
    $options = array_merge($options, $optgroup
      ->findAll('xpath', 'option'));
  }
  array_walk($options, function (NodeElement &$option) {
    $option = $option
      ->getAttribute('value');
  });
  $this
    ->assertEqualsCanonicalizing($expected_options, $options);
}