function EntityReferenceAdminTest::assertFieldSelectOptions

Same name in this branch
  1. 8.9.x core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\FunctionalJavascript\EntityReference\EntityReferenceAdminTest::assertFieldSelectOptions()
Same name in other branches
  1. 9 core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\FunctionalJavascript\EntityReference\EntityReferenceAdminTest::assertFieldSelectOptions()
  2. 9 core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceAdminTest::assertFieldSelectOptions()
  3. 10 core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\FunctionalJavascript\EntityReference\EntityReferenceAdminTest::assertFieldSelectOptions()
  4. 10 core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceAdminTest::assertFieldSelectOptions()
  5. 11.x core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\FunctionalJavascript\EntityReference\EntityReferenceAdminTest::assertFieldSelectOptions()
  6. 11.x core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\Functional\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::testAvailableFormatters in core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php
Tests the formatters for the Entity References.

File

core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php, line 392

Class

EntityReferenceAdminTest
Tests for the administrative UI.

Namespace

Drupal\Tests\field\Functional\EntityReference

Code

protected function assertFieldSelectOptions($name, array $expected_options) {
    $xpath = $this->buildXPathQuery('//select[@name=:name]', [
        ':name' => $name,
    ]);
    $fields = $this->xpath($xpath);
    if ($fields) {
        $field = $fields[0];
        $options = $field->findAll('xpath', 'option');
        array_walk($options, function (NodeElement &$option) {
            $option = $option->getValue();
        });
        sort($options);
        sort($expected_options);
        $this->assertIdentical($options, $expected_options);
    }
    else {
        $this->fail('Unable to find field ' . $name);
    }
}

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