self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); UserFactory::createMany(10); $this->createClientWithCredentials()->request('GET', '/users'); $this->assertResponseStatusCodeSame(Response::HTTP_OK); $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); $this->assertJsonContains([ '@context' => '/contexts/User', '@id' => '/users', '@type' => 'hydra:Collection', 'hydra:totalItems' => 11, ]); } /** * @throws RedirectionExceptionInterface * @throws DecodingExceptionInterface * @throws ClientExceptionInterface * @throws TransportExceptionInterface * @throws ServerExceptionInterface */ public function testCreateUser(): void { UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); $this->createClientWithCredentials()->request('POST', '/users',['json' => [ 'username' => self::USER_CREATE, 'password' => '12345678', 'enabled' => true, ]]); $this->assertResponseStatusCodeSame(201); $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); $this->assertJsonContains([ '@context' => '/contexts/UserOutput', '@type' => 'User', 'username' => self::USER_CREATE, 'enabled' => true, ]); } /** * @throws RedirectionExceptionInterface * @throws DecodingExceptionInterface * @throws ClientExceptionInterface * @throws TransportExceptionInterface * @throws ServerExceptionInterface */ public function testUpdateUser(): void { UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); UserFactory::createOne(['username' => self::USER_UPDATE, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); $iri = $this->findIriBy(User::class, ['username' => self::USER_UPDATE]); $this->createClientWithCredentials()->request('PATCH', $iri, ['json' => [ 'username' => self::USER_UPDATE, ]]); $this->assertResponseIsSuccessful(); $this->assertJsonContains([ '@id' => $iri, 'username' => self::USER_UPDATE, ]); } /** * @throws TransportExceptionInterface * @throws ServerExceptionInterface * @throws RedirectionExceptionInterface * @throws DecodingExceptionInterface * @throws ClientExceptionInterface */ public function testDeleteUser(): void { UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); UserFactory::createOne(['username' => self::USER_DELETE, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); $iri = $this->findIriBy(User::class, ['username' => self::USER_DELETE]); $this->createClientWithCredentials()->request('DELETE', $iri); $this->assertResponseStatusCodeSame(204); $this->assertNull( static::getContainer()->get('doctrine')->getRepository(User::class)->findOneBy(['username' => self::USER_DELETE]) ); } }