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