You are here

function ALProfilesAPITest::testGetInstance in Acquia Lift Connector 7

Same name and namespace in other branches
  1. 7.2 acquia_lift_profiles/tests/acquia_lift_profiles_unit.test \ALProfilesAPITest::testGetInstance()

Tests getting ALProfilesAPI instance with invalid and valid credentials.

File

acquia_lift_profiles/tests/acquia_lift_profiles_unit.test, line 72
Unit tests for Acquia Lift Profiles module.

Class

ALProfilesAPITest
@file Unit tests for Acquia Lift Profiles module.

Code

function testGetInstance() {

  // Make sure calls to variable_get() for the account name and api url return
  // an empty string.
  global $conf;
  $original_conf = $conf;
  $conf['acquia_lift_profiles_account_name'] = '';
  $conf['acquia_lift_profiles_api_url'] = '';
  $conf['acquia_lift_profiles_access_key'] = '';
  $conf['acquia_lift_profiles_secret_key'] = '';
  try {
    $acquia_lift_profiles_api = ALProfilesAPI::getInstance('', 'ohai');
    $this
      ->fail('Should never reach here.');
  } catch (Exception $e) {
    $this
      ->assertTrue($e instanceof ALProfilesCredsException);
    $this
      ->assertEqual('Missing acquia_lift_profiles account information.', $e
      ->getMessage());
    try {
      $acquia_lift_profiles_api = ALProfilesAPI::getInstance($this->accountName, $this->customerSite, 'some\\invalid\\url', $this->accessKey, $this->secretKey);
      $this
        ->fail('Should never reach here.');
    } catch (Exception $e) {
      $this
        ->assertTrue($e instanceof ALProfilesCredsException);
      $this
        ->assertEqual('API URL is not a valid URL.', $e
        ->getMessage());
      try {

        // Here we pass valid creds.
        $acquia_lift_profiles_api = ALProfilesAPI::getInstance($this->accountName, $this->customerSite, $this->apiUrl, $this->accessKey, $this->secretKey);
        $acquia_lift_profiles_api
          ->setLogger(new AcquiaLiftTestLogger());
        $this
          ->assertEqual($this->apiUrl, $acquia_lift_profiles_api
          ->getApiUrl());
      } catch (Exception $e) {
        $this
          ->fail('Exception thrown when none expected.');
      }
    }
  }
  ALProfilesAPI::reset();

  // Put back our original conf settings.
  $conf = $original_conf;
}