From c6fd6e8bb21b2701b3e8b385ef691413f14537f9 Mon Sep 17 00:00:00 2001 From: Shishir Suvarna Date: Wed, 15 Nov 2023 22:13:18 +0530 Subject: [PATCH 1/3] Added ApigeeEdgeKernelTestBase as base class for Kernel testcases for Hybrid org --- .../ApigeeX/Entity/TeamViewBuilderTest.php | 4 +- .../ApigeeX/EntityControllerCacheTest.php | 4 +- .../Event/TeamInvitationEventsTest.php | 4 +- .../ApigeeX/ApigeeEdgeKernelTestBase.php | 82 +++++++++++++++++++ 4 files changed, 88 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..6c3f9980 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; 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..ea188f0a 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; diff --git a/tests/src/Kernel/ApigeeX/ApigeeEdgeKernelTestBase.php b/tests/src/Kernel/ApigeeX/ApigeeEdgeKernelTestBase.php new file mode 100644 index 00000000..c44d8555 --- /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'); + } + +} From 87817bf02cdc34a72a52142e60ba830e7d26e113 Mon Sep 17 00:00:00 2001 From: Shishir Suvarna Date: Wed, 15 Nov 2023 22:18:55 +0530 Subject: [PATCH 2/3] Storing the token for Apigeex Hybrid Org --- .../tests/src/Kernel/ApigeeX/Entity/TeamViewBuilderTest.php | 1 + .../tests/src/Kernel/ApigeeX/Event/TeamInvitationEventsTest.php | 1 + 2 files changed, 2 insertions(+) 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 6c3f9980..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 @@ -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/Event/TeamInvitationEventsTest.php b/modules/apigee_edge_teams/tests/src/Kernel/ApigeeX/Event/TeamInvitationEventsTest.php index ea188f0a..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 @@ -79,6 +79,7 @@ protected function setUp(): void { $this->baseSetUp(); + $this->storeToken(); $this->addApigeexOrganizationMatchedResponse(); } From 7727a7aeb03cc5e80ad6ab18120d8ca6d43bf3c1 Mon Sep 17 00:00:00 2001 From: Shishir Suvarna Date: Wed, 15 Nov 2023 22:24:28 +0530 Subject: [PATCH 3/3] PHPCS Fix --- tests/src/Kernel/ApigeeX/ApigeeEdgeKernelTestBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Kernel/ApigeeX/ApigeeEdgeKernelTestBase.php b/tests/src/Kernel/ApigeeX/ApigeeEdgeKernelTestBase.php index c44d8555..55628736 100644 --- a/tests/src/Kernel/ApigeeX/ApigeeEdgeKernelTestBase.php +++ b/tests/src/Kernel/ApigeeX/ApigeeEdgeKernelTestBase.php @@ -40,7 +40,7 @@ protected function setUp(): void { parent::setUp(); } - /** + /** * Stores pre-configured token storage service for testing. */ protected function storeToken() {