You are here

function AcquiaLiftWebTestCampaignWizardTargeting::testWinnerSelectionAvailability in Acquia Lift Connector 7.2

File

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

Class

AcquiaLiftWebTestCampaignWizardTargeting

Code

function testWinnerSelectionAvailability() {

  // Create user profile fields that we can use for targeting.
  $user_profile_field_1 = $this
    ->createUserProfileField();
  $context_1 = str_replace('field_', '', $user_profile_field_1['field_name']);

  // Create an agent with option set but no tests.
  $agent = $this
    ->createTargetingAgent();
  $option_set = $this
    ->createOptionSet(1, array(
    'agent' => $agent->machine_name,
    'plugin' => 'type1',
    'num_options' => 3,
    'option_ids' => array(
      'option-A',
      'option-B',
      'option-C',
    ),
  ));
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/targeting');

  // There is no test created yet so there should be no way to pick a winner.
  $this
    ->assertNoFieldById('acquia-lift-complete-everyone-else');

  // Create an audience
  $this
    ->drupalPostAJAX(NULL, array(), $this->addTargetAudienceElement);
  $edit = array(
    'audiences[new][0][details][name]' => 'Muppet fans',
    'audiences[new][0][details][mapping][contexts][0][context]' => 'user_profile_context' . PERSONALIZE_TARGETING_ADMIN_SEPARATOR . $context_1,
    'audiences[new][0][details][mapping][contexts][0][value][match]' => 'some value',
    'audiences[new][0][details][mapping][contexts][0][value][operator]' => 'equals',
  );
  $this
    ->drupalPost(NULL, $edit, $this
    ->getButton('wizard_next', array(
    'agent_name' => $agent->machine_name,
    'step' => 'targeting',
  )));

  // Assign variations and verify that there is still no way to pick a winner.
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/targeting');
  $edit = array(
    'audiences[existing][muppet-fans][assignment_order]' => 'option-A',
    'audiences[existing][everyone-else][assignment_order]' => 'option-B,option-C',
  );
  $this
    ->drupalPost(NULL, $edit, $this
    ->getButton('wizard_next', array(
    'agent_name' => $agent->machine_name,
    'step' => 'targeting',
  )));
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/targeting');
  $this
    ->assertNoFieldById('acquia-lift-complete-everyone-else');
  $this
    ->assertNoFieldById('acquia-lift-complete-muppet-fans');

  // Start the agent and verify that the button is available for the test.
  $this
    ->drupalPost('admin/structure/personalize/manage/' . $agent->machine_name . '/review', array(), $this
    ->getButton('wizard_start'));
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/targeting');
  $this
    ->assertFieldById('acquia-lift-complete-everyone-else');
  $this
    ->assertNoFieldById('acquia-lift-complete-muppet-fans');

  // Pause the agent and the button is still available.
  personalize_agent_set_status($agent->machine_name, PERSONALIZE_STATUS_PAUSED);
  $this
    ->resetAll();
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/targeting');
  $this
    ->assertFieldById('acquia-lift-complete-everyone-else');
  $this
    ->assertNoFieldById('acquia-lift-complete-muppet-fans');

  // Adjust the assignments to convert the targeting audience to a test
  // and verify that it still does not have a winner selection button.
  $edit = array(
    'audiences[existing][muppet-fans][assignment_order]' => 'option-A,option-B',
    'audiences[existing][everyone-else][assignment_order]' => 'option-B,option-C',
  );
  $this
    ->drupalPost(NULL, $edit, $this
    ->getButton('wizard_next', array(
    'agent_name' => $agent->machine_name,
    'step' => 'targeting',
  )));
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/targeting');
  $this
    ->assertFieldById('acquia-lift-complete-everyone-else');
  $this
    ->assertNoFieldById('acquia-lift-complete-muppet-fans');

  // Start the agent and now there should be buttons for both audiences.
  $this
    ->drupalPost('admin/structure/personalize/manage/' . $agent->machine_name . '/review', array(), $this
    ->getButton('wizard_start'));
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/targeting');
  $this
    ->assertFieldById('acquia-lift-complete-everyone-else');
  $this
    ->assertFieldById('acquia-lift-complete-muppet-fans-2');

  // Pause the test again and convert a test to pure targeting.
  personalize_agent_set_status($agent->machine_name, PERSONALIZE_STATUS_PAUSED);
  $this
    ->resetAll();
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/targeting');
  $this
    ->assertFieldById('acquia-lift-complete-everyone-else');
  $this
    ->assertFieldById('acquia-lift-complete-muppet-fans-2');
  $edit = array(
    'audiences[existing][muppet-fans-2][assignment_order]' => 'option-A,option-B',
    'audiences[existing][everyone-else][assignment_order]' => 'option-C',
  );
  $this
    ->drupalPost(NULL, $edit, $this
    ->getButton('wizard_next', array(
    'agent_name' => $agent->machine_name,
    'step' => 'targeting',
  )));
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/targeting');
  $this
    ->assertNoFieldById('acquia-lift-complete-everyone-else');
  $this
    ->assertFieldById('acquia-lift-complete-muppet-fans-2');

  // Start the test again and confirm options remain the same.
  $this
    ->drupalPost('admin/structure/personalize/manage/' . $agent->machine_name . '/review', array(), $this
    ->getButton('wizard_start'));
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/targeting');
  $this
    ->assertNoFieldById('acquia-lift-complete-everyone-else');
  $this
    ->assertFieldById('acquia-lift-complete-muppet-fans-2');
}