pull/13/head
parent
50f2fff71e
commit
3d0b4f25e2
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
|
||||
namespace Functional;
|
||||
|
||||
use App\Entity\Client;
|
||||
use App\Entity\HardwareProfile;
|
||||
use App\Entity\ImageRepository;
|
||||
use App\Entity\Menu;
|
||||
use App\Entity\OrganizationalUnit;
|
||||
use App\Entity\User;
|
||||
use App\Factory\ClientFactory;
|
||||
use App\Factory\HardwareProfileFactory;
|
||||
use App\Factory\ImageRepositoryFactory;
|
||||
use App\Factory\MenuFactory;
|
||||
use App\Factory\OrganizationalUnitFactory;
|
||||
use App\Factory\UserFactory;
|
||||
use App\Model\OrganizationalUnitTypes;
|
||||
use App\Model\UserGroupPermissions;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
|
||||
class ImageRepositoryTest extends AbstractTest
|
||||
{
|
||||
CONST string USER_ADMIN = 'ogadmin';
|
||||
CONST string REPOSITORY_CREATE = 'test-repository-create';
|
||||
CONST string REPOSITORY_UPDATE = 'test-repository-update';
|
||||
CONST string REPOSITORY_DELETE = 'test-repository-delete';
|
||||
|
||||
/**
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
*/
|
||||
public function testGetCollectionRepositories(): void
|
||||
{
|
||||
UserFactory::createOne(['username' => 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])
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue