You are here

public function SocialMinkContext::iFillInSelectInputWithAndSelect in Open Social 10.1.x

Same name and namespace in other branches
  1. 8.9 tests/behat/features/bootstrap/SocialMinkContext.php \Drupal\social\Behat\SocialMinkContext::iFillInSelectInputWithAndSelect()
  2. 10.3.x tests/behat/features/bootstrap/SocialMinkContext.php \Drupal\social\Behat\SocialMinkContext::iFillInSelectInputWithAndSelect()
  3. 10.0.x tests/behat/features/bootstrap/SocialMinkContext.php \Drupal\social\Behat\SocialMinkContext::iFillInSelectInputWithAndSelect()
  4. 10.2.x tests/behat/features/bootstrap/SocialMinkContext.php \Drupal\social\Behat\SocialMinkContext::iFillInSelectInputWithAndSelect()

@When /^(?:|I )fill in select2 input "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)" and select "(?P<entry>(?:[^"]|\\")*)"$/

File

tests/behat/features/bootstrap/SocialMinkContext.php, line 84

Class

SocialMinkContext
Defines application features from the specific context.

Namespace

Drupal\social\Behat

Code

public function iFillInSelectInputWithAndSelect($field, $value, $entry) {
  $page = $this
    ->getSession()
    ->getPage();
  $inputField = $page
    ->find('css', $field);
  if (!$inputField) {
    throw new \Exception('No field found');
  }
  $this
    ->getSession()
    ->wait(1000);
  $choice = $inputField
    ->getParent()
    ->find('css', '.select2-selection');
  if (!$choice) {
    throw new \Exception('No select2 choice found');
  }
  $choice
    ->press();
  $select2Input = $page
    ->find('css', '.select2-search__field');
  if (!$select2Input) {
    throw new \Exception('No input found');
  }
  $select2Input
    ->setValue($value);
  $this
    ->getSession()
    ->wait(1000);
  $chosenResults = $page
    ->findAll('css', '.select2-results li');
  foreach ($chosenResults as $result) {
    if ($result
      ->getText() == $entry) {
      $result
        ->click();
      break;
    }
  }
}