protected function FilterFormTest::assertOptions in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/filter/src/Tests/FilterFormTest.php \Drupal\filter\Tests\FilterFormTest::assertOptions()
Asserts that a select element has the correct options.
Parameters
string $id: The HTML ID of the select element.
array $expected_options: An array of option values.
string $selected: The value of the selected option.
Return value
bool TRUE if the assertion passed; FALSE otherwise.
3 calls to FilterFormTest::assertOptions()
- FilterFormTest::assertRequiredSelectAndOptions in core/
modules/ filter/ src/ Tests/ FilterFormTest.php - Asserts that there is a select element with the given ID that is required.
- FilterFormTest::doFilterFormTestAsAdmin in core/
modules/ filter/ src/ Tests/ FilterFormTest.php - Tests the behavior of the 'text_format' element as an administrator.
- FilterFormTest::doFilterFormTestAsNonAdmin in core/
modules/ filter/ src/ Tests/ FilterFormTest.php - Tests the behavior of the 'text_format' element as a normal user.
File
- core/
modules/ filter/ src/ Tests/ FilterFormTest.php, line 204 - Contains \Drupal\filter\Tests\FilterFormTest.
Class
- FilterFormTest
- Tests form elements with associated text formats.
Namespace
Drupal\filter\TestsCode
protected function assertOptions($id, array $expected_options, $selected) {
$select = $this
->xpath('//select[@id=:id]', array(
':id' => $id,
));
$select = reset($select);
$passed = $this
->assertTrue($select instanceof \SimpleXMLElement, SafeMarkup::format('Field @id exists.', array(
'@id' => $id,
)));
$found_options = $this
->getAllOptions($select);
foreach ($found_options as $found_key => $found_option) {
$expected_key = array_search($found_option
->attributes()->value, $expected_options);
if ($expected_key !== FALSE) {
$this
->pass(SafeMarkup::format('Option @option for field @id exists.', array(
'@option' => $expected_options[$expected_key],
'@id' => $id,
)));
unset($found_options[$found_key]);
unset($expected_options[$expected_key]);
}
}
// Make sure that all expected options were found and that there are no
// unexpected options.
foreach ($expected_options as $expected_option) {
$this
->fail(SafeMarkup::format('Option @option for field @id exists.', array(
'@option' => $expected_option,
'@id' => $id,
)));
$passed = FALSE;
}
foreach ($found_options as $found_option) {
$this
->fail(SafeMarkup::format('Option @option for field @id does not exist.', array(
'@option' => $found_option
->attributes()->value,
'@id' => $id,
)));
$passed = FALSE;
}
return $passed && $this
->assertOptionSelected($id, $selected);
}