129 lines
4.7 KiB
PHP
129 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace Functional;
|
|
|
|
use App\Entity\Command;
|
|
use App\Entity\CommandTask;
|
|
use App\Factory\CommandFactory;
|
|
use App\Factory\CommandTaskFactory;
|
|
use App\Factory\UserFactory;
|
|
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 CommandTaskTest extends AbstractTest
|
|
{
|
|
CONST string USER_ADMIN = 'ogadmin';
|
|
|
|
CONST string CMD_TASK_CREATE = 'test-cmd-task-create';
|
|
CONST string CMD_TASK_UPDATE = 'test-cmd-task-update';
|
|
CONST string CMD_TASK_DELETE = 'test-cmd-task-delete';
|
|
CONST string CMD_CREATE = 'test-cmd-create';
|
|
|
|
/**
|
|
* @throws RedirectionExceptionInterface
|
|
* @throws DecodingExceptionInterface
|
|
* @throws ClientExceptionInterface
|
|
* @throws TransportExceptionInterface
|
|
* @throws ServerExceptionInterface
|
|
*/
|
|
public function testGetCollectionCommandTask(): void
|
|
{
|
|
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
|
|
|
|
CommandTaskFactory::createMany(10);
|
|
|
|
$this->createClientWithCredentials()->request('GET', '/command-tasks');
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
|
|
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
|
|
$this->assertJsonContains([
|
|
'@context' => '/contexts/CommandTask',
|
|
'@id' => '/command-tasks',
|
|
'@type' => 'hydra:Collection',
|
|
'hydra:totalItems' => 10,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @throws RedirectionExceptionInterface
|
|
* @throws DecodingExceptionInterface
|
|
* @throws ClientExceptionInterface
|
|
* @throws TransportExceptionInterface
|
|
* @throws ServerExceptionInterface
|
|
*/
|
|
public function testCreateCommandTask(): void
|
|
{
|
|
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
|
|
|
|
CommandFactory::createOne(['name' => self::CMD_CREATE]);
|
|
$commandIri = $this->findIriBy(Command::class, ['name' => self::CMD_CREATE]);
|
|
|
|
$date = new \DateTimeImmutable();
|
|
|
|
$this->createClientWithCredentials()->request('POST', '/command-tasks',['json' => [
|
|
'dateTime' => $date->format('Y-m-d H:i:s'),
|
|
'notes' => self::CMD_TASK_CREATE,
|
|
'commands' => [
|
|
$commandIri
|
|
]
|
|
]]);
|
|
|
|
$this->assertResponseStatusCodeSame(201);
|
|
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
|
|
$this->assertJsonContains([
|
|
'@context' => '/contexts/CommandTaskOutput',
|
|
'@type' => 'CommandTask',
|
|
'notes' => self::CMD_TASK_CREATE,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @throws RedirectionExceptionInterface
|
|
* @throws DecodingExceptionInterface
|
|
* @throws ClientExceptionInterface
|
|
* @throws TransportExceptionInterface
|
|
* @throws ServerExceptionInterface
|
|
*/
|
|
public function testUpdateCommandTask(): void
|
|
{
|
|
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
|
|
|
|
CommandTaskFactory::createOne(['notes' => self::CMD_TASK_CREATE]);
|
|
$iri = $this->findIriBy(CommandTask::class, ['notes' => self::CMD_TASK_CREATE]);
|
|
|
|
$this->createClientWithCredentials()->request('PUT', $iri, ['json' => [
|
|
'notes' => self::CMD_TASK_UPDATE,
|
|
]]);
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
$this->assertJsonContains([
|
|
'@id' => $iri,
|
|
'notes' => self::CMD_TASK_UPDATE
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @throws TransportExceptionInterface
|
|
* @throws ServerExceptionInterface
|
|
* @throws RedirectionExceptionInterface
|
|
* @throws DecodingExceptionInterface
|
|
* @throws ClientExceptionInterface
|
|
*/
|
|
public function testDeleteCommandTask(): void
|
|
{
|
|
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
|
|
|
|
CommandTaskFactory::createOne(['notes' => self::CMD_TASK_DELETE]);
|
|
$iri = $this->findIriBy(CommandTask::class, ['notes' => self::CMD_TASK_DELETE]);
|
|
|
|
$this->createClientWithCredentials()->request('DELETE', $iri);
|
|
$this->assertResponseStatusCodeSame(204);
|
|
$this->assertNull(
|
|
static::getContainer()->get('doctrine')->getRepository(CommandTask::class)->findOneBy(['notes' => self::CMD_TASK_DELETE])
|
|
);
|
|
}
|
|
} |