You are here

public function AcquiaLiftTest::testGetAgent in Acquia Lift Connector 7.2

Same name and namespace in other branches
  1. 7 tests/AcquiaLiftAPI.test \AcquiaLiftTest::testGetAgent()

Test AcquiaLiftAPI->getAgent()

File

tests/AcquiaLiftAPI.test, line 358
Unit tests for Acquia Lift module.

Class

AcquiaLiftTest
@file Unit tests for Acquia Lift module.

Code

public function testGetAgent() {
  $lift_api = $this
    ->getAcquiaLiftAPI();
  $machineName = 'some_machine_name';
  $lift_api
    ->getAgent($machineName);
  $logged_requests = DummyAcquiaLiftHttpClient::getLoggedRequests();
  $expected_uri = "{$lift_api->getApiUrl()}/campaigns/{$machineName}?client_id={$lift_api->getPublicKey()}";

  // Confirm the request URI is as expected.
  $this
    ->assertAPIRequestURI($expected_uri, $logged_requests[0]['uri']);
  $logs = array();
  $this
    ->assertLogs($logs);
  DummyAcquiaLiftHttpClient::clearLoggedRequests();
  $lift_api = $this
    ->getAcquiaLiftAPI(TRUE);
  try {
    $lift_api
      ->getAgent($machineName);
    $this
      ->fail('Should not reach here');
  } catch (AcquiaLiftException $e) {
  }

  // Confirm the expected requests and logs.
  $this
    ->assertAPIRequestURI($expected_uri, $logged_requests[0]['uri']);
  $logs = array(
    array(
      'level' => 'error',
      'message' => 'Could not retrieve the specified agent from Lift',
    ),
  );
  $this
    ->assertLogs($logs);
  DummyAcquiaLiftHttpClient::clearLoggedRequests();
}