You are here

public function FeatureContext::assertAudienceHasNoVariation in Acquia Lift Connector 7.2

@Then :variation variation should not be assigned to the :audience audience

File

behat-tests/features/bootstrap/FeatureContext.php, line 763

Class

FeatureContext
Defines application features from the specific context.

Code

public function assertAudienceHasNoVariation($variation_label, $audience_label) {
  $escaped_variation = $this
    ->getSession()
    ->getSelectorsHandler()
    ->xpathLiteral($variation_label);
  $audience_element = $this
    ->getAudienceElement($audience_label);
  if (empty($audience_element)) {
    throw new \Exception(sprintf('The "%s" audience container cannot be found on the page.', $audience_label));
  }
  $variation_select = $audience_element
    ->find('css', 'select[name*=assignment]');
  $variation_option = $variation_select
    ->find('named', array(
    'option',
    $escaped_variation,
  ));
  if (empty($variation_option)) {
    throw new \Exception(sprintf('The "%s" variation cannot be found in the "%s" audience variation select options.', $variation_label, $audience_label));
  }
  if ($variation_option
    ->isSelected()) {
    throw new \Exception(sprintf('The "%s" variation is selected for the "%s" audience.', $variation_label, $audience_label));
  }
  $variations_list = $audience_element
    ->find('css', '.acquia-lift-draggable-variations');
  $variation_display = $variations_list
    ->find('named', array(
    'content',
    $escaped_variation,
  ));
  if (!empty($variation_display)) {
    throw new \Exception(sprintf('The "%s" variation is displayed for "%s" audience.', $variation_label, $audience_label));
  }
}