function AcquiaLiftTest::testUpdateAgentStatus in Acquia Lift Connector 7
File
- tests/AcquiaLiftAPI.test, line 1910
- Unit tests for Acquia Lift module.
Class
- AcquiaLiftTest
- @file
Unit tests for Acquia Lift module.
Code
function testUpdateAgentStatus() {
$lift_api = $this
->getAcquiaLiftAPI();
DummyAcquiaLiftHttpClient::clearLoggedRequests();
$agent_name = 'my-test-agent';
try {
$lift_api
->updateAgentStatus($agent_name, 'some-non-existent-status-code');
$this
->fail('Exception not thrown as expected');
} catch (Exception $e) {
$this
->pass('Exception thrown as expected');
}
try {
$lift_api
->updateAgentStatus($agent_name, 33);
$this
->fail('Exception not thrown as expected');
} catch (Exception $e) {
$this
->pass('Exception thrown as expected');
}
try {
$lift_api
->updateAgentStatus($agent_name, AcquiaLiftAPI::PAUSED_STATUS);
} catch (Exception $e) {
$this
->fail('Exception thrown when none expected');
}
$requests = array(
array(
'type' => 'put',
'uri' => "http://api.lift.acquia.com/{$this->liftOwnerCode}/agent-api/{$agent_name}?apikey={$this->liftAdminKey}",
'headers' => array(
'Content-Type' => 'application/json; charset=utf-8',
'Accept' => 'application/json',
),
'options' => array(),
'body' => array(
'status' => AcquiaLiftAPI::PAUSED_STATUS,
),
),
);
$this
->assertAPIRequests($requests);
$logs = array(
array(
'level' => PersonalizeLogLevel::INFO,
'message' => "The new status of campaign {$agent_name} was pushed to Acquia Lift",
),
);
$this
->assertLogs($logs);
$this->logger
->clearLogs();
try {
$lift_api
->updateAgentStatus($agent_name, PERSONALIZE_STATUS_PAUSED);
} catch (Exception $e) {
$this
->fail('Exception thrown when none expected');
}
$this
->assertAPIRequests($requests);
$this
->assertLogs($logs);
$this->logger
->clearLogs();
$lift_api = $this
->getAcquiaLiftAPI(TRUE);
try {
$lift_api
->updateAgentStatus($agent_name, PERSONALIZE_STATUS_PAUSED);
$this
->fail('Exception not thrown as expected');
} catch (Exception $e) {
$this
->pass('Exception thrown as expected');
}
$this
->assertAPIRequests($requests);
$logs = array(
array(
'level' => PersonalizeLogLevel::ERROR,
'message' => "The new status of campaign {$agent_name} could not be pushed to Acquia Lift",
),
);
$this
->assertLogs($logs);
$this->logger
->clearLogs();
}