You are here

public function FeatureContext::getVariationLinkCss in Acquia Lift Connector 7

Same name and namespace in other branches
  1. 7.2 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.

2 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

File

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

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 campaign 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 campaign %s.', $campaign));
  }
  $option_sets = personalize_option_set_load_by_agent($campaign);
  if ($agent_instance instanceof AcquiaLiftSimpleAB) {

    // One decision with many variations.
    $option_set = reset($option_sets);
    foreach ($option_set->options as $index => $option) {
      if ($option['option_label'] == $variation) {
        break;
      }
    }
    $css = '.acquia-lift-menu-item[data-acquia-lift-personalize-agent="' . $campaign . '"]';
    switch ($link) {
      case "rename":
        $css .= ' a.acquia-lift-variation-rename';
        break;
      case "delete":
        $css .= ' a.acquia-lift-variation-delete';
        break;
      default:
        throw new \Exception(sprintf('Campaign %s does not support edit links for variations.', $campaign));
    }
    $css .= '[data-acquia-lift-personalize-page-variation="' . $index . '"]';
  }
  else {

    // Standard option set names displayed.
    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;
      }
    }
    $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;
}