You are here

public function FeatureContext::getVariationLinkCss in Acquia Lift Connector 7.2

Same name and namespace in other branches
  1. 7 behat-tests/features/bootstrap/FeatureContext.php \FeatureContext::getVariationLinkCss()

Helper function to generate the css for a variation action link.

Parameters

string $variation_set: The name of the variation set displayed

string $variation: The name of the variation displayed

string $link: The link text to find. One of "rename", "edit", or "delete".

Throws

\Exception If the link type is invalid or the current campaign is not available.

3 calls to FeatureContext::getVariationLinkCss()
FeatureContext::assertNotRegionVariationHasLink in behat-tests/features/bootstrap/FeatureContext.php
@Then :variation_set set :variation variation should not have the :link link
FeatureContext::assertRegionVariationHasLink in behat-tests/features/bootstrap/FeatureContext.php
@Then :variation_set set :variation variation should have the :link link
FeatureContext::assertRegionVariationHasLinkDisabled in behat-tests/features/bootstrap/FeatureContext.php
@Then :variation_set set :variation variation :link link is disabled

File

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

Class

FeatureContext
Defines application features from the specific context.

Code

public function getVariationLinkCss($variation_set, $variation, $link) {
  $link = drupal_strtolower($link);
  if (!in_array($link, array(
    'edit',
    'rename',
    'delete',
  ))) {
    throw new \Exception(sprintf('The variation action "%s" is invalid.', $link));
  }
  $campaign = $this
    ->getCurrentCampaign();
  if (empty($campaign)) {
    throw new \Exception(sprintf('Cannot determine the current personalization for variation set %s.', $variation_set));
  }
  $agent_instance = personalize_agent_load_agent($campaign);
  if (empty($agent_instance)) {
    throw new \Exception(sprintf('Cannot load the current agent instance for personalization %s.', $campaign));
  }
  $option_sets = personalize_option_set_load_by_agent($campaign, TRUE);
  foreach ($option_sets as $option_set) {
    if ($option_set->label == $variation_set) {
      $osid = $option_set->osid;
      foreach ($option_set->options as $option) {
        if ($option['option_label'] == $variation) {
          $option_id = $option['option_id'];
          break;
        }
      }
      break;
    }
  }
  if (empty($osid)) {
    throw new \Exception(sprintf('Cannot load the option set %s for personalization %s.', $variation_set, $campaign));
  }
  $css = '.acquia-lift-menu-item[data-acquia-lift-personalize-option-set="' . personalize_stringify_osid($osid) . '"]';
  switch ($link) {
    case "edit":
      $css .= ' a.acquia-lift-variation-edit';
      break;
    case "rename":
      $css .= ' a.acquia-lift-variation-rename';
      break;
    case "delete":
      $css .= ' a.acquia-lift-variation-delete';
      break;
  }
  $css .= '[data-acquia-lift-personalize-option-set-option="' . $option_id . '"]';
  return $css;
}