From 4b31084919df3a4208805cb427202bd171e4d3ab Mon Sep 17 00:00:00 2001 From: Shishir <75600200+shishir-intelli@users.noreply.github.com> Date: Thu, 16 Nov 2023 12:58:10 +0530 Subject: [PATCH] Added ApigeeEdgeKernelTestBase as base class for Kernel testcases for Hybrid org (#981) --- .../ApigeeX/Entity/TeamViewBuilderTest.php | 5 +- .../ApigeeX/EntityControllerCacheTest.php | 4 +- .../Event/TeamInvitationEventsTest.php | 5 +- .../ApigeeX/ApigeeEdgeKernelTestBase.php | 82 +++++++++++++++++++ 4 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 tests/src/Kernel/ApigeeX/ApigeeEdgeKernelTestBase.php diff --git a/modules/apigee_edge_teams/tests/src/Kernel/ApigeeX/Entity/TeamViewBuilderTest.php b/modules/apigee_edge_teams/tests/src/Kernel/ApigeeX/Entity/TeamViewBuilderTest.php index 149b38b5..79e69890 100644 --- a/modules/apigee_edge_teams/tests/src/Kernel/ApigeeX/Entity/TeamViewBuilderTest.php +++ b/modules/apigee_edge_teams/tests/src/Kernel/ApigeeX/Entity/TeamViewBuilderTest.php @@ -20,8 +20,8 @@ namespace Drupal\Tests\apigee_edge_teams\Kernel\ApigeeX\Entity; -use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\apigee_edge\Kernel\ApigeeEdgeKernelTestTrait; +use Drupal\Tests\apigee_edge\Kernel\ApigeeX\ApigeeEdgeKernelTestBase; use Drupal\Tests\apigee_mock_api_client\Traits\ApigeeMockApiClientHelperTrait; /** @@ -32,7 +32,7 @@ * @group apigee_edge_teams * @group apigee_edge_teams_kernel */ -class TeamViewBuilderTest extends KernelTestBase { +class TeamViewBuilderTest extends ApigeeEdgeKernelTestBase { use ApigeeMockApiClientHelperTrait, ApigeeEdgeKernelTestTrait; @@ -84,6 +84,7 @@ protected function setUp(): void { $this->installSchema('user', ['users_data']); $this->apigeeTestHelperSetup(); + $this->storeToken(); $this->addApigeexOrganizationMatchedResponse(); $this->entity = $this->createApigeexTeam(); } diff --git a/modules/apigee_edge_teams/tests/src/Kernel/ApigeeX/EntityControllerCacheTest.php b/modules/apigee_edge_teams/tests/src/Kernel/ApigeeX/EntityControllerCacheTest.php index 15ca122b..afbd37f1 100644 --- a/modules/apigee_edge_teams/tests/src/Kernel/ApigeeX/EntityControllerCacheTest.php +++ b/modules/apigee_edge_teams/tests/src/Kernel/ApigeeX/EntityControllerCacheTest.php @@ -20,7 +20,7 @@ namespace Drupal\Tests\apigee_edge_teams\Kernel\ApigeeX; use Apigee\Edge\Api\ApigeeX\Entity\AppGroup; -use Drupal\KernelTests\KernelTestBase; +use Drupal\Tests\apigee_edge\Kernel\ApigeeX\ApigeeEdgeKernelTestBase; use Drupal\Tests\apigee_edge\Traits\EntityControllerCacheUtilsTrait; /** @@ -31,7 +31,7 @@ * @group apigee_edge_teams * @group apigee_edge_teams_kernel */ -class EntityControllerCacheTest extends KernelTestBase { +class EntityControllerCacheTest extends ApigeeEdgeKernelTestBase { use EntityControllerCacheUtilsTrait; diff --git a/modules/apigee_edge_teams/tests/src/Kernel/ApigeeX/Event/TeamInvitationEventsTest.php b/modules/apigee_edge_teams/tests/src/Kernel/ApigeeX/Event/TeamInvitationEventsTest.php index 6b81c873..b824b15c 100644 --- a/modules/apigee_edge_teams/tests/src/Kernel/ApigeeX/Event/TeamInvitationEventsTest.php +++ b/modules/apigee_edge_teams/tests/src/Kernel/ApigeeX/Event/TeamInvitationEventsTest.php @@ -24,7 +24,7 @@ use Drupal\apigee_edge_teams\Entity\TeamInvitation; use Drupal\apigee_edge_teams\Entity\TeamInvitationInterface; use Drupal\apigee_edge_teams\Entity\TeamRoleInterface; -use Drupal\KernelTests\KernelTestBase; +use Drupal\Tests\apigee_edge\Kernel\ApigeeX\ApigeeEdgeKernelTestBase; use Drupal\Tests\apigee_mock_api_client\Traits\ApigeeMockApiClientHelperTrait; /** @@ -35,7 +35,7 @@ * @group apigee_edge_teams * @group apigee_edge_teams_kernel */ -class TeamInvitationEventsTest extends KernelTestBase { +class TeamInvitationEventsTest extends ApigeeEdgeKernelTestBase { use ApigeeMockApiClientHelperTrait { apigeeTestHelperSetup as baseSetUp; @@ -79,6 +79,7 @@ protected function setUp(): void { $this->baseSetUp(); + $this->storeToken(); $this->addApigeexOrganizationMatchedResponse(); } diff --git a/tests/src/Kernel/ApigeeX/ApigeeEdgeKernelTestBase.php b/tests/src/Kernel/ApigeeX/ApigeeEdgeKernelTestBase.php new file mode 100644 index 00000000..55628736 --- /dev/null +++ b/tests/src/Kernel/ApigeeX/ApigeeEdgeKernelTestBase.php @@ -0,0 +1,82 @@ +markTestSkipped('This test suite is expecting a HYBRID instance type.'); + } + parent::setUp(); + } + + /** + * Stores pre-configured token storage service for testing. + */ + protected function storeToken() { + // Storing the token for Appigeex Hybrid Org. + $this->testTokenData = [ + 'access_token' => mb_strtolower($this->randomMachineName(32)), + 'token_type' => 'bearer', + 'expires_in' => 300, + 'refresh_token' => mb_strtolower($this->randomMachineName(32)), + 'scope' => 'create', + ]; + $storage = $this->tokenStorage(); + + // Save the token. + $storage->saveToken($this->testTokenData); + } + + /** + * Returns a pre-configured token storage service for testing. + * + * @param bool $rebuild + * Enforces rebuild of the container and with the the token storage + * service. + * + * @return \Drupal\apigee_edge\OauthTokenFileStorage + * The configured and initialized OAuth file token storage service. + * + * @throws \Exception + */ + private function tokenStorage(bool $rebuild = FALSE): OauthTokenFileStorage { + $config = $this->config('apigee_edge.auth'); + $config->set('oauth_token_storage_location', OauthTokenFileStorage::DEFAULT_DIRECTORY)->save(); + if ($rebuild) { + $this->container->get('kernel')->rebuildContainer(); + } + return $this->container->get('apigee_edge.authentication.oauth_token_storage'); + } + +}