Skip to content

Commit

Permalink
Add mod list tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jskowronski39 committed Dec 29, 2023
1 parent 1caf350 commit f3e054a
Show file tree
Hide file tree
Showing 27 changed files with 1,135 additions and 114 deletions.
86 changes: 86 additions & 0 deletions src/DataFixtures/ModList/CupModListFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

namespace App\DataFixtures\ModList;

use App\DataFixtures\Dlc\CslaIronCurtainDlcFixture;
use App\DataFixtures\Mod\Directory\ArmaScriptProfilerModFixture;
use App\DataFixtures\Mod\Directory\Deprecated\R3ModFixture;
use App\DataFixtures\Mod\SteamWorkshop\Optional\AceInteractionMenuExpansionModFixture;
use App\DataFixtures\Mod\SteamWorkshop\Required\ArmaForcesMedicalModFixture;
use App\DataFixtures\Mod\SteamWorkshop\Required\Broken\ArmaForcesAceMedicalModFixture;
use App\DataFixtures\Mod\SteamWorkshop\Required\Deprecated\LegacyArmaForcesModsModFixture;
use App\DataFixtures\Mod\SteamWorkshop\Required\Disabled\ArmaForcesJbadBuildingFixModFixture;
use App\DataFixtures\ModGroup\CupModGroupFixture;
use App\DataFixtures\User\User1Fixture;
use App\Entity\ModList\ModList;
use App\Test\Traits\TimeTrait;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Ramsey\Uuid\Uuid;

class CupModListFixture extends Fixture implements DependentFixtureInterface
{
use TimeTrait;

public const ID = 'ea384489-c06c-4844-9e56-0e9a9c46bfaf';
public const NAME = 'CUP';
public const OWNER_ID = User1Fixture::ID;

public function load(ObjectManager $manager): void
{
$this->withTimeFrozenAt('2020-01-01T00:00:00+00:00', function () use ($manager): void {
$modList = new ModList(
Uuid::fromString(self::ID),
self::NAME,
null,
[
$this->getReference(R3ModFixture::ID),
$this->getReference(ArmaScriptProfilerModFixture::ID),

$this->getReference(AceInteractionMenuExpansionModFixture::ID),
$this->getReference(ArmaForcesAceMedicalModFixture::ID),
$this->getReference(LegacyArmaForcesModsModFixture::ID),
$this->getReference(ArmaForcesJbadBuildingFixModFixture::ID),
$this->getReference(ArmaForcesMedicalModFixture::ID),
],
[
$this->getReference(CupModGroupFixture::ID),
],
[
$this->getReference(CslaIronCurtainDlcFixture::ID),
],
$this->getReference(self::OWNER_ID),
true,
false,
);

$manager->persist($modList);
$manager->flush();

$this->addReference(self::ID, $modList);
});
}

public function getDependencies(): array
{
return [
User1Fixture::class, // owner

R3ModFixture::class,
ArmaScriptProfilerModFixture::class,

AceInteractionMenuExpansionModFixture::class,
ArmaForcesAceMedicalModFixture::class,
LegacyArmaForcesModsModFixture::class,
ArmaForcesJbadBuildingFixModFixture::class,
ArmaForcesMedicalModFixture::class,

CupModGroupFixture::class,

CslaIronCurtainDlcFixture::class,
];
}
}
5 changes: 3 additions & 2 deletions src/DataFixtures/ModList/DefaultModListFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ class DefaultModListFixture extends Fixture implements DependentFixtureInterface
use TimeTrait;

public const ID = 'f3e04dae-18a8-4533-99ea-d6d763ebabcf';
public const NAME = 'Default';

public function load(ObjectManager $manager): void
{
$this->withTimeFrozenAt('2020-01-01T00:00:00+00:00', function () use ($manager): void {
$modList = new ModList(
Uuid::fromString(self::ID),
'Default',
self::NAME,
null,
[
$this->getReference(R3ModFixture::ID),
Expand Down Expand Up @@ -77,7 +78,7 @@ public function load(ObjectManager $manager): void
],
null,
true,
false,
true,
);

$manager->persist($modList);
Expand Down
86 changes: 86 additions & 0 deletions src/DataFixtures/ModList/RhsModListFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

namespace App\DataFixtures\ModList;

use App\DataFixtures\Dlc\CslaIronCurtainDlcFixture;
use App\DataFixtures\Mod\Directory\ArmaScriptProfilerModFixture;
use App\DataFixtures\Mod\Directory\Deprecated\R3ModFixture;
use App\DataFixtures\Mod\SteamWorkshop\Optional\AceInteractionMenuExpansionModFixture;
use App\DataFixtures\Mod\SteamWorkshop\Required\ArmaForcesMedicalModFixture;
use App\DataFixtures\Mod\SteamWorkshop\Required\Broken\ArmaForcesAceMedicalModFixture;
use App\DataFixtures\Mod\SteamWorkshop\Required\Deprecated\LegacyArmaForcesModsModFixture;
use App\DataFixtures\Mod\SteamWorkshop\Required\Disabled\ArmaForcesJbadBuildingFixModFixture;
use App\DataFixtures\ModGroup\RhsModGroupFixture;
use App\DataFixtures\User\User2Fixture;
use App\Entity\ModList\ModList;
use App\Test\Traits\TimeTrait;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Ramsey\Uuid\Uuid;

class RhsModListFixture extends Fixture implements DependentFixtureInterface
{
use TimeTrait;

public const ID = 'c3b11c2f-9254-4262-bfde-3605df0149d4';
public const NAME = 'RHS';
public const OWNER_ID = User2Fixture::ID;

public function load(ObjectManager $manager): void
{
$this->withTimeFrozenAt('2020-01-01T00:00:00+00:00', function () use ($manager): void {
$modList = new ModList(
Uuid::fromString(self::ID),
self::NAME,
null,
[
$this->getReference(R3ModFixture::ID),
$this->getReference(ArmaScriptProfilerModFixture::ID),

$this->getReference(AceInteractionMenuExpansionModFixture::ID),
$this->getReference(ArmaForcesAceMedicalModFixture::ID),
$this->getReference(LegacyArmaForcesModsModFixture::ID),
$this->getReference(ArmaForcesJbadBuildingFixModFixture::ID),
$this->getReference(ArmaForcesMedicalModFixture::ID),
],
[
$this->getReference(RhsModGroupFixture::ID),
],
[
$this->getReference(CslaIronCurtainDlcFixture::ID),
],
$this->getReference(self::OWNER_ID),
false,
false,
);

$manager->persist($modList);
$manager->flush();

$this->addReference(self::ID, $modList);
});
}

public function getDependencies(): array
{
return [
User2Fixture::class, // owner

R3ModFixture::class,
ArmaScriptProfilerModFixture::class,

AceInteractionMenuExpansionModFixture::class,
ArmaForcesAceMedicalModFixture::class,
LegacyArmaForcesModsModFixture::class,
ArmaForcesJbadBuildingFixModFixture::class,
ArmaForcesMedicalModFixture::class,

RhsModGroupFixture::class,

CslaIronCurtainDlcFixture::class,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
use Doctrine\Persistence\ObjectManager;
use Ramsey\Uuid\Uuid;

class AdminUserFixture extends Fixture
class AdminFixture extends Fixture
{
public const ID = '31c9769f-4195-4fa8-b78d-0b54a1ceb8df';
public const USERNAME = 'admin#0';
public const EMAIL = '[email protected]';

public function load(ObjectManager $manager): void
{
Expand All @@ -21,9 +23,9 @@ public function load(ObjectManager $manager): void

$user = new User(
Uuid::fromString(self::ID),
'admin#0',
'[email protected]',
self::ID,
self::USERNAME,
self::EMAIL,
str_repeat('0', 18),
$permissions,
[],
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@
use Doctrine\Persistence\ObjectManager;
use Ramsey\Uuid\Uuid;

class RegularUserFixture extends Fixture
class User1Fixture extends Fixture
{
public const ID = '03f6066e-2fe9-44ac-b853-2921483f1950';
public const USERNAME = 'user#1';
public const EMAIL = '[email protected]';

public function load(ObjectManager $manager): void
{
$permissions = new UserPermissions(Uuid::fromString('35874dd8-8230-41ca-ab18-1acb3419c177'));
$permissions = new UserPermissions(Uuid::fromString('b62733f6-97dc-4031-b74a-ecb080c09658'));

$user = new User(
Uuid::fromString(self::ID),
'regular#0',
'[email protected]',
self::ID,
self::USERNAME,
self::EMAIL,
str_repeat('1', 18),
$permissions,
[],
null,
Expand Down
40 changes: 40 additions & 0 deletions src/DataFixtures/User/User2Fixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace App\DataFixtures\User;

use App\Entity\Permissions\UserPermissions;
use App\Entity\User\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Ramsey\Uuid\Uuid;

class User2Fixture extends Fixture
{
public const ID = '43c65dee-8da8-4198-87da-cb58ecc23508';
public const USERNAME = 'user#2';
public const EMAIL = '[email protected]';

public function load(ObjectManager $manager): void
{
$permissions = new UserPermissions(Uuid::fromString('97f1c390-46e8-47cd-b60d-e9cca1ae892e'));

$user = new User(
Uuid::fromString(self::ID),
self::USERNAME,
self::EMAIL,
str_repeat('2', 18),
$permissions,
[],
null,
null
);

$manager->persist($permissions);
$manager->persist($user);
$manager->flush();

$this->addReference(self::ID, $user);
}
}
40 changes: 40 additions & 0 deletions src/DataFixtures/User/User3Fixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace App\DataFixtures\User;

use App\Entity\Permissions\UserPermissions;
use App\Entity\User\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Ramsey\Uuid\Uuid;

class User3Fixture extends Fixture
{
public const ID = '7e1a0cae-e0c3-4b1d-9ce7-671505267a87';
public const USERNAME = 'user#3';
public const EMAIL = '[email protected]';

public function load(ObjectManager $manager): void
{
$permissions = new UserPermissions(Uuid::fromString('7dcfba43-a09c-46c0-9dbd-701442bd4f83'));

$user = new User(
Uuid::fromString(self::ID),
self::USERNAME,
self::EMAIL,
str_repeat('3', 18),
$permissions,
[],
null,
null
);

$manager->persist($permissions);
$manager->persist($user);
$manager->flush();

$this->addReference(self::ID, $user);
}
}
4 changes: 1 addition & 3 deletions src/Form/ModList/Dto/ModListFormDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Validator\Constraints as Assert;

/**
* @UniqueModListName(errorPath="name")
*/
#[UniqueModListName(errorPath: 'name')]
class ModListFormDto extends AbstractFormDto
{
protected ?UuidInterface $id = null;
Expand Down
6 changes: 5 additions & 1 deletion src/Validator/ModList/UniqueModListNameValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ public function validate(mixed $value, Constraint $constraint): void
}

$name = $value->getName();
if ('' === $name || null === $name) {
return;
}

$id = $value->getId();
if (!$name || $this->isColumnValueUnique(ModList::class, ['name' => $name], $id)) {
if ($this->isColumnValueUnique(ModList::class, ['name' => $name], $id)) {
return;
}

Expand Down
Loading

0 comments on commit f3e054a

Please sign in to comment.