You are here

function AcquiaLiftWebTestCampaignWizardVariations::testWhatElementForm in Acquia Lift Connector 7.2

Test element variation set creation.

File

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

Class

AcquiaLiftWebTestCampaignWizardVariations

Code

function testWhatElementForm() {
  $admin_user = $this
    ->drupalCreateUser(array(
    'access administration pages',
    'manage personalized content',
    'use advanced personalize elements features',
  ));
  $this
    ->drupalLogin($admin_user);
  $agent = $this
    ->createTargetingAgent();
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
  $this
    ->drupalPostAJAX(NULL, array(), $this->addVariationSetElement);

  // Indicate an element variation set type.
  $edit = array(
    'variations[editing][new][0][option_set_type]' => 'element',
  );
  $this
    ->drupalPostAJAX(NULL, $edit, 'variations[editing][new][0][option_set_type]');

  // Invalid url
  $edit = array(
    'variations[editing][new][0][element][content][url]' => 'invalid url',
  );
  $this
    ->drupalPost(NULL, $edit, $this
    ->getButton('wizard_element_navigate'));
  $this
    ->assertText('You have specified an invalid path');

  // Valid external url
  $edit = array(
    'variations[editing][new][0][element][content][url]' => 'http://www.google.com',
  );
  $this
    ->drupalPost(NULL, $edit, $this
    ->getButton('wizard_element_navigate'));
  $this
    ->assertNoText('You have specified an invalid path');

  // Adjust the current url to match expected URLs across environments.
  $current_url = $this->url;
  if (substr($current_url, -1) != '/') {
    $current_url .= '/';
  }

  // Assert current url's prefix a google url (but possibly already redirected by IP's country).
  $current_url_expected_prefix = 'http://www.google.';
  $current_url_expected_prefix_length = strlen($current_url_expected_prefix);
  $this
    ->assertTrue(substr($current_url, 0, $current_url_expected_prefix_length) === $current_url_expected_prefix);

  // Valid url by alias
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
  $this
    ->drupalPostAJAX(NULL, array(), $this->addVariationSetElement);
  $edit = array(
    'variations[editing][new][0][option_set_type]' => 'element',
  );
  $this
    ->drupalPostAJAX(NULL, $edit, 'variations[editing][new][0][option_set_type]');
  $edit = array(
    'variations[editing][new][0][element][content][url]' => 'admin/structure',
  );
  $this
    ->drupalPost(NULL, $edit, $this
    ->getButton('wizard_element_navigate'));
  $this
    ->assertNoText('You have specified an invalid path');
  $this
    ->assertUrl('admin/structure');

  // Valid url by path
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
  $this
    ->drupalPostAJAX(NULL, array(), $this->addVariationSetElement);

  // Indicate an element variation set type.
  $edit = array(
    'variations[editing][new][0][option_set_type]' => 'element',
  );
  $this
    ->drupalPostAJAX(NULL, $edit, 'variations[editing][new][0][option_set_type]');
  $edit = array(
    'variations[editing][new][0][element][content][url]' => 'node',
  );
  $this
    ->drupalPost(NULL, $edit, $this
    ->getButton('wizard_element_navigate'));
  $this
    ->assertNoText('You have specified an invalid path');
  $this
    ->assertUrl('node');

  // Check the settings for toolbar integration.
  $settings = $this
    ->drupalGetSettings();
  $this
    ->assertEqual($settings['acquia_lift']['toolbarEditMode'], 'element');

  // Now navigate to another page and make sure that the settings are gone.
  $this
    ->drupalGet('admin/structure/personalize');
  $settings = $this
    ->drupalGetSettings();
  $this
    ->assertTrue(empty($settings['acquia_lift']['toolbarEditMode']));

  // Create an element variation for our agent.
  $option_set = $this
    ->createPersonalizeElementsOptionSet($agent->machine_name, array(
    'num_options' => 1,
    'add_control' => TRUE,
    'pages' => 'node',
  ));

  // Go to the edit page and verify that this option set is displayed and
  // links to its "pages" page for editing.
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
  $this
    ->assertText('Element test set 1');

  // Check the preview links are displayed.
  $osid = $option_set->osid;
  foreach ($option_set->options as $option) {
    $this
      ->assertLinkByHref(url('node', array(
      PERSONALIZE_PRESELECTION_PARAM => 'osid-' . $osid . '--' . $option['option_id'],
    )));
  }

  // Now verify that the edit link goes to the node page as well.
  $this
    ->clickLink(t('Edit variations in context'));
  $this
    ->assertUrl('node');

  // Settings should include indicators for deleting and editing option sets.
  $js_osid = personalize_stringify_osid($option_set->osid);
  $settings = $this
    ->drupalGetSettings();
  $this
    ->assertFalse($settings['acquia_lift']['option_sets'][$js_osid][PERSONALIZE_CONTROL_OPTION_ID]['editable']);
  $this
    ->assertFalse($settings['acquia_lift']['option_sets'][$js_osid][PERSONALIZE_CONTROL_OPTION_ID]['deletable']);
  $this
    ->assertTrue($settings['acquia_lift']['option_sets'][$js_osid]['option-A']['editable']);
  $this
    ->assertTrue($settings['acquia_lift']['option_sets'][$js_osid]['option-A']['deletable']);

  // Start the campaign and the elements should not be deletable.
  $this
    ->createTestFromOptionSet($agent, $option_set);
  $this
    ->drupalPost('admin/structure/personalize/manage/' . $agent->machine_name . '/review', array(), t('Start'));
  $this
    ->drupalGet('');
  $settings = $this
    ->drupalGetSettings();
  $this
    ->assertFalse($settings['acquia_lift']['option_sets'][$js_osid][PERSONALIZE_CONTROL_OPTION_ID]['editable']);
  $this
    ->assertFalse($settings['acquia_lift']['option_sets'][$js_osid][PERSONALIZE_CONTROL_OPTION_ID]['deletable']);
  $this
    ->assertTrue($settings['acquia_lift']['option_sets'][$js_osid]['option-A']['editable']);
  $this
    ->assertFalse($settings['acquia_lift']['option_sets'][$js_osid]['option-A']['deletable']);

  // Add another option to the option set that is not targeted.
  $option_set->options[] = array(
    'option_id' => 'option-B',
    'option_label' => 'Option B',
    'personalize_elements_content' => 'Yaaaaaay!',
  );
  $option_set = personalize_option_set_save($option_set);
  $this
    ->resetAll();

  // The new option should be deletable.
  $this
    ->drupalGet('');
  $settings = $this
    ->drupalGetSettings();
  $this
    ->assertFalse($settings['acquia_lift']['option_sets'][$js_osid][PERSONALIZE_CONTROL_OPTION_ID]['editable']);
  $this
    ->assertFalse($settings['acquia_lift']['option_sets'][$js_osid][PERSONALIZE_CONTROL_OPTION_ID]['deletable']);
  $this
    ->assertTrue($settings['acquia_lift']['option_sets'][$js_osid]['option-A']['editable']);
  $this
    ->assertFalse($settings['acquia_lift']['option_sets'][$js_osid]['option-A']['deletable']);
  $this
    ->assertTrue($settings['acquia_lift']['option_sets'][$js_osid]['option-B']['editable']);
  $this
    ->assertTrue($settings['acquia_lift']['option_sets'][$js_osid]['option-B']['deletable']);

  // Pause the agent and all options should be editable and deletable.
  personalize_agent_set_status($agent->machine_name, PERSONALIZE_STATUS_PAUSED);
  $this
    ->drupalGet('');
  $settings = $this
    ->drupalGetSettings();
  $this
    ->assertFalse($settings['acquia_lift']['option_sets'][$js_osid][PERSONALIZE_CONTROL_OPTION_ID]['editable']);
  $this
    ->assertFalse($settings['acquia_lift']['option_sets'][$js_osid][PERSONALIZE_CONTROL_OPTION_ID]['deletable']);
  $this
    ->assertTrue($settings['acquia_lift']['option_sets'][$js_osid]['option-A']['editable']);
  $this
    ->assertTrue($settings['acquia_lift']['option_sets'][$js_osid]['option-A']['deletable']);
  $this
    ->assertTrue($settings['acquia_lift']['option_sets'][$js_osid]['option-B']['editable']);
  $this
    ->assertTrue($settings['acquia_lift']['option_sets'][$js_osid]['option-B']['deletable']);

  // Verify that the elements variation can have general edits made from
  // the campaign workflow.
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
  $edit = array(
    'variations[editing][option_sets][option_set_' . $option_set->osid . '][content][label]' => 'Element test set 1 - EDIT',
    'variations[editing][option_sets][option_set_' . $option_set->osid . '][content][options][option-A][option_label]' => 'Option A - EDIT',
    'variations[editing][option_sets][option_set_' . $option_set->osid . '][advanced][pages_all]' => 0,
    'variations[editing][option_sets][option_set_' . $option_set->osid . '][advanced][pages]' => "node\nadmin/*",
  );
  $this
    ->drupalPost(NULL, $edit, $this
    ->getButton('wizard_next', array(
    'agent_name' => $agent->machine_name,
    'step' => 'variations',
  )));
  $option_set = personalize_option_set_load($option_set->osid, TRUE);
  $this
    ->assertTrue('Element test set 1 - EDIT', $option_set->label);
  foreach ($option_set->options as $option) {
    if ($option['option_id'] == 'option-A') {
      $this
        ->assertTrue('Option A - EDIT', $option_set->label);
    }
  }
  $this
    ->assertEqual($option_set->data['pages'], "node\nadmin/*");
  $this
    ->assertEqual($option_set->preview_link, 'node');

  // Now add a javascript personalize elements variation.
  $js_option_set = $this
    ->createPersonalizeElementsOptionSet($agent->machine_name, array(
    'type' => 'runJS',
    'selector' => '',
    'add_control' => TRUE,
    'num_options' => 2,
  ));
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
  $this
    ->clickLink('Edit variations');
  $this
    ->assertOptionSelected('edit-variation-type', 'runJS');
  $edit = array(
    'title' => 'JavaScript variation set',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Should be redirected back to the "What" page
  $this
    ->assertUrl('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
  $this
    ->assertFieldByName('variations[editing][option_sets][option_set_' . $js_option_set->osid . '][content][label]', 'JavaScript variation set');
}