diff --git a/modules/common/src/Controller/OpenApiController.php b/modules/common/src/Controller/OpenApiController.php index d0ce5f4241..bfd38cc63d 100644 --- a/modules/common/src/Controller/OpenApiController.php +++ b/modules/common/src/Controller/OpenApiController.php @@ -15,8 +15,6 @@ /** * Serves openapi spec for dataset-related endpoints. - * - * @codeCoverageIgnore */ class OpenApiController implements ContainerInjectionInterface { use JsonResponseTrait; diff --git a/modules/common/tests/src/Functional/DkanDocsTest.php b/modules/common/tests/src/Functional/Controller/OpenApiControllerTest.php similarity index 62% rename from modules/common/tests/src/Functional/DkanDocsTest.php rename to modules/common/tests/src/Functional/Controller/OpenApiControllerTest.php index 5b475e8cbb..74a7847d43 100644 --- a/modules/common/tests/src/Functional/DkanDocsTest.php +++ b/modules/common/tests/src/Functional/Controller/OpenApiControllerTest.php @@ -1,12 +1,29 @@ getController(); @@ -23,15 +40,14 @@ public function testGetCompleteJson() { $data = json_decode($response->getContent(), TRUE); // Basic auth is included. - $this->assertTrue(isset($data["components"]["securitySchemes"]["basic_auth"])); + $this->assertTrue(isset($data['components']['securitySchemes']['basic_auth'])); // Some sample paths from different modules are there - $this->assertArrayHasKey('/api/1/datastore/imports', $data["paths"]); - $this->assertArrayHasKey('/api/1/harvest/plans/{plan_id}', $data["paths"]); - $this->assertArrayHasKey('/api/1/metastore/schemas/{schema_id}', $data["paths"]); + $this->assertArrayHasKey('/api/1/datastore/imports', $data['paths']); + $this->assertArrayHasKey('/api/1/harvest/plans/{plan_id}', $data['paths']); + $this->assertArrayHasKey('/api/1/metastore/schemas/{schema_id}', $data['paths']); } - public function testGetCompleteYaml() { $controller = $this->getController(); $response = $controller->getComplete('yaml'); @@ -39,16 +55,16 @@ public function testGetCompleteYaml() { $data = Yaml::decode($response->getContent(), TRUE); // Basic auth is included. - $this->assertTrue(isset($data["components"]["securitySchemes"]["basic_auth"])); + $this->assertTrue(isset($data['components']['securitySchemes']['basic_auth'])); // Some sample paths from different modules are there - $this->assertArrayHasKey('/api/1/datastore/imports', $data["paths"]); - $this->assertArrayHasKey('/api/1/harvest/plans/{plan_id}', $data["paths"]); - $this->assertArrayHasKey('/api/1/metastore/schemas/{schema_id}', $data["paths"]); + $this->assertArrayHasKey('/api/1/datastore/imports', $data['paths']); + $this->assertArrayHasKey('/api/1/harvest/plans/{plan_id}', $data['paths']); + $this->assertArrayHasKey('/api/1/metastore/schemas/{schema_id}', $data['paths']); } public function testGetNoAuth() { - $controller = $this->getController(["authentication" => "false"]); + $controller = $this->getController(['authentication' => 'false']); $response = $controller->getComplete(); // Simulate an authentication=false parameter in the request stack. @@ -56,27 +72,24 @@ public function testGetNoAuth() { $data = json_decode($response->getContent(), TRUE); // Basic auth is excluded. - $this->assertFalse(isset($data["components"]["securitySchemes"]["basic_auth"])); + $this->assertFalse(isset($data['components']['securitySchemes']['basic_auth'])); // Authorized paths are not there. - $this->assertArrayNotHasKey('/api/1/datastore/imports', $data["paths"]); - $this->assertArrayNotHasKey('/api/1/harvest/plans/{plan_id}', $data["paths"]); + $this->assertArrayNotHasKey('/api/1/datastore/imports', $data['paths']); + $this->assertArrayNotHasKey('/api/1/harvest/plans/{plan_id}', $data['paths']); // Public paths still there. - $this->assertArrayHasKey('/api/1/metastore/schemas/{schema_id}', $data["paths"]); + $this->assertArrayHasKey('/api/1/metastore/schemas/{schema_id}', $data['paths']); } private function getController(array $params = []) { - $requestStack = \Drupal::service('request_stack'); - - if (!empty($params)) { + if ($params) { + /** @var \Symfony\Component\HttpFoundation\RequestStack $requestStack */ + $requestStack = $this->container->get('request_stack'); $request = $requestStack->pop()->duplicate($params); $requestStack->push($request); } - return new OpenApiController( - $requestStack, - \Drupal::service('dkan.common.docs_generator') - ); + return OpenApiController::create($this->container); } }