public function AcquiaLiftWebTestAgentAdmin::testSaveAutoTargetingRule in Acquia Lift Connector 7
File
- tests/
acquia_lift.test, line 939 - Integration tests for Acquia Lift module.
Class
Code
public function testSaveAutoTargetingRule() {
$agent = $this
->createTestAgent();
// as acquia_lift_context options are fetched from Acquia Lift via webservice - use hardcoded ones in tests
module_load_include('inc', 'personalize', 'personalize.admin');
$agentStructure = _personalize_agent_from_form_values(array(
'machine_name' => $agent
->getMachineName(),
'title' => $agent
->getTitle(),
'agent_type' => $agent
->getType(),
'data' => $agent
->getData(),
));
$agentStructure->data['visitor_context'] = array(
// Fake Aquia Lift context to check saveAutoTargetingRule method queue
'acquia_lift_context' => array(
'some_acquia_lift_context' => 'some_acquia_lift_context',
),
);
$this
->drupalGet('admin/structure/personalize/manage/' . $agent
->getMachineName() . '/edit');
personalize_agent_save($agentStructure);
$this
->drupalGet('admin/structure/personalize/manage/' . $agent
->getMachineName() . '/edit');
$agent = personalize_agent_load_agent($agent
->getMachineName(), TRUE);
$agentData = $agent
->getData();
$expected_queues = array(
array(
'method' => 'saveAgent',
'args' => array(
$agent
->getMachineName(),
$agent
->getTitle(),
$agentData['decision_style'],
PERSONALIZE_STATUS_NOT_STARTED,
0.1,
0.2,
1,
),
'agent' => $agent
->getMachineName(),
),
array(
'method' => 'saveAutoTargetingRule',
'args' => array(
$agent
->getMachineName(),
array_keys(array_filter($agentData['visitor_context']['acquia_lift_context'])),
),
'agent' => $agent
->getMachineName(),
),
);
$this
->assertQueueItems($expected_queues);
$this->personalizedQueue
->deleteQueue();
// Now remove the acquia_lift_context items and we should be sending a delete call
// to Acquia Lift.
$agentStructure->data['visitor_context'] = array(
'acquia_lift_context' => array(),
);
$this
->drupalGet('admin/structure/personalize/manage/' . $agent
->getMachineName() . '/edit');
personalize_agent_save($agentStructure);
$this
->drupalGet('admin/structure/personalize/manage/' . $agent
->getMachineName() . '/edit');
$agent = personalize_agent_load_agent($agent
->getMachineName(), TRUE);
$agentData = $agent
->getData();
$expected_queues = array(
array(
'method' => 'saveAgent',
'args' => array(
$agent
->getMachineName(),
$agent
->getTitle(),
$agentData['decision_style'],
PERSONALIZE_STATUS_NOT_STARTED,
0.1,
0.2,
1,
),
'agent' => $agent
->getMachineName(),
),
array(
'method' => 'deleteAutoTargetingRule',
'args' => array(
$agent
->getMachineName(),
),
'agent' => $agent
->getMachineName(),
),
);
$this
->assertQueueItems($expected_queues);
}