public function AcquiaLiftWebTestFundamentals::testBatchSyncOperations in Acquia Lift Connector 7
Same name and namespace in other branches
- 7.2 tests/acquia_lift.test \AcquiaLiftWebTestFundamentals::testBatchSyncOperations()
Tests the function that gathers operations for syncing of agents and their components to Lift.
File
- tests/
acquia_lift.test, line 1871 - Integration tests for Acquia Lift module.
Class
Code
public function testBatchSyncOperations() {
// Create an agent on the site with a couple of option sets.
// Note: we do this part first rather than loading the test data to
// the server because otherwise it wouldn't allow us to create an
// agent with the same name as an existing one.
$control_rate = 10;
$explore_rate = 30;
$this
->createTestAgent(array(
'name' => 'first-existing-agent',
'control_rate' => $control_rate,
'explore_rate' => $explore_rate,
));
$option_set_values = array(
array(
'agent' => 'first-existing-agent',
'plugin' => 'type1',
'option_ids' => array(
'option-1',
'option-2',
),
),
array(
'agent' => 'first-existing-agent',
'plugin' => 'type2',
'option_ids' => array(
'option-a',
'option-b',
'option-c',
),
),
);
$option_sets = array();
foreach ($option_set_values as $i => $values) {
list($option_set, $new_queue_items) = $this
->createOptionSet($i, $values);
$option_sets[] = $option_set;
}
$first_osid = 'osid-' . $option_sets[0]->osid;
$second_osid = 'osid-' . $option_sets[1]->osid;
// Add a goal.
personalize_goal_save('first-existing-agent', 'new-goal', 2);
$this
->resetAll();
// Set up some test data to be returned by the dummy http client.
$test_data = array(
'agents' => array(
array(
'code' => 'first-existing-agent',
),
),
'points' => array(
'first-existing-agent' => array(
// The agent on the Drupal site will have this point.
$first_osid,
// The agent on the Drupal site will not have this point so it
// should get deleted upon sync.
'second-point',
),
),
'decisions' => array(
'first-existing-agent' => array(
$first_osid => array(
$first_osid,
// This decision should get deleted upon sync.
'another-decision',
),
),
),
'choices' => array(
'first-existing-agent' => array(
$first_osid => array(
$first_osid => array(
'option-1',
'option-2',
// These choices should get deleted upon sync.
'option-3',
'last-option',
),
),
),
),
'goals' => array(
'first-existing-agent' => array(
// This goal should get deleted upon sync.
'first-goal',
),
),
);
variable_set('acquia_lift_web_test_data', $test_data);
// Now try syncing this agent to Lift.
$agents = personalize_agent_load_multiple(array(
'first-existing-agent',
));
// Ensure the test API client is used during the call for operations.
AcquiaLiftAPI::setTestInstance();
module_load_include('inc', 'acquia_lift', 'acquia_lift.batch');
// Confirm that the correct operations will be performed.
$operations = acquia_lift_get_sync_operations_for_agents($agents);
$expected_operations = array(
array(
'method' => 'saveAgent',
'args' => array(
'first-existing-agent',
'first-existing-agent',
'adaptive',
PERSONALIZE_STATUS_NOT_STARTED,
$control_rate / 100,
$explore_rate / 100,
TRUE,
),
),
// PUT requests for all the points, decisions and choices that exist
// in the agent being sync'd, regardless of whether they already exist
// in Lift.
array(
'method' => 'savePoint',
'args' => array(
'first-existing-agent',
$first_osid,
),
),
array(
'method' => 'saveDecision',
'args' => array(
'first-existing-agent',
$first_osid,
$first_osid,
),
),
array(
'method' => 'saveChoice',
'args' => array(
'first-existing-agent',
$first_osid,
$first_osid,
'option-1',
),
),
array(
'method' => 'saveChoice',
'args' => array(
'first-existing-agent',
$first_osid,
$first_osid,
'option-2',
),
),
array(
'method' => 'savePoint',
'args' => array(
'first-existing-agent',
$second_osid,
),
),
array(
'method' => 'saveDecision',
'args' => array(
'first-existing-agent',
$second_osid,
$second_osid,
),
),
array(
'method' => 'saveChoice',
'args' => array(
'first-existing-agent',
$second_osid,
$second_osid,
'option-a',
),
),
array(
'method' => 'saveChoice',
'args' => array(
'first-existing-agent',
$second_osid,
$second_osid,
'option-b',
),
),
array(
'method' => 'saveChoice',
'args' => array(
'first-existing-agent',
$second_osid,
$second_osid,
'option-c',
),
),
// DELETE request for non-existent choices.
array(
'method' => 'deleteChoice',
'args' => array(
'first-existing-agent',
$first_osid,
$first_osid,
'option-3',
),
),
array(
'method' => 'deleteChoice',
'args' => array(
'first-existing-agent',
$first_osid,
$first_osid,
'last-option',
),
),
// DELETE request for non-existent decision.
array(
'method' => 'deleteDecision',
'args' => array(
'first-existing-agent',
$first_osid,
'another-decision',
),
),
// DELETE request for non-existent decision point.
array(
'method' => 'deletePoint',
'args' => array(
'first-existing-agent',
'second-point',
),
),
// PUT request for the new goal
array(
'method' => 'saveGoal',
'args' => array(
'first-existing-agent',
'new-goal',
),
),
// DELETE request for the goal that exists in Lift but not in the agent
// being sync'd.
array(
'method' => 'deleteGoal',
'args' => array(
'first-existing-agent',
'first-goal',
),
),
);
$this
->assertEqual($expected_operations, $operations);
}