self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); ViewFactory::createMany(10, ['user' => $user]); $this->createClientWithCredentials()->request('GET', '/views'); $this->assertResponseStatusCodeSame(Response::HTTP_OK); $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); $this->assertJsonContains([ '@context' => '/contexts/View', '@id' => '/views', '@type' => 'hydra:Collection', 'hydra:totalItems' => 10, ]); } /** * @throws RedirectionExceptionInterface * @throws DecodingExceptionInterface * @throws ClientExceptionInterface * @throws TransportExceptionInterface * @throws ServerExceptionInterface */ public function testCreateView(): void { $user = UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); ViewFactory::createOne(['name' => self::VIEW_CREATE, 'favourite' => true, 'user' => $user]); $viewIri = $this->findIriBy(View::class, ['name' => self::VIEW_CREATE]); $this->createClientWithCredentials()->request('POST', '/views',['json' => [ 'name' => self::VIEW_CREATE, 'favourite' => true ]]); $this->assertResponseStatusCodeSame(201); $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); $this->assertJsonContains([ '@context' => '/contexts/ViewOutput', '@type' => 'View', 'name' => self::VIEW_CREATE ]); } /** * @throws RedirectionExceptionInterface * @throws DecodingExceptionInterface * @throws ClientExceptionInterface * @throws TransportExceptionInterface * @throws ServerExceptionInterface */ public function testUpdateView(): void { $user = UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); ViewFactory::createOne(['name' => self::VIEW_CREATE, 'favourite' => true, 'user' => $user]); $viewIri = $this->findIriBy(View::class, ['name' => self::VIEW_CREATE]); $this->createClientWithCredentials()->request('PUT', $viewIri, ['json' => [ 'name' => self::VIEW_UPDATE, 'favourite' => false ]]); $this->assertResponseIsSuccessful(); $this->assertJsonContains([ '@id' => $viewIri, 'name' => self::VIEW_UPDATE, 'favorite' => false ]); } /** * @throws TransportExceptionInterface * @throws ServerExceptionInterface * @throws RedirectionExceptionInterface * @throws DecodingExceptionInterface * @throws ClientExceptionInterface */ public function testDeleteView(): void { $user = UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); ViewFactory::createOne(['name' => self::VIEW_DELETE, 'favourite' => true, 'user' => $user]); $viewIri = $this->findIriBy(View::class, ['name' => self::VIEW_DELETE]); $this->createClientWithCredentials()->request('DELETE', $viewIri); $this->assertResponseStatusCodeSame(204); $this->assertNull( static::getContainer()->get('doctrine')->getRepository(View::class)->findOneBy(['name' => self::VIEW_DELETE]) ); } }