self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); ClientFactory::createMany(10); $this->createClientWithCredentials()->request('GET', '/clients'); $this->assertResponseStatusCodeSame(Response::HTTP_OK); $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); $this->assertJsonContains([ '@context' => '/contexts/Client', '@id' => '/clients', '@type' => 'hydra:Collection', 'hydra:totalItems' => 10, ]); } /** * @throws RedirectionExceptionInterface * @throws DecodingExceptionInterface * @throws ClientExceptionInterface * @throws TransportExceptionInterface * @throws ServerExceptionInterface */ public function testCreateClient(): void { UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); OrganizationalUnitFactory::createOne(['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]); $ouIri = $this->findIriBy(OrganizationalUnit::class, ['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]); HardwareProfileFactory::createOne(['description' => self::HW_PROFILE]); $hpIri = $this->findIriBy(HardwareProfile::class, ['description' => self::HW_PROFILE]); $this->createClientWithCredentials()->request('POST', '/clients',['json' => [ 'name' => self::CLIENT_CREATE, 'organizationalUnit' => $ouIri, 'hardwareProfile' => $hpIri, 'serialNumber' => '123abc', ]]); $this->assertResponseStatusCodeSame(201); $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); $this->assertJsonContains([ '@context' => '/contexts/ClientOutput', '@type' => 'Client', 'name' => self::CLIENT_CREATE, 'serialNumber' => '123abc', ]); } /** * @throws RedirectionExceptionInterface * @throws DecodingExceptionInterface * @throws ClientExceptionInterface * @throws TransportExceptionInterface * @throws ServerExceptionInterface */ public function testUpdateClient(): void { UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); $ou = OrganizationalUnitFactory::createOne(['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]); $hp = HardwareProfileFactory::createOne(['description' => self::HW_PROFILE]); ClientFactory::createOne(['name' => self::CLIENT_UPDATE, 'serialNumber' => '123abc', 'organizationalUnit' => $ou, 'hardwareProfile' => $hp]); $iri = $this->findIriBy(Client::class, ['name' => self::CLIENT_UPDATE]); $this->createClientWithCredentials()->request('PUT', $iri, ['json' => [ 'name' => self::CLIENT_UPDATE, 'serialNumber' => '987zyx' ]]); $this->assertResponseIsSuccessful(); $this->assertJsonContains([ '@id' => $iri, 'name' => self::CLIENT_UPDATE, 'serialNumber' => '987zyx' ]); } /** * @throws TransportExceptionInterface * @throws ServerExceptionInterface * @throws RedirectionExceptionInterface * @throws DecodingExceptionInterface * @throws ClientExceptionInterface */ public function testDeleteClient(): void { UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); $ou = OrganizationalUnitFactory::createOne(['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]); $hp = HardwareProfileFactory::createOne(['description' => self::HW_PROFILE]); ClientFactory::createOne(['name' => self::CLIENT_DELETE, 'serialNumber' => '123abc', 'organizationalUnit' => $ou, 'hardwareProfile' => $hp]); $iri = $this->findIriBy(Client::class, ['name' => self::CLIENT_DELETE]); $this->createClientWithCredentials()->request('DELETE', $iri); $this->assertResponseStatusCodeSame(204); $this->assertNull( static::getContainer()->get('doctrine')->getRepository(Client::class)->findOneBy(['name' => self::CLIENT_DELETE]) ); } }