You are here

function AcquiaLiftTest::testGetInstance in Acquia Lift Connector 7

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

Tests getting a AcquiaLiftAPI instance with invalid and valid credentials.

File

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

Class

AcquiaLiftTest
@file Unit tests for Acquia Lift module.

Code

function testGetInstance() {
  try {
    $lift_api = AcquiaLiftAPI::getInstance(array(
      'api_key' => 'asdf',
    ));
    $this
      ->fail('Should never reach here.');
  } catch (Exception $e) {
    $this
      ->assertTrue($e instanceof AcquiaLiftCredsException);
    $this
      ->assertEqual('Acquia Lift account info is not complete.', $e
      ->getMessage());
    try {
      $lift_api = AcquiaLiftAPI::getInstance(array(
        'api_key' => 'asdf',
        'admin_key' => 'fasfasfs',
        'owner_code' => 'OHAI LOL',
      ));
      $this
        ->fail('Should never reach here.');
    } catch (Exception $e) {
      $this
        ->assertTrue($e instanceof AcquiaLiftCredsException);
      $this
        ->assertEqual('Acquia Lift owner code is invalid.', $e
        ->getMessage());
      try {

        // Here we pass valid creds.
        $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.');
      }
      $this
        ->assertEqual($this->liftAPIKey, $lift_api
        ->getApiKey());
    }
  }
  AcquiaLiftAPI::reset();
}