public function ALProfilesAPITest::testDeleteEvent in Acquia Lift Connector 7
Same name and namespace in other branches
- 7.2 acquia_lift_profiles/tests/acquia_lift_profiles_unit.test \ALProfilesAPITest::testDeleteEvent()
Test ALProfilesAPI->deleteEvent()
File
- acquia_lift_profiles/
tests/ acquia_lift_profiles_unit.test, line 249 - Unit tests for Acquia Lift Profiles module.
Class
- ALProfilesAPITest
- @file Unit tests for Acquia Lift Profiles module.
Code
public function testDeleteEvent() {
$acquia_lift_profiles_api = $this
->getALProfilesAPI();
$event_name = 'test_event';
$acquia_lift_profiles_api
->deleteEvent($event_name);
// Define the requests we expect to have been made to our dummy http
// client for this operation.
$canonicalRequest = "DELETE\n/dashboard/rest/{$acquia_lift_profiles_api->getAccountName()}/events/{$event_name}";
$hmac = base64_encode(hash_hmac('sha1', $canonicalRequest, $this->secretKey, TRUE));
$auth_header = 'HMAC ' . $this->accessKey . ':' . $hmac;
$requests = array(
array(
'type' => 'delete',
'uri' => "{$acquia_lift_profiles_api->getApiUrl()}/dashboard/rest/{$acquia_lift_profiles_api->getAccountName()}/events/{$event_name}",
'headers' => array(
'Authorization' => $auth_header,
),
'options' => array(),
'body' => NULL,
),
);
// Confirm the expected requests were made.
$this
->assertAPIRequests($requests);
$logs = array(
array(
'level' => PersonalizeLogLevel::INFO,
'message' => "The event {$event_name} was deleted from Acquia Lift Profiles",
),
);
$this
->assertLogs($logs);
// Now try with a broken client.
$acquia_lift_profiles_api = $this
->getALProfilesAPI(TRUE);
try {
$acquia_lift_profiles_api
->deleteEvent($event_name);
} catch (Exception $e) {
$this
->assertTrue($e instanceof ALProfilesException);
}
// Confirm the expected requests were made.
$this
->assertAPIRequests($requests);
$logs = array(
array(
'level' => PersonalizeLogLevel::ERROR,
'message' => "Could not delete event {$event_name} from Acquia Lift Profiles",
),
);
$this
->assertLogs($logs);
// Now try with a non-empty customer site
ALProfilesAPI::reset();
$this->customerSite = 'TESTSITE';
$acquia_lift_profiles_api = $this
->getALProfilesAPI();
$event_name = 'test_event';
$acquia_lift_profiles_api
->deleteEvent($event_name);
// Our request should now include a customerSite param in the querystring
$canonicalRequest = "DELETE\n/dashboard/rest/{$acquia_lift_profiles_api->getAccountName()}/events/{$event_name}?customerSite=TESTSITE";
$hmac = base64_encode(hash_hmac('sha1', $canonicalRequest, $this->secretKey, TRUE));
$auth_header = 'HMAC ' . $this->accessKey . ':' . $hmac;
$requests = array(
array(
'type' => 'delete',
'uri' => "{$acquia_lift_profiles_api->getApiUrl()}/dashboard/rest/{$acquia_lift_profiles_api->getAccountName()}/events/{$event_name}?customerSite=TESTSITE",
'headers' => array(
'Authorization' => $auth_header,
),
'options' => array(),
'body' => NULL,
),
);
// Confirm the expected requests were made.
$this
->assertAPIRequests($requests);
$logs = array(
array(
'level' => PersonalizeLogLevel::INFO,
'message' => "The event {$event_name} was deleted from Acquia Lift Profiles",
),
);
$this
->assertLogs($logs);
ALProfilesAPI::reset();
}