-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
338e444
commit b1b5f42
Showing
11 changed files
with
604 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/DataFixtures/Mod/SteamWorkshop/Required/RhsAfrfModFixture.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DataFixtures\Mod\SteamWorkshop\Required; | ||
|
||
use App\Entity\Mod\Enum\ModTypeEnum; | ||
use App\Entity\Mod\SteamWorkshopMod; | ||
use App\Test\Traits\TimeTrait; | ||
use Doctrine\Bundle\FixturesBundle\Fixture; | ||
use Doctrine\Persistence\ObjectManager; | ||
use Ramsey\Uuid\Uuid; | ||
|
||
class RhsAfrfModFixture extends Fixture | ||
{ | ||
use TimeTrait; | ||
|
||
public const ID = '91e0eaf1-3cf1-4b2c-98a9-a2d74a69fa76'; | ||
public const ITEM_ID = 843425103; | ||
|
||
public function load(ObjectManager $manager): void | ||
{ | ||
$this->withTimeFrozenAt('2020-01-01T00:00:00+00:00', function () use ($manager): void { | ||
$mod = new SteamWorkshopMod( | ||
Uuid::fromString(self::ID), | ||
'RHS AFRF', | ||
null, | ||
null, | ||
ModTypeEnum::REQUIRED, | ||
self::ITEM_ID | ||
); | ||
|
||
$manager->persist($mod); | ||
$manager->flush(); | ||
|
||
$this->addReference(self::ID, $mod); | ||
}); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/DataFixtures/Mod/SteamWorkshop/Required/RhsGrefModFixture.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DataFixtures\Mod\SteamWorkshop\Required; | ||
|
||
use App\Entity\Mod\Enum\ModTypeEnum; | ||
use App\Entity\Mod\SteamWorkshopMod; | ||
use App\Test\Traits\TimeTrait; | ||
use Doctrine\Bundle\FixturesBundle\Fixture; | ||
use Doctrine\Persistence\ObjectManager; | ||
use Ramsey\Uuid\Uuid; | ||
|
||
class RhsGrefModFixture extends Fixture | ||
{ | ||
use TimeTrait; | ||
|
||
public const ID = 'a34b691c-50a2-475e-bd0a-43e707c45db5'; | ||
public const ITEM_ID = 843593391; | ||
|
||
public function load(ObjectManager $manager): void | ||
{ | ||
$this->withTimeFrozenAt('2020-01-01T00:00:00+00:00', function () use ($manager): void { | ||
$mod = new SteamWorkshopMod( | ||
Uuid::fromString(self::ID), | ||
'RHS GREF', | ||
null, | ||
null, | ||
ModTypeEnum::REQUIRED, | ||
self::ITEM_ID | ||
); | ||
|
||
$manager->persist($mod); | ||
$manager->flush(); | ||
|
||
$this->addReference(self::ID, $mod); | ||
}); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/DataFixtures/Mod/SteamWorkshop/Required/RhsUsafModFixture.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DataFixtures\Mod\SteamWorkshop\Required; | ||
|
||
use App\Entity\Mod\Enum\ModTypeEnum; | ||
use App\Entity\Mod\SteamWorkshopMod; | ||
use App\Test\Traits\TimeTrait; | ||
use Doctrine\Bundle\FixturesBundle\Fixture; | ||
use Doctrine\Persistence\ObjectManager; | ||
use Ramsey\Uuid\Uuid; | ||
|
||
class RhsUsafModFixture extends Fixture | ||
{ | ||
use TimeTrait; | ||
|
||
public const ID = 'a37a6a74-3e82-4955-a836-0732d7816cc1'; | ||
public const ITEM_ID = 843577117; | ||
|
||
public function load(ObjectManager $manager): void | ||
{ | ||
$this->withTimeFrozenAt('2020-01-01T00:00:00+00:00', function () use ($manager): void { | ||
$mod = new SteamWorkshopMod( | ||
Uuid::fromString(self::ID), | ||
'RHS USAF', | ||
null, | ||
null, | ||
ModTypeEnum::REQUIRED, | ||
self::ITEM_ID | ||
); | ||
|
||
$manager->persist($mod); | ||
$manager->flush(); | ||
|
||
$this->addReference(self::ID, $mod); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DataFixtures\ModGroup; | ||
|
||
use App\DataFixtures\Mod\SteamWorkshop\Required\RhsAfrfModFixture; | ||
use App\DataFixtures\Mod\SteamWorkshop\Required\RhsGrefModFixture; | ||
use App\DataFixtures\Mod\SteamWorkshop\Required\RhsUsafModFixture; | ||
use App\Entity\ModGroup\ModGroup; | ||
use App\Test\Traits\TimeTrait; | ||
use Doctrine\Bundle\FixturesBundle\Fixture; | ||
use Doctrine\Common\DataFixtures\DependentFixtureInterface; | ||
use Doctrine\Persistence\ObjectManager; | ||
use Ramsey\Uuid\Uuid; | ||
|
||
class RhsModGroupFixture extends Fixture implements DependentFixtureInterface | ||
{ | ||
use TimeTrait; | ||
|
||
public const ID = '33191331-2a40-4d95-ba18-d4a75b1d43d4'; | ||
public const NAME = 'RHS'; | ||
|
||
public function load(ObjectManager $manager): void | ||
{ | ||
$this->withTimeFrozenAt('2020-01-01T00:00:00+00:00', function () use ($manager): void { | ||
$modGroup = new ModGroup( | ||
Uuid::fromString(self::ID), | ||
self::NAME, | ||
null, | ||
[ | ||
$this->getReference(RhsAfrfModFixture::ID), | ||
$this->getReference(RhsGrefModFixture::ID), | ||
$this->getReference(RhsUsafModFixture::ID), | ||
] | ||
); | ||
|
||
$manager->persist($modGroup); | ||
$manager->flush(); | ||
|
||
$this->addReference(self::ID, $modGroup); | ||
}); | ||
} | ||
|
||
public function getDependencies(): array | ||
{ | ||
return [ | ||
RhsAfrfModFixture::class, | ||
RhsGrefModFixture::class, | ||
RhsUsafModFixture::class, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Functional\Web\ModGroup; | ||
|
||
use App\DataFixtures\Mod\SteamWorkshop\Required\CupTerrainsCoreModFixture; | ||
use App\DataFixtures\Mod\SteamWorkshop\Required\CupTerrainsMapsModFixture; | ||
use App\DataFixtures\User\RegularUserFixture; | ||
use App\Entity\Mod\AbstractMod; | ||
use App\Entity\ModGroup\ModGroup; | ||
use App\Entity\User\User; | ||
use App\Tests\FunctionalTester; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class CreateModGroupCest | ||
{ | ||
public function _before(FunctionalTester $I): void | ||
{ | ||
$I->stopFollowingRedirects(); | ||
$I->freezeTime('2020-01-01T00:00:00+00:00'); | ||
} | ||
|
||
public function createModGroupAsUnauthenticatedUser(FunctionalTester $I): void | ||
{ | ||
$I->amOnPage('/mod-group/create'); | ||
$I->seeResponseRedirectsToDiscordAuth(); | ||
} | ||
|
||
public function createModGroupAsUnauthorizedUser(FunctionalTester $I): void | ||
{ | ||
$I->amDiscordAuthenticatedAs(RegularUserFixture::ID); | ||
|
||
$I->amOnPage('/mod-group/create'); | ||
$I->seeResponseCodeIs(Response::HTTP_FORBIDDEN); | ||
} | ||
|
||
public function createModGroupAsAuthorizedUser(FunctionalTester $I): void | ||
{ | ||
$user = $I->amDiscordAuthenticatedAs(RegularUserFixture::ID, function (User $user): void { | ||
$user->getPermissions()->modGroupCreate = true; | ||
}); | ||
|
||
$I->amOnPage('/mod-group/create'); | ||
|
||
// Default form values | ||
$I->seeInField('Mod group name', ''); | ||
$I->seeInField('Mod group description', ''); | ||
$I->seeTableRowCheckboxesAreUnchecked('mod_group_form_mods_'); // All checkboxes are unchecked | ||
|
||
// Fill form | ||
$I->fillField('Mod group name', 'CUP Terrains'); | ||
$I->fillField('Mod group description', 'Terrains for CUP'); | ||
$I->checkTableRowCheckbox(CupTerrainsCoreModFixture::ID); | ||
$I->checkTableRowCheckbox(CupTerrainsMapsModFixture::ID); | ||
$I->click('Create mod group'); | ||
|
||
$I->seeResponseRedirectsTo('/mod-group/list'); | ||
|
||
/** @var ModGroup $modGroup */ | ||
$modGroup = $I->grabEntityFromRepository(ModGroup::class, ['name' => 'CUP Terrains']); | ||
$I->assertSame('CUP Terrains', $modGroup->getName()); | ||
$I->assertSame('Terrains for CUP', $modGroup->getDescription()); | ||
$I->assertSame([ | ||
CupTerrainsCoreModFixture::ID, | ||
CupTerrainsMapsModFixture::ID, | ||
], array_map(fn (AbstractMod $mod) => $mod->getId()->toString(), $modGroup->getMods())); | ||
|
||
$I->assertSame('2020-01-01T00:00:00+00:00', $modGroup->getCreatedAt()->format(DATE_ATOM)); | ||
// $I->assertSame($user, $modGroup->getCreatedBy()); // FIXME | ||
$I->assertSame(null, $modGroup->getLastUpdatedAt()); | ||
$I->assertSame(null, $modGroup->getLastUpdatedBy()); | ||
} | ||
|
||
public function createModGroupAsAuthorizedUserWhenModGroupAlreadyExists(FunctionalTester $I): void | ||
{ | ||
$I->amDiscordAuthenticatedAs(RegularUserFixture::ID, function (User $user): void { | ||
$user->getPermissions()->modGroupCreate = true; | ||
}); | ||
|
||
$I->amOnPage('/mod-group/create'); | ||
|
||
$I->fillField('Mod group name', 'CUP'); | ||
$I->click('Create mod group'); | ||
|
||
$I->canSeeFormErrorMessage('name', 'Mod group with the same name "CUP" already exist.'); | ||
} | ||
|
||
public function createModGroupAsAuthorizedUserWithoutRequiredData(FunctionalTester $I): void | ||
{ | ||
$I->amDiscordAuthenticatedAs(RegularUserFixture::ID, function (User $user): void { | ||
$user->getPermissions()->modGroupCreate = true; | ||
}); | ||
|
||
$I->amOnPage('/mod-group/create'); | ||
|
||
$I->fillField('Mod group name', ''); | ||
$I->click('Create mod group'); | ||
|
||
$I->canSeeFormErrorMessage('name', 'This value should not be blank.'); | ||
} | ||
|
||
public function createModGroupAsAuthorizedUserWithDataTooLong(FunctionalTester $I): void | ||
{ | ||
$I->amDiscordAuthenticatedAs(RegularUserFixture::ID, function (User $user): void { | ||
$user->getPermissions()->modGroupCreate = true; | ||
}); | ||
|
||
$I->amOnPage('/mod-group/create'); | ||
|
||
$I->fillField('Mod group name', str_repeat('a', 256)); | ||
$I->fillField('Mod group description', str_repeat('a', 256)); | ||
$I->click('Create mod group'); | ||
|
||
$I->canSeeFormErrorMessage('name', 'This value is too long. It should have 255 characters or less.'); | ||
$I->canSeeFormErrorMessage('description', 'This value is too long. It should have 255 characters or less.'); | ||
} | ||
} |
Oops, something went wrong.