function AcquiaLiftWebTestTarget::testMVTCreation in Acquia Lift Connector 7.2
File
- tests/
acquia_lift.test, line 2692 - Integration tests for Acquia Lift module.
Class
Code
function testMVTCreation() {
$this
->drupalLogin($this->managerUser);
$targeting_agent = $this
->createTargetingAgent();
$targeting_agent->data['variation_set_handling'] = ACQUIA_LIFT_DECISION_MULTIVARIATE;
personalize_agent_save($targeting_agent);
// Add a single option set, should not get past the review screen.
$os1 = $this
->createOptionSet(1, array(
'agent' => $targeting_agent->machine_name,
'plugin' => 'type1',
'num_options' => 2,
));
// Add a couple of goals.
personalize_goal_save($targeting_agent->machine_name, 'form_submit', 1);
personalize_goal_save($targeting_agent->machine_name, 'user_login', 2);
// Verify the error message.
$this
->drupalGet('admin/structure/personalize/manage/' . $targeting_agent->machine_name . '/review');
$this
->assertText('A multi-variate test requires at least two option sets.');
$this
->assertNoText('You have multiple variation sets with different numbers of variations - the personalization cannot be started until all variation sets have the same number of variations.');
// Add another option set.
$os2 = $this
->createOptionSet(2, array(
'agent' => $targeting_agent->machine_name,
'plugin' => 'type1',
'num_options' => 3,
));
$this
->drupalGet('admin/structure/personalize/manage/' . $targeting_agent->machine_name . '/review');
$this
->assertNoText('A multi-variate test requires at least two option sets.');
$this
->assertNoText('You have multiple variation sets with different numbers of variations - the personalization cannot be started until all variation sets have the same number of variations.');
// Grab the goals created so we can assert that they get moved over to the
// MVT later.
$goals = personalize_goal_load_by_conditions(array(
'agent' => $targeting_agent->machine_name,
), TRUE);
// Just pull the details out into an array.
$original_goal_info = array();
foreach ($goals as $goal) {
$goal_array = (array) $goal;
unset($goal_array['agent']);
$original_goal_info[$goal->id] = $goal_array;
}
// Implement the MVT.
AcquiaLiftAPI::setTestInstance();
acquia_lift_implement_mvt($targeting_agent);
$this
->resetAll();
$nested = personalize_agent_load_by_type(ACQUIA_LIFT_TESTING_AGENT, TRUE);
$nested_mvt = reset($nested);
$this
->assertEqual($nested_mvt->machine_name, acquia_lift_get_mvt_name_for_agent($targeting_agent->machine_name));
$option_sets = personalize_option_set_load_by_agent($nested_mvt->machine_name, TRUE);
$this
->assertTrue(isset($option_sets[$os1->osid]));
$this
->assertTrue(isset($option_sets[$os2->osid]));
$goals = personalize_goal_load_by_conditions(array(
'agent' => $nested_mvt->machine_name,
), TRUE);
$mvt_goal_info = array();
foreach ($goals as $goal) {
$goal_array = (array) $goal;
unset($goal_array['agent']);
$mvt_goal_info[$goal->id] = $goal_array;
}
$this
->assertEqual($original_goal_info, $mvt_goal_info);
// There shouldn't be any option sets or goals on the parent agent.
$option_sets_original = personalize_option_set_load_by_agent($targeting_agent->machine_name, TRUE);
$this
->assertTrue(empty($option_sets_original));
$goals_original = personalize_goal_load_by_conditions(array(
'agent' => $targeting_agent->machine_name,
), TRUE);
$this
->assertTrue(empty($goals_original));
}