You are here

protected function DeveloperAppApiKeysPermissionTest::setUp in Apigee Edge 8

Overrides ApigeeEdgeFunctionalTestBase::setUp

File

tests/src/Functional/DeveloperAppApiKeysPermissionTest.php, line 86

Class

DeveloperAppApiKeysPermissionTest
Tests Api Keys permissions for developer_app.

Namespace

Drupal\Tests\apigee_edge\Functional

Code

protected function setUp() {
  parent::setUp();
  $this
    ->addOrganizationMatchedResponse();
  $this->account = $this
    ->createAccount([
    'add_api_key own developer_app',
  ]);
  $this->admin = $this
    ->createAccount([
    'add_api_key any developer_app',
    'revoke_api_key any developer_app',
    'delete_api_key any developer_app',
    'view any developer_app',
    'update any 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();
  if ($keys = $this->developerApp
    ->getCredentials()) {
    $credential = reset($keys);
    $this->consumer_key = $credential
      ->getConsumerKey();
    $this->apiProduct = $this
      ->createProduct();

    /* @var \Drupal\apigee_edge\Entity\Controller\AppCredentialControllerInterface $appCredentialController */
    $appCredentialController = \Drupal::service('apigee_edge.controller.developer_app_credential_factory')
      ->developerAppCredentialController($this->developerApp
      ->getAppOwner(), $this->developerApp
      ->getName());
    $appCredentialController
      ->addProducts($this->consumer_key, [
      $this->apiProduct
        ->getName(),
    ]);
  }
}