You are here

public function TestSubContext::theRadioButtonShouldBeSetTo in Drupal Commons 7.3

@Then the :field radio button should be set to :option

@link: https://www.drupal.org/node/1891584 @endlink

File

tests/steps/commons_test.behat.inc, line 541
Provide Behat step-definitions for generic Commons tests.

Class

TestSubContext

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__);
  }
}