You are here

public function AcquiaLiftWebTestWorkflow::testAutoCreateGoal in Acquia Lift Connector 7.2

File

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

Class

AcquiaLiftWebTestWorkflow

Code

public function testAutoCreateGoal() {
  $this
    ->drupalLogin($this->adminUser);
  $agent = $this
    ->createTargetingAgent();
  $option_set = $this
    ->createPersonalizedBlock(0, $agent, 2);
  $this
    ->resetAll();
  $goals = personalize_goal_load_by_conditions(array(
    'agent' => $agent->machine_name,
  ));
  $this
    ->assertEqual(1, count($goals));
  $goal = reset($goals);
  $this
    ->assertEqual('clicks_option_set_' . $option_set->osid, $goal->action);
  $this
    ->assertEqual(1, $goal->value);
  $goal_action = visitor_actions_custom_load($goal->action);
  $this
    ->assertEqual($option_set->osid, $goal_action['data']['auto_created']);

  // Delete the goal and confirm that saving the option set again does not
  // result in another goal being created.
  personalize_goal_delete($goal->id);
  personalize_option_set_save($option_set);
  $goals = personalize_goal_load_by_conditions(array(
    'agent' => $agent->machine_name,
  ), TRUE);
  $this
    ->assertEqual(0, count($goals));

  // Add an agent and create a goal before creating an option set. A second goal is
  // automatically created when creating the option set.
  $agent2 = $this
    ->createTargetingAgent();
  personalize_goal_save($agent2->machine_name, 'user_login', 2);

  // The goal should not have an auto created indicator.
  $goals = personalize_goal_load_by_conditions(array(
    'agent' => $agent2->machine_name,
  ));
  $manual_goal = reset($goals);
  $manual_goal_action = visitor_actions_custom_load($manual_goal->action);
  $this
    ->assertTrue(!isset($manual_goal_action['data']['auto_created']));
  $option_set = $this
    ->createPersonalizedBlock(1, $agent2, 2);
  $this
    ->resetAll();
  $goals = personalize_goal_load_by_conditions(array(
    'agent' => $agent2->machine_name,
  ));
  $this
    ->assertEqual(2, count($goals));
  $goal = reset($goals);
  $this
    ->assertEqual('user_login', $goal->action);
  $this
    ->assertEqual(2, $goal->value);
  $goal = end($goals);
  $goal_action = visitor_actions_custom_load($goal->action);
  $this
    ->assertEqual($option_set->osid, $goal_action['data']['auto_created']);
  $this
    ->assertEqual(1, $goal->value);

  // Now set the variable that prevents auto-creation of goals.
  variable_set('acquia_lift_auto_goal', FALSE);
  $agent3 = $this
    ->createTargetingAgent();
  $this
    ->createPersonalizedBlock(2, $agent3, 2);
  $this
    ->resetAll();
  $goals = personalize_goal_load_by_conditions(array(
    'agent' => $agent3->machine_name,
  ), TRUE);
  $this
    ->assertEqual(0, count($goals));
}