function AcquiaLiftWebTestTarget::testNestedAgentDeletion in Acquia Lift Connector 7.2
File
- tests/
acquia_lift.test, line 2347 - Integration tests for Acquia Lift module.
Class
Code
function testNestedAgentDeletion() {
$agent_with_nesting = $this
->createTargetingAgentWithNestedTest(2);
// Add another option set and make it lock-step.
$agent_with_nesting->data['variation_set_handling'] = ACQUIA_LIFT_DECISION_LOCKSTEP;
$second_os = $this
->createOptionSet(1, array(
'agent' => $agent_with_nesting->machine_name,
'plugin' => 'some_plugin',
'num_options' => 2,
));
AcquiaLiftAPI::setTestInstance();
acquia_lift_implement_targeting($agent_with_nesting);
$this
->resetAll();
// Confirm the nested test has been created as expected.
$nested_tests = acquia_lift_get_nested_tests($agent_with_nesting);
$nested_agent_name = reset($nested_tests);
$nested_agent = personalize_agent_load($nested_agent_name, TRUE);
$this
->assertNotNull($nested_agent);
$nested_os = personalize_option_set_load_by_agent($nested_agent_name);
$this
->assertEqual(1, count($nested_os));
$nested_os = reset($nested_os);
$this
->assertNotNull($nested_os);
DummyAcquiaLiftHttpClient::clearLoggedRequests();
AcquiaLiftAPI::setTestInstance();
personalize_option_set_delete($second_os->osid);
$this
->resetAll();
$requests = DummyAcquiaLiftHttpClient::getLoggedRequests();
$this
->assertEqual(array(), $requests);
// Confirm the agent still exists.
$nested_agent = personalize_agent_load($nested_agent_name, TRUE);
$this
->assertNotNull($nested_agent);
// Now delete the remaining option set.
$option_set = acquia_lift_get_option_set_for_targeting($agent_with_nesting->machine_name);
personalize_option_set_delete($option_set->osid);
$this
->resetAll();
$requests = DummyAcquiaLiftHttpClient::getLoggedRequests();
$this
->assertEqual('delete', $requests[0]['type']);
$pattern = preg_quote("http://api.example.com/campaigns/{$nested_agent_name}?request_id=", '#') . '[a-zA-Z0-9-_]*' . preg_quote('&client_id=test-api-key', '#');
$this
->assertTrue(preg_match("#{$pattern}#", $requests[0]['uri']));
$nested_agent = personalize_agent_load($nested_agent_name, TRUE);
$this
->assertNull($nested_agent);
$nested_os = personalize_option_set_load_by_agent($nested_agent_name, TRUE);
$this
->assertEqual(0, count($nested_os));
}