From 1e52ec42cada166cf6e747dca4cb1ddf8d152d2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 1 Oct 2023 21:56:05 +0200 Subject: [PATCH] Added tests for availability of the API documentation --- tests/API/APIDocsAvailabilityTest.php | 71 +++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/API/APIDocsAvailabilityTest.php diff --git a/tests/API/APIDocsAvailabilityTest.php b/tests/API/APIDocsAvailabilityTest.php new file mode 100644 index 00000000..053950e9 --- /dev/null +++ b/tests/API/APIDocsAvailabilityTest.php @@ -0,0 +1,71 @@ +. + */ + +declare(strict_types=1); + + +namespace API; + +use App\Entity\UserSystem\User; +use Doctrine\ORM\EntityManagerInterface; +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; + +class APIDocsAvailabilityTest extends WebTestCase +{ + /** + * @dataProvider urlProvider + */ + public function testDocAvailabilityForLoggedInUser(string $url): void + { + self::ensureKernelShutdown(); + $client = static::createClient(); + $user = static::getContainer()->get(EntityManagerInterface::class) + ->getRepository(User::class)->findOneBy(['name' => 'admin']); + $client->loginUser($user); + + $client->request('GET',$url); + self::assertResponseIsSuccessful(); + } + + /** + * @dataProvider urlProvider + */ + public function testDocForbidden(string $url): void + { + self::ensureKernelShutdown(); + $client = static::createClient(); + $user = static::getContainer()->get(EntityManagerInterface::class) + ->getRepository(User::class)->findOneBy(['name' => 'noread']); + $client->loginUser($user); + + $client->request('GET',$url); + self::assertResponseStatusCodeSame(403); + } + + public static function urlProvider(): array + { + return [ + ['/api'], + ['/api/docs.html'], + ['/api/docs.json'], + //['/api/docs.jsonld'], + ]; + } +} \ No newline at end of file