public function TestSubContext::theRadioButtonShouldBeSetTo in Panopoly 7
Same name and namespace in other branches
- 8.2 modules/panopoly/panopoly_test/behat/steps/panopoly_test.behat.inc \TestSubContext::theRadioButtonShouldBeSetTo()
@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 948 - Provide Behat step-definitions for generic Panopoly tests.
Class
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' and @id=(//label[contains(., '{$option}')]/@for)] ");
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__);
}
}