You are here

protected function DeveloperAppApiKeyTest::setUp in Apigee Edge 8

Overrides ApigeeEdgeFunctionalTestBase::setUp

File

tests/src/Functional/DeveloperAppApiKeyTest.php, line 87

Class

DeveloperAppApiKeyTest
Developer app API key test.

Namespace

Drupal\Tests\apigee_edge\Functional

Code

protected function setUp() {
  parent::setUp();
  $this->appCredentialController = \Drupal::service('apigee_edge.controller.developer_app_credential_factory');
  $this->account = $this
    ->createAccount([
    'add_api_key own developer_app',
    'revoke_api_key own developer_app',
    'delete_api_key own developer_app',
  ]);
  $this
    ->queueDeveloperResponse($this->account);
  $this->developer = Developer::load($this->account
    ->getEmail());
  $this->developerApp = DeveloperApp::create([
    'name' => $this
      ->randomMachineName(),
    'status' => App::STATUS_APPROVED,
    'developerId' => $this->developer
      ->getDeveloperId(),
  ]);
  $this->developerApp
    ->setOwner($this->account);
  $this
    ->queueDeveloperAppResponse($this->developerApp);
  $this->developerApp
    ->save();
  $productOne = ApiProduct::create([
    'name' => 'api_one',
    'displayName' => 'API One',
    'approvalType' => ApiProduct::APPROVAL_TYPE_AUTO,
  ]);
  $this->stack
    ->queueMockResponse([
    'api_product' => [
      'product' => $productOne,
    ],
  ]);
  $productOne
    ->save();
  $productTwo = ApiProduct::create([
    'name' => 'api_two',
    'displayName' => 'API Two',
    'approvalType' => ApiProduct::APPROVAL_TYPE_AUTO,
  ]);
  $this->stack
    ->queueMockResponse([
    'api_product' => [
      'product' => $productTwo,
    ],
  ]);
  $productTwo
    ->save();
  $this->apiProducts = [
    $productOne,
    $productTwo,
  ];
  if ($keys = $this->developerApp
    ->getCredentials()) {
    $credential = reset($keys);
    $this->consumer_key = $credential
      ->getConsumerKey();
  }
  $this
    ->addOrganizationMatchedResponse();
  $this
    ->drupalLogin($this->account);
}