You are here

function AcquiaLiftWebTestVariationSets::testPersonalizeElementsVariationSets in Acquia Lift Connector 7

File

tests/acquia_lift.test, line 501
Integration tests for Acquia Lift module.

Class

AcquiaLiftWebTestVariationSets

Code

function testPersonalizeElementsVariationSets() {
  module_load_include('inc', 'acquia_lift', 'acquia_lift.page_variations');
  $agent_name = 'test-agent';

  // Variation 1 (only one element).
  $os1 = personalize_elements_get_option_set_for_variation('my first os', $agent_name, 'div.some-class', 'addClass', 'node');
  acquia_lift_page_variation_create('my_first_varset', $os1, array(
    'personalize_elements_content' => 'test-class',
  ));

  // Variation 2 (2 elements).
  $os2 = personalize_elements_get_option_set_for_variation('my second os', $agent_name, 'div.some-class', 'appendHtml', 'node');
  acquia_lift_page_variation_create('my_first_varset', $os2, array(
    'personalize_elements_content' => 'appended html',
  ));
  $os3 = personalize_elements_get_option_set_for_variation('my first os', $agent_name, 'div.some-class', 'addClass', 'node');
  acquia_lift_page_variation_create('my_first_varset', $os3, array(
    'personalize_elements_content' => 'other-class',
  ), 2);
  $this
    ->resetAll();
  $option_sets = personalize_option_set_load_multiple(FALSE, array(
    'agent' => $agent_name,
  ));
  $osids = array_keys($option_sets);
  $this
    ->assertEqual(2, count($option_sets));
  foreach ($option_sets as $osid => $option_set) {
    $this
      ->assertEqual('my_first_varset', $option_set->decision_name);
    $this
      ->assertEqual(3, count($option_set->options));
  }
  $expected_options_os1 = array(
    array(
      'option_id' => PERSONALIZE_CONTROL_OPTION_ID,
      'option_label' => PERSONALIZE_CONTROL_OPTION_LABEL,
    ),
    array(
      'option_id' => 'variation-1',
      'option_label' => 'Variation #1',
      'personalize_elements_content' => 'test-class',
    ),
    array(
      'option_id' => 'variation-2',
      'option_label' => 'Variation #2',
      'personalize_elements_content' => 'other-class',
    ),
  );
  $this
    ->assertEqual($expected_options_os1, $option_sets[$osids[0]]->options);
  $expected_options_os2 = array(
    array(
      'option_id' => PERSONALIZE_CONTROL_OPTION_ID,
      'option_label' => PERSONALIZE_CONTROL_OPTION_LABEL,
    ),
    array(
      'option_id' => 'variation-1',
      'option_label' => 'Variation #1',
    ),
    array(
      'option_id' => 'variation-2',
      'option_label' => 'Variation #2',
      'personalize_elements_content' => 'appended html',
    ),
  );
  $this
    ->assertEqual($expected_options_os2, $option_sets[$osids[1]]->options);
}