public function AcquiaLiftWebTestReports::testReportDates in Acquia Lift Connector 7.2
Same name and namespace in other branches
- 7 tests/acquia_lift.test \AcquiaLiftWebTestReports::testReportDates()
File
- tests/
acquia_lift.test, line 1219 - Integration tests for Acquia Lift module.
Class
Code
public function testReportDates() {
$this
->drupalLogin($this->managerUser);
AcquiaLiftAPI::setTestInstance();
$agents = array(
'first-agent' => array(
'num_options' => 2,
'num_days' => 58,
),
'second-agent' => array(
'num_options' => 2,
'num_days' => 70,
),
);
module_load_include('inc', 'acquia_lift', 'acquia_lift.admin');
$now = time();
foreach ($agents as $agent_name => &$agent_info) {
$agent = $this
->createTargetingAgent($agent_name);
$agent_name = $agent->machine_name;
$this
->createOptionSet(0, array(
'plugin' => 'some_plugin',
'agent' => $agent_name,
'num_options' => $agent_info['num_options'],
));
personalize_goal_save($agent_name, 'user_login', 1);
variable_set(_personalize_agent_get_status_variable($agent_name), PERSONALIZE_STATUS_RUNNING);
$started = $now;
$agent->started = $started - $agent_info['num_days'] * 86400;
personalize_agent_save($agent);
$agent_info['report_dates'] = acquia_lift_get_report_dates_for_agent($agent);
}
// Now check that the report dates are properly adjusted for each agent.
// The first agent should show the complete history, i.e. 58 days.
$this
->assertEqual(array(
date('Y-m-d', $now - 58 * 86400),
date('Y-m-d', $now),
), $agents['first-agent']['report_dates']);
// The second agent has been runnign for 70 days but should only show 60.
$this
->assertEqual(array(
date('Y-m-d', $now - 60 * 86400),
date('Y-m-d', $now),
), $agents['second-agent']['report_dates']);
// Now set the max days to 90 instead of 60.
variable_set('acquia_lift_report_max_days', 90);
$this
->resetAll();
foreach ($agents as $agent_name => &$agent_info) {
$agent = personalize_agent_load($agent_name);
$agent_info['report_dates'] = acquia_lift_get_report_dates_for_agent($agent);
}
// The first agent should still show the complete history, i.e. 58 days.
$this
->assertEqual(array(
date('Y-m-d', $now - 58 * 86400),
date('Y-m-d', $now),
), $agents['first-agent']['report_dates']);
// The second agent should now also show the complete history, i.e. 70 days.
$this
->assertEqual(array(
date('Y-m-d', $now - 70 * 86400),
date('Y-m-d', $now),
), $agents['second-agent']['report_dates']);
}