You are here

public function TestSubContext::assertSeeRadioById in Drupal Commons 7.3

@Then I should see the radio button :field with the id :id @Then I should see the radio button :field

File

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

Class

TestSubContext

Code

public function assertSeeRadioById($field, $id = FALSE) {
  $element = $this
    ->getSession()
    ->getPage();
  $radiobutton = $id ? $element
    ->findById($id) : $element
    ->find('named', array(
    'radio',
    $this
      ->getSession()
      ->getSelectorsHandler()
      ->xpathLiteral($field),
  ));
  if ($radiobutton === NULL) {
    throw new \Exception(sprintf('The radio button with "%s" was not found on the page %s', $id ? $id : $field, $this
      ->getSession()
      ->getCurrentUrl()));
  }
  if ($id) {
    $value = $radiobutton
      ->getAttribute('value');
    $labelonpage = $radiobutton
      ->getParent()
      ->getText();
    if ($field != $labelonpage) {
      throw new \Exception(sprintf("Button with id '%s' has label '%s' instead of '%s' on the page %s", $id, $labelonpage, $field, $this
        ->getSession()
        ->getCurrentUrl()));
    }
  }
}