From 3d0b4f25e2f5effa4d5b29233dbb520060cd582c Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Wed, 30 Oct 2024 10:53:25 +0100 Subject: [PATCH] refs #1082. ImageRepository Test --- tests/Functional/ImageRepositoryTest.php | 133 +++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 tests/Functional/ImageRepositoryTest.php diff --git a/tests/Functional/ImageRepositoryTest.php b/tests/Functional/ImageRepositoryTest.php new file mode 100644 index 0000000..da616c6 --- /dev/null +++ b/tests/Functional/ImageRepositoryTest.php @@ -0,0 +1,133 @@ + self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + ImageRepositoryFactory::createMany(10); + + $this->createClientWithCredentials()->request('GET', '/image-repositories'); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/ImageRepository', + '@id' => '/image-repositories', + '@type' => 'hydra:Collection', + 'hydra:totalItems' => 10, + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testCreateRepository(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + $this->createClientWithCredentials()->request('POST', '/image-repositories',['json' => [ + 'name' => self::REPOSITORY_CREATE, + 'comments' => self::REPOSITORY_CREATE, + 'ip' => '127.0.0.1' + ]]); + + $this->assertResponseStatusCodeSame(201); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/ImageRepositoryOutput', + '@type' => 'ImageRepository', + 'name' => self::REPOSITORY_CREATE, + 'comments' => self::REPOSITORY_CREATE, + 'ip' => '127.0.0.1' + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testUpdateRepository(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + ImageRepositoryFactory::createOne(['name' => self::REPOSITORY_UPDATE, 'comments' => self::REPOSITORY_UPDATE]); + $iri = $this->findIriBy(ImageRepository::class, ['name' => self::REPOSITORY_UPDATE]); + + $this->createClientWithCredentials()->request('PUT', $iri, ['json' => [ + 'name' => self::REPOSITORY_UPDATE, + 'comments' => self::REPOSITORY_UPDATE, + 'ip' => '127.0.0.1' + ]]); + + $this->assertResponseIsSuccessful(); + $this->assertJsonContains([ + '@id' => $iri, + 'name' => self::REPOSITORY_UPDATE, + 'comments' => self::REPOSITORY_UPDATE, + 'ip' => '127.0.0.1' + ]); + } + + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + */ + public function testDeleteRepository(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + ImageRepositoryFactory::createOne(['name' => self::REPOSITORY_DELETE, 'comments' => self::REPOSITORY_DELETE]); + $iri = $this->findIriBy(ImageRepository::class, ['name' => self::REPOSITORY_DELETE]); + $this->createClientWithCredentials()->request('DELETE', $iri); + $this->assertResponseStatusCodeSame(204); + $this->assertNull( + static::getContainer()->get('doctrine')->getRepository(ImageRepository::class)->findOneBy(['name' => self::REPOSITORY_DELETE]) + ); + } +} \ No newline at end of file