From 2fc13eb1ed3e86ffc98ee23a3e7f2e482488d489 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 +- .../_partial/_optional_mods_tab.html.twig | 4 +- tests/_support/Helper/Functional.php | 12 -- .../ModListPublic/CustomizeModListCest.php | 54 +++++++++ .../Web/ModListPublic/DownloadModListCest.php | 111 ++++++++++++++++++ .../Web/ModListPublic/SelectModListCest.php | 34 ++++++ 6 files changed, 204 insertions(+), 15 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/templates/mod_list_public/_partial/_optional_mods_tab.html.twig b/templates/mod_list_public/_partial/_optional_mods_tab.html.twig index 55f9d104..5fdee2bb 100644 --- a/templates/mod_list_public/_partial/_optional_mods_tab.html.twig +++ b/templates/mod_list_public/_partial/_optional_mods_tab.html.twig @@ -23,10 +23,10 @@ {{ tableMacro.row_mod_status_icon(mod) }} {{ tableMacro.row_name_with_description(mod.name, mod.description) }} - {% set modEntryId = 'mod-' ~ mod.id %} + {% set modEntryId = 'optional-mod-' ~ mod.id %}
- +
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 customizeModListAsUnauthenticatedUser(FunctionalTester $I): void + { + $I->amOnPage(sprintf('/mod-list/%s', DefaultModListFixture::NAME)); + + $I->seeResponseCodeIs(HttpCode::OK); + + $I->seeTableRowCheckboxesAreUnchecked('optional-mod-'); // All checkboxes are unchecked + + $I->seeLink('Download'); + $I->seeLink('Download required'); + } + + public function customizeModListAsAuthenticatedUser(FunctionalTester $I): void + { + $I->amDiscordAuthenticatedAs(User1Fixture::ID); + + $I->amOnPage(sprintf('/mod-list/%s', DefaultModListFixture::NAME)); + + $I->seeResponseCodeIs(HttpCode::OK); + + $I->seeTableRowCheckboxesAreUnchecked('optional-mod-'); // All checkboxes are unchecked + + $I->seeLink('Download'); + $I->seeLink('Download required'); + } + + public function customizeModListAsAuthenticatedUserWhenModListInactive(FunctionalTester $I): void + { + $I->amDiscordAuthenticatedAs(User1Fixture::ID); + + $I->amOnPage(sprintf('/mod-list/%s', RhsModListFixture::NAME)); + + $I->seeResponseCodeIs(HttpCode::FORBIDDEN); + } +} diff --git a/tests/functional/Web/ModListPublic/DownloadModListCest.php b/tests/functional/Web/ModListPublic/DownloadModListCest.php new file mode 100644 index 00000000..226e4c34 --- /dev/null +++ b/tests/functional/Web/ModListPublic/DownloadModListCest.php @@ -0,0 +1,111 @@ +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 downloadModListAsAuthenticatedUserWhenModListInactive(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 + } +}