public function TestSubContext::theRadioButtonShouldBeSetTo in Panopoly 8.2
Same name and namespace in other branches
- 7 modules/panopoly/panopoly_test/behat/steps/panopoly_test.behat.inc \TestSubContext::theRadioButtonShouldBeSetTo()
Asserts the selected radio button option.
@Then the :field radio button should be set to :option
@link: https://www.drupal.org/node/1891584 @endlink
File
- modules/
panopoly/ panopoly_test/ behat/ steps/ panopoly_test.behat.inc, line 894 - Provide Behat step-definitions for generic Panopoly tests.
Class
- TestSubContext
- Behat sub-context for Panopoly.
Code
public function theRadioButtonShouldBeSetTo($field, $option) {
$page = $this
->getSession()
->getPage();
$div = $page
->find('xpath', "//div[contains(., '{$field}') and @class[contains(.,'form-type-radio')]]");
if ($div) {
$radios = $div
->find('xpath', "//input[@type='radio']");
if ($radios) {
$checkedRadio = $div
->find('xpath', "//input[@type='radio' and @checked='checked']/following-sibling::label[contains(text(), '{$option}')] ");
if (!$checkedRadio) {
throw new \Exception(sprintf('We found the radio buttons for "%s", but "%s" was not selected.', $field, $option));
}
}
elseif (!$radios) {
throw new \Exception(sprintf('We found "%s", but it did not contain any radio buttons".', $field));
}
}
elseif (!$div) {
throw new \Exception(sprintf('We couldn\'nt find "%s" on the page', $field));
}
else {
throw new \Exception('General exception from ' . __FUNCTION__);
}
}