You are here

function AcquiaLiftTest::testGetInstanceWithAPIUrl in Acquia Lift Connector 7

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

Tests getting a AcquiaLiftAPI instance that uses the default API url.

File

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

Class

AcquiaLiftTest
@file Unit tests for Acquia Lift module.

Code

function testGetInstanceWithAPIUrl() {
  AcquiaLiftAPI::reset();
  try {

    // We don't pass an API url so it should use the default.
    $lift_api = AcquiaLiftAPI::getInstance(array(
      'api_key' => $this->liftAPIKey,
      'admin_key' => $this->liftAdminKey,
      'owner_code' => $this->liftOwnerCode,
    ));
    $lift_api
      ->setLogger(new AcquiaLiftTestLogger());
  } catch (Exception $e) {
    $this
      ->fail('Exception thrown when none expected.');
  }
  global $is_https;
  $url_scheme = $is_https ? 'https://' : 'http://';

  // Check that the URL is as expected.
  $this
    ->assertEqual($url_scheme . AcquiaLiftAPI::API_URL, $lift_api
    ->getApiUrl());
  AcquiaLiftAPI::reset();

  // Test passing an invalid URL.
  try {
    $lift_api = AcquiaLiftAPI::getInstance(array(
      'api_key' => $this->liftAPIKey,
      'admin_key' => $this->liftAdminKey,
      'owner_code' => $this->liftOwnerCode,
      'api_url' => 'some\\invalid\\url',
    ));
    $this
      ->fail('Should never reach here.');
  } catch (Exception $e) {
    $this
      ->assertTrue($e instanceof AcquiaLiftCredsException);
    $this
      ->assertEqual('Acquia Lift API URL is not a valid URL.', $e
      ->getMessage());
  }

  // Test passing a valid URL with no scheme.
  $lift_api = AcquiaLiftAPI::getInstance(array(
    'api_key' => $this->liftAPIKey,
    'admin_key' => $this->liftAdminKey,
    'owner_code' => $this->liftOwnerCode,
    'api_url' => 'test-api.example.com',
  ));

  // The scheme will match whatever the current scheme is.
  global $is_https;
  $url_scheme = $is_https ? 'https://' : 'http://';

  // Check that the URL is as expected.
  $this
    ->assertEqual($url_scheme . 'test-api.example.com', $lift_api
    ->getApiUrl());
  AcquiaLiftAPI::reset();

  // Test passing a valid URL with the scheme specified.
  $lift_api = AcquiaLiftAPI::getInstance(array(
    'api_key' => $this->liftAPIKey,
    'admin_key' => $this->liftAdminKey,
    'owner_code' => $this->liftOwnerCode,
    'api_url' => 'https://test-api.example.com',
  ));

  // Check that the URL is as expected.
  $this
    ->assertEqual('https://test-api.example.com', $lift_api
    ->getApiUrl());
  AcquiaLiftAPI::reset();
}