protected function AcquiaLiftWebTestBase::createTestAgent in Acquia Lift Connector 7
Same name and namespace in other branches
- 7.2 tests/acquia_lift.test \AcquiaLiftWebTestBase::createTestAgent()
Help function to create and test queue creation of Personalize Agent
Parameters
array $data: array ( 'name' => Agent title 'machine_name' => string processed by personalize_generate_machine_name() )
bool $cleanQueue Clean or not Drupal queue after 'saveAgent' queue testing:
Return value
NULL|PersonalizeAgentInterface
See also
personalize_generate_machine_name()
testSaveAgent()
20 calls to AcquiaLiftWebTestBase::createTestAgent()
- AcquiaLiftWebTestAgentAdmin::testDeleteAgentGoals in tests/
acquia_lift.test - AcquiaLiftWebTestAgentAdmin::testPauseAgents in tests/
acquia_lift.test - Tests that agents are paused when they need to be paused.
- AcquiaLiftWebTestAgentAdmin::testSaveAgent in tests/
acquia_lift.test - AcquiaLiftWebTestAgentAdmin::testSaveAutoTargetingRule in tests/
acquia_lift.test - AcquiaLiftWebTestAgentAdmin::testSyncGoalsFromCampaignUI in tests/
acquia_lift.test
File
- tests/
acquia_lift.test, line 101 - Integration tests for Acquia Lift module.
Class
- AcquiaLiftWebTestBase
- @file Integration tests for Acquia Lift module.
Code
protected function createTestAgent($data = array(), $cleanQueue = TRUE, $assertResults = TRUE) {
$this
->configureAcquiaLiftAccount();
$this
->drupalLogin($this->managerUser);
$data += array(
'name' => $this
->randomName(),
'agent_type' => 'acquia_lift',
'decision_style' => 'adaptive',
'control_rate' => 10,
'explore_rate' => 20,
'cache_decisions' => 1,
'auto_stop' => 0,
);
$data += array(
'machine_name' => personalize_generate_machine_name($data['name'], 'personalize_agent_machine_name_exists'),
);
$edit = array(
'agent_basic_info[title]' => $data['name'],
'agent_basic_info[machine_name]' => $data['machine_name'],
'agent_basic_info[agent_type]' => $data['agent_type'],
'agent_basic_info[options][acquia_lift][decision_style]' => $data['decision_style'],
'agent_basic_info[options][acquia_lift][control_rate]' => $data['control_rate'],
'agent_basic_info[options][acquia_lift][explore_rate]' => $data['explore_rate'],
'cache_decisions' => $data['cache_decisions'],
);
$this
->drupalPost('admin/structure/personalize/add', $edit, $this
->getButton('agent'));
if ($data['auto_stop']) {
$agent = personalize_agent_load($data['machine_name']);
$agent->data['auto_stop'] = 1;
AcquiaLiftAPI::setTestInstance();
personalize_agent_save($agent);
}
$agent = personalize_agent_load_agent($data['machine_name'], TRUE);
if ($assertResults) {
$this
->assertTrue($agent instanceof AcquiaLiftAgent);
}
$expected_queue_items = array(
array(
'method' => 'saveAgent',
'args' => array(
$data['machine_name'],
$data['name'],
'adaptive',
PERSONALIZE_STATUS_NOT_STARTED,
isset($data['control_rate']) ? $data['control_rate'] / 100 : 0.1,
isset($data['explore_rate']) ? $data['explore_rate'] / 100 : 0.2,
isset($data['cache_decisions']) && $data['cache_decisions'],
),
'agent' => $data['machine_name'],
),
);
if ($assertResults) {
$this
->assertQueueItems($expected_queue_items);
}
if ($cleanQueue) {
$this->personalizedQueue
->deleteQueue();
}
return $agent;
}