function AcquiaLiftWebTestAgentAdmin::testAgentList in Acquia Lift Connector 7.2
File
- tests/
acquia_lift.test, line 601 - Integration tests for Acquia Lift module.
Class
Code
function testAgentList() {
module_disable(array(
'personalize_test',
));
$admin_user = $this
->drupalCreateUser(array(
'access administration pages',
'manage personalized content',
));
$this
->drupalLogin($admin_user);
// There should just be a message saying there are no agents.
$this
->drupalGet('admin/structure/personalize');
$this
->assertText(t('To create your first new personalization, click the above Add Personalization link.'));
$this
->assertNoRaw('<h3>Draft</h3>');
$this
->assertNoRaw('<h3>Scheduled</h3>');
$this
->assertNoRaw('<h3>Running</h3>');
$this
->assertNoRaw('<h3>Paused</h3>');
$this
->assertNoRaw('<h3>Completed</h3>');
// An agent without any variations should have a link to edit and delete
// but not for reports.
$agent = $this
->createTargetingAgent();
$this
->drupalGet('admin/structure/personalize');
$this
->assertNoText(t('No personalizations available.'));
$this
->assertLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
$this
->assertLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/delete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/results');
$this
->assertRaw('<h3>Draft</h3>');
$this
->assertNoRaw('<h3>Scheduled</h3>');
$this
->assertNoRaw('<h3>Running</h3>');
$this
->assertNoRaw('<h3>Paused</h3>');
$this
->assertNoRaw('<h3>Completed</h3>');
// Add a variation set and create a test.
$option_set = $this
->createPersonalizedBlock(0, $agent, 3);
$this
->createTestFromOptionSet($agent, $option_set);
$this
->drupalGet('admin/structure/personalize');
$this
->assertLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/delete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/results');
$this
->assertText(t('Test only'));
$this
->assertText(t('Everyone'));
// No link to complete this test because it hasn't been started yet.
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/everyone-else/complete');
// Add two audiences and assign variations so that there is only targeting.
$audience_1 = personalize_generate_machine_name($this
->randomName(), NULL, '-');
$this
->createTargetAudience($option_set, $audience_1);
$audience_2 = personalize_generate_machine_name($this
->randomName(), NULL, '-');
$this
->createTargetAudience($option_set, $audience_2);
$targeting = array(
$audience_1 => array(
'option-1',
),
$audience_2 => array(
'option-2',
),
ACQUIA_LIFT_TARGETING_EVERYONE_ELSE => array(
'option-3',
),
);
acquia_lift_save_targeting_structure($agent, $targeting);
$this
->drupalGet('admin/structure/personalize');
$this
->assertLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/delete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/results');
$this
->assertText(t('Target only'));
$this
->assertText($audience_1);
$this
->assertText($audience_2);
$this
->assertText(t('Everyone else'));
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/' . $audience_1 . '/complete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/' . $audience_2 . '/complete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/everyone-else/complete');
// Adjust variations so that there is testing and targeting.
$targeting = array(
$audience_1 => array(
'option-1',
'option-2',
),
$audience_2 => array(
'option-2',
),
ACQUIA_LIFT_TARGETING_EVERYONE_ELSE => array(
'option-3',
),
);
acquia_lift_save_targeting_structure($agent, $targeting);
$this
->drupalGet('admin/structure/personalize');
$this
->assertLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/delete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/results');
$this
->assertText(t('Test and target'));
$this
->assertText($audience_1);
$this
->assertText($audience_2);
$this
->assertText(t('Everyone else'));
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/' . $audience_1 . '/complete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/' . $audience_2 . '/complete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/everyone-else/complete');
// Schedule and check heading.
personalize_agent_set_start_date($agent->machine_name, time() + 86400);
personalize_agent_set_status($agent->machine_name, PERSONALIZE_STATUS_SCHEDULED);
$this
->drupalGet('admin/structure/personalize');
$this
->assertLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/delete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/results');
$this
->assertNoRaw('<h3>Draft</h3>');
$this
->assertRaw('<h3>Scheduled</h3>');
$this
->assertNoRaw('<h3>Running</h3>');
$this
->assertNoRaw('<h3>Paused</h3>');
$this
->assertNoRaw('<h3>Completed</h3>');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/' . $audience_1 . '/complete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/' . $audience_2 . '/complete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/everyone-else/complete');
// Set it to running and check that the reporting link is now available
// and that the campaign is shown in the correct section.
personalize_agent_set_status($agent->machine_name, PERSONALIZE_STATUS_RUNNING);
$this
->drupalGet('admin/structure/personalize');
$this
->assertLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/delete');
$this
->assertLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/results');
$this
->assertLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/results?targeting_audience=' . $audience_1);
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/results?targeting_audience=' . $audience_2);
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/results?targeting_audience=' . ACQUIA_LIFT_TARGETING_EVERYONE_ELSE);
$this
->assertLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/' . $audience_1 . '/complete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/' . $audience_2 . '/complete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/everyone-else/complete');
$this
->assertNoRaw('<h3>Draft</h3>');
$this
->assertNoRaw('<h3>Scheduled</h3>');
$this
->assertRaw('<h3>Running</h3>');
$this
->assertNoRaw('<h3>Paused</h3>');
$this
->assertNoRaw('<h3>Completed</h3>');
// Pause and check heading.
personalize_agent_set_status($agent->machine_name, PERSONALIZE_STATUS_PAUSED);
$this
->drupalGet('admin/structure/personalize');
$this
->assertNoRaw('<h3>Draft</h3>');
$this
->assertNoRaw('<h3>Scheduled</h3>');
$this
->assertNoRaw('<h3>Running</h3>');
$this
->assertRaw('<h3>Paused</h3>');
$this
->assertNoRaw('<h3>Completed</h3>');
$this
->assertLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/' . $audience_1 . '/complete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/' . $audience_2 . '/complete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/everyone-else/complete');
// Complete and check heading.
personalize_agent_set_status($agent->machine_name, PERSONALIZE_STATUS_COMPLETED);
$this
->drupalGet('admin/structure/personalize');
$this
->assertNoRaw('<h3>Draft</h3>');
$this
->assertNoRaw('<h3>Scheduled</h3>');
$this
->assertNoRaw('<h3>Running</h3>');
$this
->assertNoRaw('<h3>Paused</h3>');
$this
->assertRaw('<h3>Completed</h3>');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/' . $audience_1 . '/complete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/' . $audience_2 . '/complete');
$this
->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/everyone-else/complete');
}