127 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			127 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			PHP
		
	
	
| <?php
 | |
| 
 | |
| namespace Functional;
 | |
| 
 | |
| use App\Entity\Command;
 | |
| use App\Entity\CommandGroup;
 | |
| use App\Factory\CommandFactory;
 | |
| use App\Factory\CommandGroupFactory;
 | |
| 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 CommandGroupTest extends AbstractTest
 | |
| {
 | |
|     CONST string USER_ADMIN = 'ogadmin';
 | |
| 
 | |
|     CONST string CMD_GROUP_CREATE = 'test-cmd-group-create';
 | |
|     CONST string CMD_GROUP_UPDATE = 'test-cmd-group-update';
 | |
|     CONST string CMD_GROUP_DELETE = 'test-cmd-group-delete';
 | |
|     CONST string CMD_CREATE = 'test-cmd-create';
 | |
| 
 | |
| 
 | |
|     /**
 | |
|      * @throws RedirectionExceptionInterface
 | |
|      * @throws DecodingExceptionInterface
 | |
|      * @throws ClientExceptionInterface
 | |
|      * @throws TransportExceptionInterface
 | |
|      * @throws ServerExceptionInterface
 | |
|      */
 | |
|     public function testGetCollectionCommandGroup(): void
 | |
|     {
 | |
|         UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
 | |
| 
 | |
|         CommandGroupFactory::createMany(10);
 | |
| 
 | |
|         $this->createClientWithCredentials()->request('GET', '/command-groups');
 | |
|         $this->assertResponseStatusCodeSame(Response::HTTP_OK);
 | |
|         $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
 | |
|         $this->assertJsonContains([
 | |
|             '@context' => '/contexts/CommandGroup',
 | |
|             '@id' => '/command-groups',
 | |
|             '@type' => 'hydra:Collection',
 | |
|             'hydra:totalItems' => 10,
 | |
|         ]);
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @throws RedirectionExceptionInterface
 | |
|      * @throws DecodingExceptionInterface
 | |
|      * @throws ClientExceptionInterface
 | |
|      * @throws TransportExceptionInterface
 | |
|      * @throws ServerExceptionInterface
 | |
|      */
 | |
|     public function testCreateCommandGroup(): 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]);
 | |
| 
 | |
|         $this->createClientWithCredentials()->request('POST', '/command-groups',['json' => [
 | |
|             'name' => self::CMD_GROUP_CREATE,
 | |
|             'commands' => [
 | |
|                 $commandIri
 | |
|             ]
 | |
|         ]]);
 | |
| 
 | |
|         $this->assertResponseStatusCodeSame(201);
 | |
|         $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
 | |
|         $this->assertJsonContains([
 | |
|             '@context' => '/contexts/CommandGroupOutput',
 | |
|             '@type' => 'CommandGroup',
 | |
|             'name' => self::CMD_GROUP_CREATE,
 | |
|         ]);
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @throws RedirectionExceptionInterface
 | |
|      * @throws DecodingExceptionInterface
 | |
|      * @throws ClientExceptionInterface
 | |
|      * @throws TransportExceptionInterface
 | |
|      * @throws ServerExceptionInterface
 | |
|      */
 | |
|     public function testUpdateCommandGroup(): void
 | |
|     {
 | |
|         UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
 | |
| 
 | |
|         CommandGroupFactory::createOne(['name' => self::CMD_GROUP_CREATE]);
 | |
|         $iri = $this->findIriBy(CommandGroup::class, ['name' => self::CMD_GROUP_CREATE]);
 | |
| 
 | |
|         $this->createClientWithCredentials()->request('PUT', $iri, ['json' => [
 | |
|             'name' => self::CMD_GROUP_UPDATE,
 | |
|         ]]);
 | |
| 
 | |
|         $this->assertResponseIsSuccessful();
 | |
|         $this->assertJsonContains([
 | |
|             '@id' => $iri,
 | |
|             'name' => self::CMD_GROUP_UPDATE
 | |
|         ]);
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @throws TransportExceptionInterface
 | |
|      * @throws ServerExceptionInterface
 | |
|      * @throws RedirectionExceptionInterface
 | |
|      * @throws DecodingExceptionInterface
 | |
|      * @throws ClientExceptionInterface
 | |
|      */
 | |
|     public function testDeleteCommandGroup(): void
 | |
|     {
 | |
|         UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
 | |
| 
 | |
|         CommandGroupFactory::createOne(['name' => self::CMD_GROUP_DELETE]);
 | |
|         $iri = $this->findIriBy(CommandGroup::class, ['name' => self::CMD_GROUP_DELETE]);
 | |
| 
 | |
|         $this->createClientWithCredentials()->request('DELETE', $iri);
 | |
|         $this->assertResponseStatusCodeSame(204);
 | |
|         $this->assertNull(
 | |
|             static::getContainer()->get('doctrine')->getRepository(CommandGroup::class)->findOneBy(['name' => self::CMD_GROUP_DELETE])
 | |
|         );
 | |
|     }
 | |
| } |