public function AcquiaLiftWebTestFundamentals::testAcquiaLiftQueue in Acquia Lift Connector 7
File
- tests/acquia_lift.test, line 1683
- Integration tests for Acquia Lift module.
Class
- AcquiaLiftWebTestFundamentals
Code
public function testAcquiaLiftQueue() {
$marketer = $this
->drupalCreateUser(array(
'access administration pages',
'manage personalized content',
));
$this
->drupalLogin($marketer);
$agent = $this
->createTestAgent(array(), FALSE);
$agent_name = $agent
->getTitle();
$machine_name = $agent
->getMachineName();
$settings = $this
->drupalGetSettings();
$this
->assertEqual(1, $settings['acquia_lift']['sync_queue']);
$expected_queue_items = array();
$queued_agent_item = array(
'method' => 'saveAgent',
'args' => array(
$machine_name,
$agent_name,
'adaptive',
PERSONALIZE_STATUS_NOT_STARTED,
0.1,
0.2,
1,
),
'agent' => $machine_name,
);
$expected_queue_items[] = $queued_agent_item;
$this
->assertQueueItems($expected_queue_items);
$this
->drupalGet('acquia_lift/queue');
$this
->assertQueueItems(array());
$this
->drupalGet('admin/structure/personalize');
$this
->assertNoText(t('At least one of your campaigns has configuration that has not been fully synchronized with Acquia Lift. This should resolve itself on the next cron run.'));
$this
->drupalPost("admin/structure/personalize/manage/{$machine_name}/edit", array(), $this
->getButton('agent'));
$goal_name = 'form_submit';
personalize_goal_save($machine_name, $goal_name, 2);
$expected_queue_items = array();
$expected_queue_items[] = $queued_agent_item;
$expected_queue_items[] = array(
'method' => 'saveGoal',
'args' => array(
$machine_name,
$goal_name,
),
'agent' => $machine_name,
);
$expected_queue_items[] = $queued_agent_item;
$this
->assertQueueItems($expected_queue_items);
$this
->assertTrue(isset($_SESSION['acquia_lift_queue_trigger']));
$this
->drupalLogout();
$this
->drupalLogin($marketer);
$this
->drupalGet('admin/structure/personalize');
$this
->assertText(t('At least one of your campaigns has configuration that has not been fully synchronized with Acquia Lift. This should resolve itself on the next cron run.'));
$this
->drupalLogout();
$admin_user = $this
->drupalCreateUser(array(
'administer site configuration',
'access administration pages',
'manage personalized content',
));
$this
->drupalLogin($admin_user);
$this
->drupalGet('admin/structure/personalize');
$this
->assertRaw(t('At least one of your campaigns has configuration that has not been fully synchronized with Acquia Lift. This should resolve itself on the next cron run.') . t(' Click here to <a href="@cron">run cron manually</a>.', array(
'@cron' => url('admin/reports/status/run-cron'),
)));
$this
->drupalGet('admin/reports/status/run-cron');
$this
->assertQueueItems(array());
$this
->drupalPost("admin/structure/personalize/manage/{$machine_name}/edit", array(), $this
->getButton('agent'));
$expected_queue_items = array(
$queued_agent_item,
);
$this
->assertQueueItems($expected_queue_items);
AcquiaLiftAPI::setTestInstance(TRUE);
$_SESSION['acquia_lift_queue_trigger'] = true;
acquia_lift_process_queue(FALSE);
$expected_logs = array();
for ($i = 0; $i <= AcquiaLiftQueue::MAX_RETRIES; $i++) {
$expected_logs[] = array(
'level' => 'error',
'message' => "The campaign {$machine_name} could not be pushed to Acquia Lift",
);
}
$test_logger = new AcquiaLiftTestLogger(FALSE);
$logs = $test_logger
->getLogs();
$this
->assertEqual($expected_logs, $logs);
$this
->assertQueueItems(array());
$test_logger
->clearLogs();
$edit = array(
'cache_decisions' => FALSE,
);
$this
->drupalPost("admin/structure/personalize/manage/{$machine_name}/edit", $edit, $this
->getButton('agent'));
personalize_agent_set_status($machine_name, PERSONALIZE_STATUS_PAUSED);
$this
->resetAll();
$queued_agent_item['args'][6] = FALSE;
$expected_queue_items = array(
$queued_agent_item,
);
$expected_queue_items[] = array(
'method' => 'updateAgentStatus',
'args' => array(
$machine_name,
PERSONALIZE_STATUS_PAUSED,
),
'agent' => $machine_name,
);
$this
->assertQueueItems($expected_queue_items);
$this
->resetAll();
AcquiaLiftAPI::setTestInstance(TRUE, TRUE);
$_SESSION['acquia_lift_queue_trigger'] = true;
acquia_lift_process_queue(FALSE);
$expected_logs = array();
$expected_logs[] = array(
'level' => 'error',
'message' => "The campaign {$machine_name} could not be pushed to Acquia Lift",
);
$logs = $test_logger
->getLogs();
$this
->assertEqual($expected_logs, $logs);
$this
->assertQueueItems(array());
}