You are here

function AcquiaLiftTest::testGetInstance in Acquia Lift Connector 7.2

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

Tests getting a AcquiaLiftAPI instance with invalid and valid credentials.

File

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

Class

AcquiaLiftTest
@file Unit tests for Acquia Lift module.

Code

function testGetInstance() {
  try {
    $lift_api = AcquiaLiftAPI::getInstance(array());
    $this
      ->fail('Should never reach here.');
  } catch (Exception $e) {
    $this
      ->assertTrue($e instanceof AcquiaLiftCredsException);
    $this
      ->assertEqual('Acquia Lift API URL is missing or not a valid URL.', $e
      ->getMessage());
    try {
      $lift_api = AcquiaLiftAPI::getInstance(array(
        'api_url' => 'some.valid.url.com',
      ));
      $this
        ->fail('Should never reach here.');
    } catch (Exception $e) {
      $this
        ->assertTrue($e instanceof AcquiaLiftCredsException);
      $this
        ->assertEqual('Acquia Lift Public Key was not found.', $e
        ->getMessage());
      try {
        $lift_api = AcquiaLiftAPI::getInstance(array(
          'api_url' => 'some.valid.url.com',
          'public_key' => $this->publicKey,
        ));
        $this
          ->fail('Should never reach here.');
      } catch (Exception $e) {
        $this
          ->assertTrue($e instanceof AcquiaLiftCredsException);
        $this
          ->assertEqual('Acquia Lift Private Key was not found.', $e
          ->getMessage());
        try {
          $lift_api = AcquiaLiftAPI::getInstance(array(
            'api_url' => 'some.valid.url.com',
            'private_key' => $this->privateKey,
            'public_key' => $this->publicKey,
            'validate_response' => TRUE,
          ));
        } catch (Exception $e) {
          $this
            ->fail('Exception thrown when none expected.');
        }
      }
    }
  }
  AcquiaLiftAPI::reset();
}