You are here

public function TestSubContext::theSelectShouldBeSetTo in Drupal Commons 7.3

@Then the :field select should be set to :value

File

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

Class

TestSubContext

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