You are here

class AcquiaLiftWebTestCampaignWizardVariations in Acquia Lift Connector 7.2

Hierarchy

Expanded class hierarchy of AcquiaLiftWebTestCampaignWizardVariations

File

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

View source
class AcquiaLiftWebTestCampaignWizardVariations extends AcquiaLiftWebTestCampaignWizardBase {
  public static function getInfo() {
    return array(
      'name' => t('Acquia Lift Web Tests - Personalization Wizard Variations'),
      'description' => t('Tests functionality related to the personalization management wizard variation sets.'),
      'group' => t('Personalize'),
    );
  }
  function testVariationTypeSelect() {
    $variation_input_name = key($this->addVariationSetElement);
    $variation_input_value = reset($this->addVariationSetElement);
    $block_title_name = 'variations[editing][new][0][block][content][title]';
    $element_url_name = 'variations[editing][new][0][element][content][url]';
    $option_set_type_name = 'variations[editing][new][0][option_set_type]';
    $block_type_id = 'edit-variations-editing-new-0-option-set-type-block';
    $element_type_id = 'edit-variations-editing-new-0-option-set-type-element';
    $this
      ->drupalLogin($this->managerUser);
    $agent = $this
      ->createTargetingAgent();
    $this
      ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
    $this
      ->drupalPostAJAX(NULL, array(), $this->addVariationSetElement);

    // Make sure the type selection is shown by default without any selections.
    $this
      ->assertFieldByName($option_set_type_name);
    $this
      ->assertNoFieldChecked($block_type_id);
    $this
      ->assertNoFieldChecked($element_type_id);

    // Actual forms should not be shown yet.
    $this
      ->assertNoFieldByName($block_title_name);
    $this
      ->assertNoFieldByName($element_url_name);

    // Button to add a new variation set should still be available.
    $this
      ->assertFieldByName($variation_input_name, $variation_input_value);

    // Cancel variation set creation.
    $this
      ->drupalPostAJAX(NULL, array(), array(
      'cancel_option_set_0' => t('Cancel'),
    ));
    $this
      ->assertFieldByName($variation_input_name, $variation_input_value);
    $this
      ->assertNoFieldByName($option_set_type_name);
    $this
      ->assertNoFieldByName($block_title_name);
    $this
      ->assertNoFieldByName($element_url_name);

    // Select a block variation set.
    $this
      ->drupalPostAJAX(NULL, array(), $this->addVariationSetElement);
    $this
      ->assertFieldByName($option_set_type_name);
    $this
      ->assertNoFieldChecked($block_type_id);
    $this
      ->assertNoFieldChecked($element_type_id);
    $this
      ->assertNoFieldByName($block_title_name);
    $this
      ->assertNoFieldByName($element_url_name);
    $this
      ->assertFieldByName($variation_input_name, $variation_input_value);
    $edit = array(
      $option_set_type_name => 'block',
    );
    $this
      ->drupalPostAJAX(NULL, $edit, $option_set_type_name);
    $this
      ->assertFieldByName($variation_input_name, $variation_input_value);
    $this
      ->assertNoFieldByName($option_set_type_name);
    $this
      ->assertFieldByName($block_title_name);
    $this
      ->assertNoFieldByName($element_url_name);

    // Change the type
    $this
      ->drupalPostAJAX(NULL, array(), $this->changeTypeElement);
    $this
      ->assertFieldByName($option_set_type_name);
    $this
      ->assertNoFieldChecked($block_type_id);
    $this
      ->assertNoFieldChecked($element_type_id);
    $this
      ->assertNoFieldByName($block_title_name);
    $this
      ->assertNoFieldByName($element_url_name);
    $this
      ->assertFieldByName($variation_input_name, $variation_input_value);

    // Select block again.
    $edit = array(
      $option_set_type_name => 'block',
    );
    $this
      ->drupalPostAJAX(NULL, $edit, $option_set_type_name);
    $this
      ->assertFieldByName($variation_input_name, $variation_input_value);
    $this
      ->assertNoFieldByName($option_set_type_name);
    $this
      ->assertFieldByName($block_title_name);
    $this
      ->assertNoFieldByName($element_url_name);

    // Cancel the creation of the variation set.
    $this
      ->drupalPostAJAX(NULL, array(), array(
      'cancel_block_option_set_0' => t('Cancel'),
    ));
    $this
      ->assertFieldByname($variation_input_name, $variation_input_value);
    $this
      ->assertNoFieldByName($option_set_type_name);
    $this
      ->assertNoFieldByName($block_title_name);
    $this
      ->assertNoFieldByName($element_url_name);

    // Select an element variation set.
    $this
      ->drupalPostAJAX(NULL, array(), $this->addVariationSetElement);
    $this
      ->assertFieldByName($option_set_type_name);
    $this
      ->assertNoFieldChecked($block_type_id);
    $this
      ->assertNoFieldChecked($element_type_id);
    $this
      ->assertNoFieldByName($block_title_name);
    $this
      ->assertNoFieldByName($element_url_name);
    $this
      ->assertFieldByName($variation_input_name, $variation_input_value);
    $edit = array(
      $option_set_type_name => 'element',
    );
    $this
      ->drupalPostAJAX(NULL, $edit, $option_set_type_name);
    $this
      ->assertFieldByName($variation_input_name, $variation_input_value);
    $this
      ->assertNoFieldByName($option_set_type_name);
    $this
      ->assertNoFieldByName($block_title_name);
    $this
      ->assertFieldByName($element_url_name);

    // Change the type.
    $this
      ->drupalPostAJAX(NULL, array(), $this->changeTypeElement);
    $this
      ->assertFieldByName($option_set_type_name);
    $this
      ->assertNoFieldChecked($block_type_id);
    $this
      ->assertNoFieldChecked($element_type_id);
    $this
      ->assertNoFieldByName($block_title_name);
    $this
      ->assertNoFieldByName($element_url_name);
    $this
      ->assertFieldByName($variation_input_name, $variation_input_value);

    // Select element again.
    $edit = array(
      $option_set_type_name => 'element',
    );
    $this
      ->drupalPostAJAX(NULL, $edit, $option_set_type_name);
    $this
      ->assertFieldByName($variation_input_name, $variation_input_value);
    $this
      ->assertNoFieldByName($option_set_type_name);
    $this
      ->assertNoFieldByName($block_title_name);
    $this
      ->assertFieldByName($element_url_name);

    // Cancel the creation of the variation set.
    $this
      ->drupalPostAJAX(NULL, array(), array(
      'cancel_element_option_set_0' => t('Cancel'),
    ));
    $this
      ->assertFieldByname($variation_input_name, $variation_input_value);
    $this
      ->assertNoFieldByName($option_set_type_name);
    $this
      ->assertNoFieldByName($block_title_name);
    $this
      ->assertNoFieldByName($element_url_name);

    // Now test the selection process when there is an existing option set.

    /* Temporarily removed: https://www.drupal.org/node/2505247
        $this->createPersonalizedBlock(1, $agent);

        // Set the variation set handling
        $this->drupalget('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
        $this->assertNoFieldByName($block_title_name);
        $this->assertNoFieldByName($element_url_name);
        $this->assertNoFieldByName('variations[add_variation][option_set_type]');
        $this->assertFieldByName('variations[add_variation][variation_set_handling]');
        $edit = array(
          'variations[add_variation][variation_set_handling]' => ACQUIA_LIFT_DECISION_LOCKSTEP,
        );
        $this->drupalPostAJAX(NULL, $edit, 'variations[add_variation][variation_set_handling]');
        // Now we can set the type of option set to create.
        $edit = array(
          'variations[add_variation][option_set_type]' => 'block',
        );
        $this->drupalPostAJAX(NULL, $edit, 'variations[add_variation][option_set_type]');
        // And finally there should be the new block form.
        $this->assertFieldByName($block_title_name);

        // Finally test adding option sets once they are already multiple.
        $this->createPersonalizedBlock(2, $agent);
        $agent->data['variation_set_handling'] = ACQUIA_LIFT_DECISION_LOCKSTEP;
        personalize_agent_save($agent);

        $this->drupalget('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
        $this->assertText('Variation sets (Lock step)');
        $this->assertFieldByName('variations[add_variation][option_set_type]');
        $this->assertNoFieldByName('variations[add_variation][variation_set_handling]');
        $this->assertNoFieldByName($block_title_name);
        $this->assertNoFieldByName($element_url_name);
        $edit = array(
          'variations[add_variation][option_set_type]' => 'block',
        );
        $this->drupalPostAJAX(NULL, $edit, 'variations[add_variation][option_set_type]');
        // The new block form should display without selecting variation handling.
        $this->assertFieldByName($block_title_name);
        */
  }

  /**
   * Test block variation set creation.
   */
  function testWhatBlockForm() {
    $this
      ->drupalLogin($this->managerUser);
    $agent = $this
      ->createTargetingAgent();

    // Create a personalized block from existing blocks.
    $this
      ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
    $this
      ->drupalPostAJAX(NULL, array(), $this->addVariationSetElement);

    // Indicate a block variation set type.
    $edit = array(
      'variations[editing][new][0][option_set_type]' => 'block',
    );
    $this
      ->drupalPostAJAX(NULL, $edit, 'variations[editing][new][0][option_set_type]');
    $edit = array(
      'variations[editing][new][0][block][content][title]' => 'Muppets',
      'variations[editing][new][0][block][content][pblock_wrapper][blocks][0][option_label]' => 'My variation 1',
      'variations[editing][new][0][block][content][pblock_wrapper][blocks][0][block][bid]' => 'comment_delta_recent',
      'variations[editing][new][0][block][content][pblock_wrapper][blocks][1][option_label]' => 'My variation 2',
      'variations[editing][new][0][block][content][pblock_wrapper][blocks][1][block][bid]' => 'node_delta_recent',
    );
    $this
      ->drupalPost(NULL, $edit, $this
      ->getButton('wizard_next', array(
      'agent_name' => $agent->machine_name,
      'step' => 'variations',
    )));
    $option_sets = personalize_option_set_load_by_agent($agent->machine_name);
    $this
      ->assertEqual(count($option_sets), 1);
    $option_set = reset($option_sets);
    $this
      ->assertEqual(count($option_set->options), 2);
    $this
      ->assertEqual($option_set->label, t('Muppets'));
    $this
      ->assertEqual($option_set->options[0]['option_label'], 'My variation 1');
    $this
      ->assertEqual($option_set->options[0]['bid'], 'comment_delta_recent');
    $this
      ->assertEqual($option_set->options[1]['option_label'], 'My variation 2');
    $this
      ->assertEqual($option_set->options[1]['bid'], 'node_delta_recent');

    // Now go to the variations page and verify the new option set is available.
    $this
      ->resetAll();
    $this
      ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
    $this
      ->assertFieldByName('variations[editing][option_sets][option_set_' . $option_set->osid . '][content][title]', 'Muppets');
    $this
      ->assertOptionSelected('edit-variations-editing-option-sets-option-set-' . $option_set->osid . '-content-pblock-wrapper-blocks-0-block-bid', 'comment_delta_recent');
    $this
      ->assertOptionSelected('edit-variations-editing-option-sets-option-set-' . $option_set->osid . '-content-pblock-wrapper-blocks-1-block-bid', 'node_delta_recent');

    // Edit the variation set title change the second block to a new block
    // created inline.
    $edit = array(
      'variations[editing][option_sets][option_set_' . $option_set->osid . '][content][title]' => 'Great Muppet Caper',
      'variations[editing][option_sets][option_set_' . $option_set->osid . '][content][pblock_wrapper][blocks][0][block][bid]' => 'comment_delta_recent',
      'variations[editing][option_sets][option_set_' . $option_set->osid . '][content][pblock_wrapper][blocks][1][block][block_type]' => 'add',
      'variations[editing][option_sets][option_set_' . $option_set->osid . '][content][pblock_wrapper][blocks][1][block][add][title]' => 'Kermit',
      'variations[editing][option_sets][option_set_' . $option_set->osid . '][content][pblock_wrapper][blocks][1][block][add][info]' => 'Piggy',
      'variations[editing][option_sets][option_set_' . $option_set->osid . '][content][pblock_wrapper][blocks][1][block][add][body][value]' => 'complicated',
    );
    $this
      ->drupalPost(NULL, $edit, $this
      ->getButton('wizard_next', array(
      'agent_name' => $agent->machine_name,
      'step' => 'variations',
    )));
    $option_sets = personalize_option_set_load_by_agent($agent->machine_name, TRUE);
    $this
      ->assertEqual(count($option_sets), 1);
    $option_set = reset($option_sets);
    $this
      ->assertEqual(count($option_set->options), 2);
    $this
      ->assertEqual($option_set->label, 'Great Muppet Caper');
    $this
      ->assertEqual($option_set->options[1]['bid'], 'block_delta_1');

    // Now go to the variations page test the advanced options
    $this
      ->resetAll();
    $this
      ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
    $edit = array(
      'variations[editing][option_sets][option_set_' . $option_set->osid . '][advanced][stateful]' => 1,
      'variations[editing][option_sets][option_set_' . $option_set->osid . '][advanced][preview_link]' => 'invalid url',
      'variations[editing][option_sets][option_set_' . $option_set->osid . '][advanced][executor]' => 'callback',
    );
    $this
      ->drupalPost(NULL, $edit, $this
      ->getButton('wizard_next', array(
      'agent_name' => $agent->machine_name,
      'step' => 'variations',
    )));
    $this
      ->assertText('You have specified an invalid path');
    $edit['variations[editing][option_sets][option_set_' . $option_set->osid . '][advanced][preview_link]'] = '<front>';
    $this
      ->drupalPost(NULL, $edit, $this
      ->getButton('wizard_next', array(
      'agent_name' => $agent->machine_name,
      'step' => 'variations',
    )));
    $option_sets = personalize_option_set_load_by_agent($agent->machine_name, TRUE);
    $this
      ->assertEqual(count($option_sets), 1);
    $option_set = reset($option_sets);
    $this
      ->assertEqual(count($option_set->options), 2);
    $this
      ->assertEqual($option_set->label, 'Great Muppet Caper');
    $this
      ->assertEqual($option_set->stateful, 1);
    $this
      ->assertEqual($option_set->preview_link, '<front>');
    $this
      ->assertEqual($option_set->executor, 'callback');
    $this
      ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
    $osid = $option_set->osid;
    foreach ($option_set->options as $option) {
      $preview_link = url('<front>', array(
        'query' => array(
          PERSONALIZE_PRESELECTION_PARAM => 'osid-' . $osid . '--' . $option['option_id'],
        ),
      ));
      $this
        ->assertLinkByHref($preview_link);
    }
  }

  /**
   * Test element variation set creation.
   */
  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');
  }

  /**
   * Test the personalize fields view of the "What" campaign subform.
   */
  function testWhatFieldsForm() {
    module_enable(array(
      'personalize_fields',
    ));
    $this
      ->resetAll();
    $admin_user = $this
      ->drupalCreateUser(array(
      'access administration pages',
      'administer site configuration',
      'access content',
      'administer content types',
      'administer nodes',
      'bypass node access',
      'manage personalized content',
    ));
    $this
      ->drupalLogin($admin_user);

    // Add personalizable field to the article node type.
    $this
      ->createPersonalizedArticleField();
    list($node, $os, $agent_name) = $this
      ->createPersonalizedField();
    $this
      ->drupalGet("admin/structure/personalize/manage/{$agent_name}/variations");

    // Text should be shown in preview.
    $this
      ->assertText('first value');
    $this
      ->assertText('second value');

    // Basic variation editing should be available.
    $edit = array(
      'variations[editing][option_sets][option_set_' . $os->osid . '][content][label]' => 'Fields test edit',
      'variations[editing][option_sets][option_set_' . $os->osid . '][content][options][first-value][option_label]' => 'Option A - EDIT',
      'variations[editing][option_sets][option_set_' . $os->osid . '][content][options][second-value][option_label]' => 'Option B - EDIT',
      'variations[editing][option_sets][option_set_' . $os->osid . '][advanced][preview_link]' => 'node/' . $node->nid,
    );
    $this
      ->drupalPost(NULL, $edit, $this
      ->getButton('wizard_next', array(
      'agent_name' => $agent_name,
      'step' => 'variations',
    )));

    // Go back and verify the changes.
    $this
      ->drupalGet("admin/structure/personalize/manage/{$agent_name}/variations");
    $this
      ->assertFieldByName('variations[editing][option_sets][option_set_' . $os->osid . '][content][label]', 'Fields test edit');
    $this
      ->assertFieldByName('variations[editing][option_sets][option_set_' . $os->osid . '][content][options][first-value][option_label]', 'Option A - EDIT');
    $this
      ->assertFieldByName('variations[editing][option_sets][option_set_' . $os->osid . '][content][options][second-value][option_label]', 'Option B - EDIT');
    $this
      ->assertText('first value');
    $this
      ->assertText('second value');
    $this
      ->assertLinkByHref(url('node/' . $node->nid, array(
      'query' => array(
        PERSONALIZE_PRESELECTION_PARAM => personalize_stringify_osid($os->osid) . '--first-value',
      ),
    )));
    $this
      ->assertLinkByHref(url('node/' . $node->nid, array(
      'query' => array(
        PERSONALIZE_PRESELECTION_PARAM => personalize_stringify_osid($os->osid) . '--second-value',
      ),
    )));

    // Check the link to edit in context.
    $this
      ->clickLink(t('Edit variations in context'));
    $this
      ->assertUrl('node/' . $node->nid . '/edit', array(
      'query' => array(
        'destination' => "admin/structure/personalize/manage/{$agent_name}/variations",
      ),
    ));
    $this
      ->drupalPost(NULL, array(), t('Save'));
    $this
      ->assertUrl("admin/structure/personalize/manage/{$agent_name}/variations");
  }

  /**
   * Test lock-step combinations of variation sets.
   */
  function testWhatLockStep() {
    $error_heading = "Let's fix this";
    $error_message = 'Variation sets must contain an equal number of variations.';
    $this
      ->drupalLogin($this->managerUser);
    $agent = $this
      ->createTargetingAgent();

    // Create a personalized block from existing blocks.
    $this
      ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
    $this
      ->assertNoText($error_heading);
    $this
      ->assertNoText($error_message);

    // Add two variation sets.
    $this
      ->drupalPostAJAX(NULL, array(), $this->addVariationSetElement);
    $this
      ->drupalPostAJAX(NULL, array(), $this->addVariationSetElement);
    $edit = array(
      'variations[editing][new][0][option_set_type]' => 'block',
    );
    $this
      ->drupalPostAJAX(NULL, $edit, 'variations[editing][new][0][option_set_type]');
    $edit = array(
      'variations[editing][new][1][option_set_type]' => 'block',
    );
    $this
      ->drupalPostAJAX(NULL, $edit, 'variations[editing][new][1][option_set_type]');
    $this
      ->drupalPostAJAX(NULL, array(), 'blocks_add_variation_add_1');
    $edit = array(
      'variations[editing][new][0][block][content][title]' => 'Muppets',
      'variations[editing][new][0][block][content][pblock_wrapper][blocks][0][option_label]' => 'Muppets variation 1',
      'variations[editing][new][0][block][content][pblock_wrapper][blocks][0][block][bid]' => 'comment_delta_recent',
      'variations[editing][new][0][block][content][pblock_wrapper][blocks][1][option_label]' => 'Muppets variation 2',
      'variations[editing][new][0][block][content][pblock_wrapper][blocks][1][block][bid]' => 'node_delta_recent',
      'variations[editing][new][1][block][content][title]' => 'Sesame',
      'variations[editing][new][1][block][content][pblock_wrapper][blocks][0][option_label]' => 'Sesame variation 1',
      'variations[editing][new][1][block][content][pblock_wrapper][blocks][0][block][bid]' => 'system_delta_powered-by',
      'variations[editing][new][1][block][content][pblock_wrapper][blocks][1][option_label]' => 'Sesme variation 2',
      'variations[editing][new][1][block][content][pblock_wrapper][blocks][1][block][bid]' => 'system_delta_help',
      'variations[editing][new][1][block][content][pblock_wrapper][blocks][2][option_label]' => 'Sesame variation 3',
      'variations[editing][new][1][block][content][pblock_wrapper][blocks][2][block][bid]' => 'user_delta_new',
    );
    $this
      ->drupalPost(NULL, $edit, $this
      ->getButton('wizard_next', array(
      'agent_name' => $agent->machine_name,
      'step' => 'variations',
    )));
    $this
      ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');

    // Should still be on the variations page only now there should be a
    // warning message.
    $this
      ->assertText($error_heading);
    $this
      ->assertText($error_message);

    // Remove the extra variation.
    $option_sets = personalize_option_set_load_by_agent($agent->machine_name);
    $second_os = end($option_sets);
    $edit = array(
      'variations[editing][option_sets][option_set_' . $second_os->osid . '][content][pblock_wrapper][blocks][2][block][bid]' => '',
    );
    $this
      ->drupalPost(NULL, $edit, $this
      ->getButton('wizard_save'));

    // Verify that the error message is gone.
    $this
      ->assertNoText($error_heading);
    $this
      ->assertNoText($error_message);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AcquiaLiftWebTestBase::$adminUser protected property
AcquiaLiftWebTestBase::$agent_plugin protected static property
AcquiaLiftWebTestBase::$liftProfileJsPath protected property The string to use as the JavaScript path.
AcquiaLiftWebTestBase::$managerUser protected property
AcquiaLiftWebTestBase::configureAcquiaLiftAccount protected function Helper method to configure an Acquia Lift account.
AcquiaLiftWebTestBase::createOptionSet protected function
AcquiaLiftWebTestBase::createPersonalizedArticleField protected function Adds a personalizable field to the article node type.
AcquiaLiftWebTestBase::createPersonalizedBlock protected function Creates the required number of custom blocks.
AcquiaLiftWebTestBase::createPersonalizedField protected function Creates an article node with a personalized headline field.
AcquiaLiftWebTestBase::createPersonalizeElementsOptionSet protected function Create personalize element option set.
AcquiaLiftWebTestBase::createTargetAudience protected function Helper that adds a target audience using two contexts AND'd together.
AcquiaLiftWebTestBase::createTargetingAgent protected function A helper function to create an acquia_lift_target agent.
AcquiaLiftWebTestBase::createTargetingAgentWithNestedTest protected function
AcquiaLiftWebTestBase::createTestAgent protected function Helper function to create an agent.
AcquiaLiftWebTestBase::createTestFromOptionSet function 1
AcquiaLiftWebTestBase::createUserProfileField protected function Creates a user profile field which can be used for targeting.
AcquiaLiftWebTestBase::getButton protected function Helper method to move buttons names to one pace to simplify it's maintaining
AcquiaLiftWebTestBase::tearDown public function Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix. Overrides DrupalWebTestCase::tearDown
AcquiaLiftWebTestCampaignWizardBase::$addGoalElement protected property
AcquiaLiftWebTestCampaignWizardBase::$addTargetAudienceElement protected property
AcquiaLiftWebTestCampaignWizardBase::$addVariationSetElement protected property
AcquiaLiftWebTestCampaignWizardBase::$changeTypeElement protected property
AcquiaLiftWebTestCampaignWizardBase::setUp public function Sets up a Drupal site for running functional and integration tests. Overrides AcquiaLiftWebTestBase::setUp
AcquiaLiftWebTestCampaignWizardVariations::getInfo public static function
AcquiaLiftWebTestCampaignWizardVariations::testVariationTypeSelect function
AcquiaLiftWebTestCampaignWizardVariations::testWhatBlockForm function Test block variation set creation.
AcquiaLiftWebTestCampaignWizardVariations::testWhatElementForm function Test element variation set creation.
AcquiaLiftWebTestCampaignWizardVariations::testWhatFieldsForm function Test the personalize fields view of the "What" campaign subform.
AcquiaLiftWebTestCampaignWizardVariations::testWhatLockStep function Test lock-step combinations of variation sets.
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalWebTestCase::$additionalCurlOptions protected property Additional cURL options.
DrupalWebTestCase::$content protected property The content of the page currently loaded in the internal browser.
DrupalWebTestCase::$cookieFile protected property The current cookie file used by cURL.
DrupalWebTestCase::$cookies protected property The cookies of the page currently loaded in the internal browser.
DrupalWebTestCase::$curlHandle protected property The handle of the current cURL connection.
DrupalWebTestCase::$drupalSettings protected property The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser.
DrupalWebTestCase::$elements protected property The parsed version of the page.
DrupalWebTestCase::$generatedTestFiles protected property Whether the files were copied to the test files directory.
DrupalWebTestCase::$headers protected property The headers of the page currently loaded in the internal browser.
DrupalWebTestCase::$httpauth_credentials protected property HTTP authentication credentials (<username>:<password>).
DrupalWebTestCase::$httpauth_method protected property HTTP authentication method
DrupalWebTestCase::$loggedInUser protected property The current user logged in using the internal browser.
DrupalWebTestCase::$originalShutdownCallbacks protected property The original shutdown handlers array, before it was cleaned for testing purposes.
DrupalWebTestCase::$originalUser protected property The original user, before it was changed to a clean uid = 1 for testing purposes.
DrupalWebTestCase::$plainTextContent protected property The content of the page currently loaded in the internal browser (plain text version).
DrupalWebTestCase::$profile protected property The profile to install as a basis for testing. 20
DrupalWebTestCase::$redirect_count protected property The number of redirects followed during the handling of a request.
DrupalWebTestCase::$session_id protected property The current session ID, if available.
DrupalWebTestCase::$session_name protected property The current session name, if available.
DrupalWebTestCase::$url protected property The URL currently loaded in the internal browser.
DrupalWebTestCase::assertField protected function Asserts that a field exists with the given name or ID.
DrupalWebTestCase::assertFieldById protected function Asserts that a field exists in the current page with the given ID and value.
DrupalWebTestCase::assertFieldByName protected function Asserts that a field exists in the current page with the given name and value.
DrupalWebTestCase::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
DrupalWebTestCase::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
DrupalWebTestCase::assertLink protected function Pass if a link with the specified label is found, and optional with the specified index.
DrupalWebTestCase::assertLinkByHref protected function Pass if a link containing a given href (part) is found.
DrupalWebTestCase::assertMail protected function Asserts that the most recently sent e-mail message has the given value.
DrupalWebTestCase::assertMailPattern protected function Asserts that the most recently sent e-mail message has the pattern in it.
DrupalWebTestCase::assertMailString protected function Asserts that the most recently sent e-mail message has the string in it.
DrupalWebTestCase::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
DrupalWebTestCase::assertNoField protected function Asserts that a field does not exist with the given name or ID.
DrupalWebTestCase::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
DrupalWebTestCase::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
DrupalWebTestCase::assertNoFieldByXPath protected function Asserts that a field doesn't exist or its value doesn't match, by XPath.
DrupalWebTestCase::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
DrupalWebTestCase::assertNoLink protected function Pass if a link with the specified label is not found.
DrupalWebTestCase::assertNoLinkByHref protected function Pass if a link containing a given href (part) is not found.
DrupalWebTestCase::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
DrupalWebTestCase::assertNoPattern protected function Will trigger a pass if the perl regex pattern is not present in raw content.
DrupalWebTestCase::assertNoRaw protected function Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertNoResponse protected function Asserts the page did not return the specified response code.
DrupalWebTestCase::assertNoText protected function Pass if the text is NOT found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertNoTitle protected function Pass if the page title is not the given string.
DrupalWebTestCase::assertNoUniqueText protected function Pass if the text is found MORE THAN ONCE on the text version of the page.
DrupalWebTestCase::assertOptionSelected protected function Asserts that a select option in the current page is checked.
DrupalWebTestCase::assertPattern protected function Will trigger a pass if the Perl regex pattern is found in the raw content.
DrupalWebTestCase::assertRaw protected function Pass if the raw text IS found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertResponse protected function Asserts the page responds with the specified response code.
DrupalWebTestCase::assertText protected function Pass if the text IS found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertTextHelper protected function Helper for assertText and assertNoText.
DrupalWebTestCase::assertThemeOutput protected function Asserts themed output.
DrupalWebTestCase::assertTitle protected function Pass if the page title is the given string.
DrupalWebTestCase::assertUniqueText protected function Pass if the text is found ONLY ONCE on the text version of the page.
DrupalWebTestCase::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
DrupalWebTestCase::assertUrl protected function Pass if the internal browser's URL matches the given path.
DrupalWebTestCase::buildXPathQuery protected function Builds an XPath query.
DrupalWebTestCase::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
DrupalWebTestCase::checkForMetaRefresh protected function Check for meta refresh tag and if found call drupalGet() recursively. This function looks for the http-equiv attribute to be set to "Refresh" and is case-sensitive.
DrupalWebTestCase::checkPermissions protected function Check to make sure that the array of permissions are valid.
DrupalWebTestCase::clickLink protected function Follows a link by name.
DrupalWebTestCase::constructFieldXpath protected function Helper function: construct an XPath for the given set of attributes and value.
DrupalWebTestCase::copySetupCache protected function Copy the setup cache from/to another table and files directory.
DrupalWebTestCase::cronRun protected function Runs cron in the Drupal installed by Simpletest.
DrupalWebTestCase::curlClose protected function Close the cURL handler and unset the handler.
DrupalWebTestCase::curlExec protected function Initializes and executes a cURL request.
DrupalWebTestCase::curlHeaderCallback protected function Reads headers and registers errors received from the tested site.
DrupalWebTestCase::curlInitialize protected function Initializes the cURL connection.
DrupalWebTestCase::drupalCompareFiles protected function Compare two files based on size and file name.
DrupalWebTestCase::drupalCreateContentType protected function Creates a custom content type based on default settings.
DrupalWebTestCase::drupalCreateNode protected function Creates a node based on default settings.
DrupalWebTestCase::drupalCreateRole protected function Creates a role with specified permissions.
DrupalWebTestCase::drupalCreateUser protected function Create a user with a given set of permissions.
DrupalWebTestCase::drupalGet protected function Retrieves a Drupal path or an absolute path.
DrupalWebTestCase::drupalGetAJAX protected function Retrieve a Drupal path or an absolute path and JSON decode the result.
DrupalWebTestCase::drupalGetContent protected function Gets the current raw HTML of requested page.
DrupalWebTestCase::drupalGetHeader protected function Gets the value of an HTTP response header. If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed…
DrupalWebTestCase::drupalGetHeaders protected function Gets the HTTP response headers of the requested page. Normally we are only interested in the headers returned by the last request. However, if a page is redirected or HTTP authentication is in use, multiple requests will be required to retrieve the…
DrupalWebTestCase::drupalGetMails protected function Gets an array containing all e-mails sent during this test case.
DrupalWebTestCase::drupalGetNodeByTitle function Get a node from the database based on its title.
DrupalWebTestCase::drupalGetSettings protected function Gets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::drupalGetTestFiles protected function Get a list files that can be used in tests.
DrupalWebTestCase::drupalGetToken protected function Generate a token for the currently logged in user.
DrupalWebTestCase::drupalHead protected function Retrieves only the headers for a Drupal path or an absolute path.
DrupalWebTestCase::drupalLogin protected function Log in a user with the internal browser.
DrupalWebTestCase::drupalLogout protected function
DrupalWebTestCase::drupalPost protected function Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser.
DrupalWebTestCase::drupalPostAJAX protected function Execute an Ajax submission.
DrupalWebTestCase::drupalSetContent protected function Sets the raw HTML content. This can be useful when a page has been fetched outside of the internal browser and assertions need to be made on the returned page.
DrupalWebTestCase::drupalSetSettings protected function Sets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::getAbsoluteUrl protected function Takes a path and returns an absolute path.
DrupalWebTestCase::getAllOptions protected function Get all option elements, including nested options, in a select.
DrupalWebTestCase::getSelectedItem protected function Get the selected value from a select field.
DrupalWebTestCase::getSetupCacheKey protected function Returns the cache key used for the setup caching.
DrupalWebTestCase::getUrl protected function Get the current URL from the cURL handler.
DrupalWebTestCase::handleForm protected function Handle form input related to drupalPost(). Ensure that the specified fields exist and attempt to create POST data in the correct manner for the particular field type.
DrupalWebTestCase::loadSetupCache protected function Copies the cached tables and files for a cached installation setup.
DrupalWebTestCase::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
DrupalWebTestCase::preloadRegistry protected function Preload the registry from the testing site.
DrupalWebTestCase::prepareDatabasePrefix protected function Generates a database prefix for running tests.
DrupalWebTestCase::prepareEnvironment protected function Prepares the current environment for running the test.
DrupalWebTestCase::recursiveDirectoryCopy protected function Recursively copy one directory to another.
DrupalWebTestCase::refreshVariables protected function Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread. 1
DrupalWebTestCase::resetAll protected function Reset all data structures after having enabled new modules.
DrupalWebTestCase::storeSetupCache protected function Store the installation setup to a cache.
DrupalWebTestCase::verboseEmail protected function Outputs to verbose the most recent $count emails sent.
DrupalWebTestCase::xpath protected function Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page.
DrupalWebTestCase::__construct function Constructor for DrupalWebTestCase. Overrides DrupalTestCase::__construct 1