function FilterFormTest::assertRequiredSelectAndOptions

Same name and namespace in other branches
  1. 11.x core/modules/filter/tests/src/Functional/FilterFormTest.php \Drupal\Tests\filter\Functional\FilterFormTest::assertRequiredSelectAndOptions()
  2. 10 core/modules/filter/tests/src/Functional/FilterFormTest.php \Drupal\Tests\filter\Functional\FilterFormTest::assertRequiredSelectAndOptions()
  3. 9 core/modules/filter/tests/src/Functional/FilterFormTest.php \Drupal\Tests\filter\Functional\FilterFormTest::assertRequiredSelectAndOptions()
  4. main core/modules/filter/tests/src/Functional/FilterFormTest.php \Drupal\Tests\filter\Functional\FilterFormTest::assertRequiredSelectAndOptions()

Asserts that there is a select element with the given ID that is required.

Parameters

string $id: The HTML ID of the select element.

array $options: An array of option values that are contained in the select element besides the "- Select -" option.

Return value

bool TRUE if the assertion passed; FALSE otherwise.

1 call to FilterFormTest::assertRequiredSelectAndOptions()
FilterFormTest::doFilterFormTestAsAdmin in core/modules/filter/tests/src/Functional/FilterFormTest.php
Tests the behavior of the 'text_format' element as an administrator.

File

core/modules/filter/tests/src/Functional/FilterFormTest.php, line 245

Class

FilterFormTest
Tests form elements with associated text formats.

Namespace

Drupal\Tests\filter\Functional

Code

protected function assertRequiredSelectAndOptions($id, array $options) {
  $select = $this->xpath('//select[@id=:id and contains(@required, "required")]', [
    ':id' => $id,
  ]);
  $this->assertNotEmpty($select, new FormattableMarkup('Required field @id exists.', [
    '@id' => $id,
  ]));
  // A required select element has a "- Select -" option whose key is an empty
  // string.
  $options[] = '';
  $this->assertOptions($id, $options, '');
}

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