From 22c76fc73e49e7397a0e17e08d9732b9b46f48a7 Mon Sep 17 00:00:00 2001 From: arshad Date: Mon, 6 Apr 2020 21:22:15 +0400 Subject: [PATCH] [#375] Switch to mocks for Functional StatusReportTest (#389) * [#375] Switch to mocks for Functional StatusReportTest * [#375] Switch to mocks for Functional StatusReportTest. Co-authored-by: Arlina Espinoza --- tests/modules/apigee_mock_api_client/README.md | 6 ++++++ .../tests/response-templates/access-token.json.twig | 8 ++++++++ tests/src/Functional/StatusReportTest.php | 13 +++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 tests/modules/apigee_mock_api_client/tests/response-templates/access-token.json.twig diff --git a/tests/modules/apigee_mock_api_client/README.md b/tests/modules/apigee_mock_api_client/README.md index dc5df1c6..4774ef38 100644 --- a/tests/modules/apigee_mock_api_client/README.md +++ b/tests/modules/apigee_mock_api_client/README.md @@ -116,3 +116,9 @@ For convenience, helper methods have been added to `ApigeeMockApiClientHelperTra See [ApigeeMockApiClientHelperTrait](tests/src/Traits/ApigeeMockApiClientHelperTrait.php) for a full list of helper methods and documentation on usage. + +Notes: + +- This module is not currently compatible with `apigee_edge_test` or `apigee_edge_debug`, as they decorate the +SDK connector client, and this module replaces one of the arguments (injected services). Refactored tests should not +enable those modules. diff --git a/tests/modules/apigee_mock_api_client/tests/response-templates/access-token.json.twig b/tests/modules/apigee_mock_api_client/tests/response-templates/access-token.json.twig new file mode 100644 index 00000000..727ff57f --- /dev/null +++ b/tests/modules/apigee_mock_api_client/tests/response-templates/access-token.json.twig @@ -0,0 +1,8 @@ +{ + "access_token": "yeJhbGciOiJSUzI1NiJ9.eyJqdGkiOiIxNWE0ZDlmNS0xNWEyLTQ3NzYtYjg1My0zZTMxZDBjMmI5MGYiLCJzdWIiOiJmMjgzZGZlOC1mMDJhLTRkNmEtYWMyZC0zMGI1ZDQ5ZGZmNjEiLCJzY29wZSI6WyJzY2ltLmVtYWlscy5yZWFkIiwic2NpbS5tZSIsIm9wZW5pZCIsInBhc3N3b3JkLnd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jp_BOTNDFBuSpqv8qwGmTQOmMAVfjyzEpI_7M7x", + "expires_in": 43199, + "scope": "scim.emails.read scim.me openid password.write approvals.me scim.ids.read oauth.approvals", + "jti": "17a4d9f5-15a2-4776-b853-3e31d0c2b90i" +} diff --git a/tests/src/Functional/StatusReportTest.php b/tests/src/Functional/StatusReportTest.php index 6c424540..65409f9b 100644 --- a/tests/src/Functional/StatusReportTest.php +++ b/tests/src/Functional/StatusReportTest.php @@ -41,14 +41,22 @@ class StatusReportTest extends ApigeeEdgeFunctionalTestBase { const CANNOT_CONNECT_LONG = 'Cannot connect to Apigee Edge server. You have either given wrong credential details or the Apigee Edge server is unreachable. Visit the Apigee Edge general settings page to get more information.'; + /** + * {@inheritdoc} + */ + protected static $mock_api_client_ready = TRUE; + /** * Tests invalid credentials. */ public function testInvalidCredentials() { + $orgName = $this->sdkConnector->getOrganization(); + $this->drupalLogin($this->rootUser); $status_report_path = Url::fromRoute('system.status'); // Ensure that pre-defined credentials are correctly set. + $this->stack->queueMockResponse(['org' => ['org_name' => $orgName]]); $this->drupalGet($status_report_path); $this->assertSession()->pageTextNotContains(self::CANNOT_CONNECT_SHORT); @@ -82,6 +90,7 @@ public function testInvalidCredentials() { $key->save(); $this->setKey('private_file'); + $this->stack->queueMockResponse(['org' => ['org_name' => $orgName]]); $this->drupalGet($status_report_path); $this->assertSession()->pageTextNotContains(self::CANNOT_CONNECT_SHORT); @@ -95,6 +104,7 @@ public function testInvalidCredentials() { ])); $key->save(); + $this->stack->queueMockResponse(['get_not_found' => ['status_code' => 401]]); $this->drupalGet($status_report_path); $this->assertSession()->pageTextContains(self::CANNOT_CONNECT_LONG); @@ -117,6 +127,8 @@ public function testInvalidCredentials() { $this->setKey('private_file_oauth'); + $this->stack->queueMockResponse('access_token'); + $this->stack->queueMockResponse(['org' => ['org_name' => $orgName]]); $this->drupalGet($status_report_path); $this->assertSession()->pageTextNotContains(self::CANNOT_CONNECT_SHORT); @@ -130,6 +142,7 @@ public function testInvalidCredentials() { ])); $key->save(); + $this->stack->queueMockResponse('get_not_found'); $this->drupalGet($status_report_path); $this->assertSession()->pageTextContains(self::CANNOT_CONNECT_LONG);