function ManageDisplayTest::assertFieldSelectOptions

Same name in this branch
  1. 10 core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php \Drupal\Tests\field_ui\Functional\ManageDisplayTest::assertFieldSelectOptions()
Same name in other branches
  1. 9 core/modules/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php \Drupal\Tests\field_ui\FunctionalJavascript\ManageDisplayTest::assertFieldSelectOptions()
  2. 9 core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php \Drupal\Tests\field_ui\Functional\ManageDisplayTest::assertFieldSelectOptions()
  3. 8.9.x core/modules/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php \Drupal\Tests\field_ui\FunctionalJavascript\ManageDisplayTest::assertFieldSelectOptions()
  4. 8.9.x core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php \Drupal\Tests\field_ui\Functional\ManageDisplayTest::assertFieldSelectOptions()
  5. 11.x core/modules/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php \Drupal\Tests\field_ui\FunctionalJavascript\ManageDisplayTest::assertFieldSelectOptions()
  6. 11.x core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php \Drupal\Tests\field_ui\Functional\ManageDisplayTest::assertFieldSelectOptions()

Checks if a select element contains the specified options.

@internal

Parameters

\Behat\Mink\Element\NodeElement $field: The select field to validate.

array $expected_options: An array of expected options.

string|null $selected: The default value to validate.

2 calls to ManageDisplayTest::assertFieldSelectOptions()
ManageDisplayTest::testFormatterUI in core/modules/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php
Tests formatter settings.
ManageDisplayTest::testWidgetUI in core/modules/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php
Tests widget settings.

File

core/modules/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php, line 406

Class

ManageDisplayTest
Tests the Field UI "Manage display" and "Manage form display" screens.

Namespace

Drupal\Tests\field_ui\FunctionalJavascript

Code

protected function assertFieldSelectOptions(NodeElement $field, array $expected_options, ?string $selected = NULL) : void {
    
    /** @var \Behat\Mink\Element\NodeElement[] $select_options */
    $select_options = $field->findAll('xpath', 'option');
    // Validate the number of options.
    $this->assertSameSize($expected_options, $select_options);
    // Validate the options and expected order.
    foreach ($select_options as $key => $option) {
        $this->assertEquals($option->getAttribute('value'), $expected_options[$key]);
    }
    // Validate the default value if passed.
    if (!is_null($selected)) {
        $this->assertEquals($selected, $field->getValue());
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.