function AcquiaLiftTest::testGetAgents in Acquia Lift Connector 7
File
- tests/
AcquiaLiftAPI.test, line 1594 - Unit tests for Acquia Lift module.
Class
- AcquiaLiftTest
- @file Unit tests for Acquia Lift module.
Code
function testGetAgents() {
$lift_api = AcquiaLiftAPI::getInstance(array(
'api_key' => 'asdf',
'admin_key' => 'fasfasfs',
'owner_code' => 'Some_valid-owner123-code',
));
// Pass some dummy agent data to our dummy http client and
// confirm that we get it back via the getExistingAgents()
// method on the the AcquiaLiftAPI class.
$agents = array();
$agent_codes = array(
'first-agent',
'second-agent',
);
foreach ($agent_codes as $code) {
$agent = new stdClass();
$agent->code = $code;
$agent->decisions = array();
$agent->goals = array();
$agents[] = $agent;
}
$lift_api
->setHttpClient(new DummyAcquiaLiftHttpClient(FALSE, array(
'agents' => $agents,
)));
$lift_api
->setLogger(new AcquiaLiftTestLogger());
$agents = $lift_api
->getExistingAgents();
$this
->assertEqual($agent_codes, array_keys($agents));
// Simulate no agents being returned by the service.
$lift_api
->setHttpClient(new DummyAcquiaLiftHttpClient(FALSE));
$agents = $lift_api
->getExistingAgents();
$this
->assertTrue(empty($agents));
// Now try with a broken httpclient (simulating a 500 response from the service).
$lift_api
->setHttpClient(new DummyAcquiaLiftHttpClient(TRUE));
try {
$agents = $lift_api
->getExistingAgents();
$this
->fail('Should never reach here');
} catch (Exception $e) {
$this
->assertTrue($e instanceof AcquiaLiftException);
$this
->assertEqual('Error retrieving agent list from Acquia Lift', $e
->getMessage());
}
}