From 8d93106c64b3e24e8c4a1c8d1c445bdcb5a539ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Skowro=C5=84ski?= Date: Wed, 10 Jan 2024 22:53:48 +0100 Subject: [PATCH] Add mod list public tests --- .../ModListPublic/DownloadAction.php | 4 +- tests/_support/Helper/Functional.php | 12 -- .../ModListPublic/CustomizeModListCest.php | 9 ++ .../Web/ModListPublic/DownloadModListCest.php | 111 ++++++++++++++++++ .../Web/ModListPublic/SelectModListCest.php | 34 ++++++ 5 files changed, 157 insertions(+), 13 deletions(-) delete mode 100644 tests/_support/Helper/Functional.php create mode 100644 tests/functional/Web/ModListPublic/CustomizeModListCest.php create mode 100644 tests/functional/Web/ModListPublic/DownloadModListCest.php create mode 100644 tests/functional/Web/ModListPublic/SelectModListCest.php diff --git a/src/Controller/ModListPublic/DownloadAction.php b/src/Controller/ModListPublic/DownloadAction.php index e476648c..dc50c1c9 100644 --- a/src/Controller/ModListPublic/DownloadAction.php +++ b/src/Controller/ModListPublic/DownloadAction.php @@ -13,6 +13,8 @@ use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; +use function Symfony\Component\Clock\now; + class DownloadAction extends AbstractController { public function __construct( @@ -24,7 +26,7 @@ public function __construct( #[IsGranted(PermissionsEnum::MOD_LIST_DOWNLOAD->value, 'modList')] public function __invoke(ModList $modList, string $optionalModsJson = null): Response { - $name = sprintf('ArmaForces %s %s', $modList->getName(), (new \DateTimeImmutable())->format('Y_m_d H_i')); + $name = sprintf('ArmaForces %s %s', $modList->getName(), now()->format('Y_m_d H_i')); $mods = $this->modRepository->findIncludedSteamWorkshopMods($modList); $optionalMods = json_decode($optionalModsJson ?? '', true) ?: []; diff --git a/tests/_support/Helper/Functional.php b/tests/_support/Helper/Functional.php deleted file mode 100644 index eb527c98..00000000 --- a/tests/_support/Helper/Functional.php +++ /dev/null @@ -1,12 +0,0 @@ -freezeTime('2020-01-01T00:00:00+00:00'); + } + + public function downloadModListAsUnauthenticatedUser(FunctionalTester $I): void + { + $optionalMods = [ + AceInteractionMenuExpansionModFixture::ID, + 'invalid', + ]; + + $I->amOnPage(sprintf('/mod-list/%s/download/%s', DefaultModListFixture::NAME, json_encode($optionalMods))); + + $I->seeResponseContainsModListPresetWithMods('ArmaForces Default 2020_01_01 00_00.html', [ + $I->grabEntityFromRepository(Dlc::class, ['id' => CslaIronCurtainDlcFixture::ID]), + $I->grabEntityFromRepository(Dlc::class, ['id' => GlobalMobilizationDlcFixture::ID]), + $I->grabEntityFromRepository(Dlc::class, ['id' => SogPrairieFireDlcFixture::ID]), + $I->grabEntityFromRepository(Dlc::class, ['id' => Spearhead1944DlcFixture::ID]), + ], [ + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => ArmaForcesAceMedicalModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => ArmaForcesMedicalModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => CupTerrainsCoreModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => CupTerrainsMapsModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => CupUnitsModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => CupVehiclesModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => CupWeaponsModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => RhsAfrfModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => RhsGrefModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => RhsUsafModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => LegacyArmaForcesModsModFixture::ID]), + ]); + } + + public function downloadModListAsAuthenticatedUser(FunctionalTester $I): void + { + $I->amDiscordAuthenticatedAs(User1Fixture::ID); + + $optionalMods = [ + AceInteractionMenuExpansionModFixture::ID, + 'invalid', + ]; + + $I->amOnPage(sprintf('/mod-list/%s/download/%s', DefaultModListFixture::NAME, json_encode($optionalMods))); + + $I->seeResponseContainsModListPresetWithMods('ArmaForces Default 2020_01_01 00_00.html', [ + $I->grabEntityFromRepository(Dlc::class, ['id' => CslaIronCurtainDlcFixture::ID]), + $I->grabEntityFromRepository(Dlc::class, ['id' => GlobalMobilizationDlcFixture::ID]), + $I->grabEntityFromRepository(Dlc::class, ['id' => SogPrairieFireDlcFixture::ID]), + $I->grabEntityFromRepository(Dlc::class, ['id' => Spearhead1944DlcFixture::ID]), + ], [ + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => ArmaForcesAceMedicalModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => ArmaForcesMedicalModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => CupTerrainsCoreModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => CupTerrainsMapsModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => CupUnitsModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => CupVehiclesModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => CupWeaponsModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => RhsAfrfModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => RhsGrefModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => RhsUsafModFixture::ID]), + $I->grabEntityFromRepository(SteamWorkshopMod::class, ['id' => LegacyArmaForcesModsModFixture::ID]), + ]); + } + + public function downloadModListAsAuthenticatedUserWhenModListNotDisabled(FunctionalTester $I): void + { + $I->amDiscordAuthenticatedAs(User1Fixture::ID); + + $optionalMods = [ + AceInteractionMenuExpansionModFixture::ID, + 'invalid', + ]; + + $I->amOnPage(sprintf('/mod-list/%s/download/%s', RhsModListFixture::NAME, json_encode($optionalMods))); + + $I->seeResponseCodeIs(HttpCode::FORBIDDEN); + } +} diff --git a/tests/functional/Web/ModListPublic/SelectModListCest.php b/tests/functional/Web/ModListPublic/SelectModListCest.php new file mode 100644 index 00000000..ac4944e9 --- /dev/null +++ b/tests/functional/Web/ModListPublic/SelectModListCest.php @@ -0,0 +1,34 @@ +amOnPage('/mod-list/select'); + + $I->see(DefaultModListFixture::NAME); + $I->see(CupModListFixture::NAME); + $I->dontSee(RhsModListFixture::NAME); // disabled + } + + public function selectModListAsAuthenticatedUser(FunctionalTester $I): void + { + $I->amDiscordAuthenticatedAs(User1Fixture::ID); + + $I->amOnPage('/mod-list/select'); + + $I->see(DefaultModListFixture::NAME); + $I->see(CupModListFixture::NAME); + $I->dontSee(RhsModListFixture::NAME); // disabled + } +}