protected function BrowserTestBase::getOptions in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/simpletest/src/BrowserTestBase.php \Drupal\simpletest\BrowserTestBase::getOptions()
Helper function to get the options of select field.
Parameters
\Behat\Mink\Element\NodeElement|string $select: Name, ID, or Label of select field to assert.
\Behat\Mink\Element\Element $container: (optional) Container element to check against. Defaults to current page.
Return value
array Associative array of option keys and values.
File
- core/
modules/ simpletest/ src/ BrowserTestBase.php, line 789 - Contains \Drupal\simpletest\BrowserTestBase.
Class
- BrowserTestBase
- Provides a test case for functional Drupal tests.
Namespace
Drupal\simpletestCode
protected function getOptions($select, Element $container = NULL) {
if (is_string($select)) {
$select = $this
->assertSession()
->selectExists($select, $container);
}
$options = [];
/* @var \Behat\Mink\Element\NodeElement $option */
foreach ($select
->findAll('xpath', '//option') as $option) {
$label = $option
->getText();
$value = $option
->getAttribute('value') ?: $label;
$options[$value] = $label;
}
return $options;
}