public function TestSubContext::theSelectShouldBeSetTo in Panopoly 8.2
Same name and namespace in other branches
- 7 modules/panopoly/panopoly_test/behat/steps/panopoly_test.behat.inc \TestSubContext::theSelectShouldBeSetTo()
Asserts select field value.
@Then the :field select should be set to :value
File
- modules/
panopoly/ panopoly_test/ behat/ steps/ panopoly_test.behat.inc, line 965 - Provide Behat step-definitions for generic Panopoly tests.
Class
- TestSubContext
- Behat sub-context for Panopoly.
Code
public function theSelectShouldBeSetTo($field, $value) {
$select = $this
->getSession()
->getPage()
->findField($field);
if (empty($select)) {
throw new \Exception(sprintf('We couldn\'nt find "%s" on the page', $field));
}
$options = $select
->findAll('xpath', '//option[@selected="selected"]');
if (empty($select)) {
throw new \Exception(sprintf('The select "%s" doesn\'t have any options selected', $field));
}
$found = FALSE;
foreach ($options as $option) {
if ($option
->getText() === $value) {
$found = TRUE;
break;
}
}
if (!$found) {
throw new \Exception(sprintf('The select "%s" doesn\'t have the option "%s" selected', $field, $value));
}
}