From a5d37d5092b2aa5717a307eea00cbd3d942968dc Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Wed, 12 Jun 2024 14:53:22 +0200 Subject: [PATCH] refs #452. Migrate clients and hardware profile ended --- migrations/Version20240612105731.php | 33 ++++ migrations/Version20240612111552.php | 37 +++++ .../OrganizationalUnitClassroomInput.php | 5 +- src/Entity/NetworkSettings.php | 4 +- tests/Functional/OrganizationalUnitTest.php | 148 ++++++++++++++++++ 5 files changed, 222 insertions(+), 5 deletions(-) create mode 100644 migrations/Version20240612105731.php create mode 100644 migrations/Version20240612111552.php create mode 100644 tests/Functional/OrganizationalUnitTest.php diff --git a/migrations/Version20240612105731.php b/migrations/Version20240612105731.php new file mode 100644 index 0000000..f61d5c1 --- /dev/null +++ b/migrations/Version20240612105731.php @@ -0,0 +1,33 @@ +addSql('ALTER TABLE client CHANGE name name VARCHAR(255) NOT NULL'); + $this->addSql('ALTER TABLE network_settings CHANGE mcast_speed mcast_speed INT DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE network_settings CHANGE mcast_speed mcast_speed INT NOT NULL'); + $this->addSql('ALTER TABLE client CHANGE name name VARCHAR(255) DEFAULT NULL'); + } +} diff --git a/migrations/Version20240612111552.php b/migrations/Version20240612111552.php new file mode 100644 index 0000000..a5cca1d --- /dev/null +++ b/migrations/Version20240612111552.php @@ -0,0 +1,37 @@ +addSql('ALTER TABLE client CHANGE name name VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE hardware CHANGE name name VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE organizational_unit CHANGE name name VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE user_group CHANGE name name VARCHAR(255) DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE hardware CHANGE name name VARCHAR(255) NOT NULL'); + $this->addSql('ALTER TABLE user_group CHANGE name name VARCHAR(255) NOT NULL'); + $this->addSql('ALTER TABLE organizational_unit CHANGE name name VARCHAR(255) NOT NULL'); + $this->addSql('ALTER TABLE client CHANGE name name VARCHAR(255) NOT NULL'); + } +} diff --git a/src/Dto/Input/OrganizationalUnitClassroomInput.php b/src/Dto/Input/OrganizationalUnitClassroomInput.php index 8231b46..dad97b7 100644 --- a/src/Dto/Input/OrganizationalUnitClassroomInput.php +++ b/src/Dto/Input/OrganizationalUnitClassroomInput.php @@ -2,6 +2,7 @@ namespace App\Dto\Input; +use App\Dto\Output\OrganizationalUnitOutput; use App\Entity\NetworkSettings; use App\Entity\OrganizationalUnit; use App\Model\OrganizationalUnitTypes; @@ -87,9 +88,7 @@ final class OrganizationalUnitClassroomInput extends OrganizationalUnitInput ?EntityManagerInterface $entityManager = null ): OrganizationalUnit { - if (!$organizationalUnit) { - $organizationalUnit = new OrganizationalUnit(); - } + $organizationalUnit = parent::createOrUpdateEntity($organizationalUnit); $organizationalUnit->setType(OrganizationalUnitTypes::CLASSROOM); $organizationalUnit->setLocation($this->location); diff --git a/src/Entity/NetworkSettings.php b/src/Entity/NetworkSettings.php index e229208..c9a0a4c 100644 --- a/src/Entity/NetworkSettings.php +++ b/src/Entity/NetworkSettings.php @@ -34,7 +34,7 @@ class NetworkSettings extends AbstractEntity #[ORM\Column(length: 255, nullable: true)] private ?string $mcastIp = null; - #[ORM\Column] + #[ORM\Column(length: 255, nullable: true)] private ?int $mcastSpeed = null; #[ORM\Column(length: 255, nullable: true)] @@ -161,7 +161,7 @@ class NetworkSettings extends AbstractEntity return $this->mcastSpeed; } - public function setMcastSpeed(int $mcastSpeed): static + public function setMcastSpeed(?int $mcastSpeed): static { $this->mcastSpeed = $mcastSpeed; diff --git a/tests/Functional/OrganizationalUnitTest.php b/tests/Functional/OrganizationalUnitTest.php new file mode 100644 index 0000000..7bd6ca7 --- /dev/null +++ b/tests/Functional/OrganizationalUnitTest.php @@ -0,0 +1,148 @@ + self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + OrganizationalUnitFactory::createMany(2, ['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]); + OrganizationalUnitFactory::createMany(2, ['type' => OrganizationalUnitTypes::CLASSROOMS_GROUP]); + OrganizationalUnitFactory::createMany(2, ['type' => OrganizationalUnitTypes::CLASSROOM]); + OrganizationalUnitFactory::createMany(2, ['type' => OrganizationalUnitTypes::CLIENTS_GROUP]); + + $this->createClientWithCredentials()->request('GET', '/organizational-units'); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/OrganizationalUnit', + '@id' => '/organizational-units', + '@type' => 'hydra:Collection', + 'hydra:totalItems' => 8, + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testCreateOrganizationalUnitRoot(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + $this->createClientWithCredentials()->request('POST', '/organizational-units/root',['json' => [ + 'name' => self::ORGANIZATIONAL_UNIT_CREATE, + ]]); + + $this->assertResponseStatusCodeSame(201); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/OrganizationalUnitOutput', + '@type' => 'OrganizationalUnit', + 'name' => self::ORGANIZATIONAL_UNIT_CREATE, + 'type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT, + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testCreateOrganizationalUnitClassroomGroup(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + $this->createClientWithCredentials()->request('POST', '/organizational-units/classroom-group',['json' => [ + 'name' => self::ORGANIZATIONAL_UNIT_CREATE, + ]]); + + $this->assertResponseStatusCodeSame(201); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/OrganizationalUnitOutput', + '@type' => 'OrganizationalUnit', + 'name' => self::ORGANIZATIONAL_UNIT_CREATE, + 'type' => OrganizationalUnitTypes::CLASSROOMS_GROUP, + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testCreateOrganizationalUnitClassroom(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + $this->createClientWithCredentials()->request('POST', '/organizational-units/classroom',['json' => [ + 'name' => self::ORGANIZATIONAL_UNIT_CREATE, + ]]); + + $this->assertResponseStatusCodeSame(201); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/OrganizationalUnitOutput', + '@type' => 'OrganizationalUnit', + 'name' => self::ORGANIZATIONAL_UNIT_CREATE, + 'type' => OrganizationalUnitTypes::CLASSROOM, + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testCreateOrganizationalUnitClientGroup(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + $this->createClientWithCredentials()->request('POST', '/organizational-units/client-group',['json' => [ + 'name' => self::ORGANIZATIONAL_UNIT_CREATE, + ]]); + + $this->assertResponseStatusCodeSame(201); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/OrganizationalUnitOutput', + '@type' => 'OrganizationalUnit', + 'name' => self::ORGANIZATIONAL_UNIT_CREATE, + 'type' => OrganizationalUnitTypes::CLIENTS_GROUP, + ]); + } +} \ No newline at end of file