src/DrupalExtension/Context/SelectFieldContext.php
protected function getSelectedOptionByLabel($select, $option_label, $check_selected = TRUE) {
    if (!$field = $this->getSession()->getPage()->findField($select)) {
      throw new ExpectationException("Field '$select' not found.", $this->getSession());
    }

    /* @var \Behat\Mink\Element\NodeElement $field */

    // Check that the specified field is a <select> field.
    $this->assertElementType($field, 'select');

    $options = $field->findAll('css', 'option');
    $options = array_filter($options, function (NodeElement $option) use ($option_label) {
      return $option->getText() == $option_label ? $option : FALSE;
    });

    if (!($option = $options ? reset($options) : NULL)) {
      throw new ExpectationException("Option '$option_label' doesn't exist in '$select' select.", $this->getSession());
    }

    return $check_selected ? $option->isSelected() : !$option->isSelected();
  }
protected function getSelectedOptionByLabel($select, $option_label, $check_selected = TRUE) {
    if (!$field = $this->getSession()->getPage()->findField($select)) {
      throw new ExpectationException("Field '$select' not found.", $this->getSession());
    }

    /* @var \Behat\Mink\Element\NodeElement $field */

    // Check that the specified field is a <select> field.
    $this->assertElementType($field, 'select');

    $options = $field->findAll('css', 'option');
    $options = array_filter($options, function (NodeElement $option) use ($option_label) {
      return $option->getText() == $option_label ? $option : FALSE;
    });

    if (!($option = $options ? reset($options) : NULL)) {
      throw new ExpectationException("Option '$option_label' doesn't exist in '$select' select.", $this->getSession());
    }

    return $check_selected ? $option->isSelected() : !$option->isSelected();
  }
protected function getSelectedOptionByLabel ( $ select , $ option_label , $ check_selected = TRUE ) { if ( ! $ field = $ this -> getSession ( ) -> getPage ( ) -> findField ( $ select ) ) { throw new ExpectationException ( "Field '$select' not found." , $ this -> getSession ( ) ) ; } /* @var \Behat\Mink\Element\NodeElement $field */ // Check that the specified field is a <select> field. $ this -> assertElementType ( $ field , 'select' ) ; $ options = $ field -> findAll ( 'css' , 'option' ) ; $ options = array_filter ( $ options , function ( NodeElement $ option ) use ( $ option_label ) { return $ option -> getText ( ) == $ option_label ? $ option : FALSE ; } ) ; if ( ! ( $ option = $ options ? reset ( $ options ) : NULL ) ) { throw new ExpectationException ( "Option '$option_label' doesn't exist in '$select' select." , $ this -> getSession ( ) ) ; } return $ check_selected ? $ option -> isSelected ( ) : ! $ option -> isSelected ( ) ; }
Returns an option from a specific select.

@param string $select
The select name.
@param string $option_label
The option text.
@param bool $check_selected
(optional) If TRUE, will check for selected option, if FALSE for
unselected. Defaults to TRUE.

@return \Behat\Mink\Element\NodeElement|null
The node element or NULL.

@throws \Behat\Mink\Exception\ExpectationException
Returns an option from a specific select .