-
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
29a054c
commit 3209410
Showing
7 changed files
with
598 additions
and
3 deletions.
There are no files selected for viewing
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,221 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Functional\Web\Dlc; | ||
|
||
use App\DataFixtures\User\RegularUserFixture; | ||
use App\Entity\Dlc\Dlc; | ||
use App\Entity\User\User; | ||
use App\Service\SteamApiClient\Helper\SteamHelper; | ||
use App\Tests\FunctionalTester; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class CreateDlcCest | ||
{ | ||
public function _before(FunctionalTester $I): void | ||
{ | ||
$I->stopFollowingRedirects(); | ||
$I->freezeTime('2020-01-01T00:00:00+00:00'); | ||
} | ||
|
||
public function createDlcAsUnauthenticatedUser(FunctionalTester $I): void | ||
{ | ||
$I->amOnPage('/dlc/create'); | ||
$I->seeResponseRedirectsToDiscordAuth(); | ||
} | ||
|
||
public function createDlcAsUnauthorizedUser(FunctionalTester $I): void | ||
{ | ||
$I->amDiscordAuthenticatedAs(RegularUserFixture::ID); | ||
|
||
$I->amOnPage('/dlc/create'); | ||
$I->seeResponseCodeIs(Response::HTTP_FORBIDDEN); | ||
} | ||
|
||
public function createDlcAsAuthorizedUser(FunctionalTester $I): void | ||
{ | ||
$user = $I->amDiscordAuthenticatedAs(RegularUserFixture::ID, function (User $user): void { | ||
$user->getPermissions()->dlcCreate = true; | ||
}); | ||
|
||
$I->amOnPage('/dlc/create'); | ||
|
||
// Default form values | ||
$I->seeInField('Steam Store URL', ''); | ||
$I->seeInField('DLC directory', ''); | ||
$I->seeInField('DLC name', ''); | ||
$I->seeInField('DLC description', ''); | ||
|
||
// Fill form | ||
$I->fillField('Steam Store URL', 'https://store.steampowered.com/app/1681170/Arma_3_Creator_DLC_Western_Sahara'); | ||
$I->fillField('DLC directory', 'ws'); | ||
$I->fillField('DLC name', 'Western Sahara'); | ||
$I->fillField('DLC description', 'Western Sahara Arma 3 DLC'); | ||
$I->click('Create DLC'); | ||
|
||
$I->seeResponseRedirectsTo('/dlc/list'); | ||
|
||
/** @var Dlc $dlc */ | ||
$dlc = $I->grabEntityFromRepository(Dlc::class, ['appId' => 1681170]); | ||
$I->assertSame(1681170, $dlc->getAppId()); | ||
$I->assertSame('ws', $dlc->getDirectory()); | ||
$I->assertSame('Western Sahara', $dlc->getName()); | ||
$I->assertSame('Western Sahara Arma 3 DLC', $dlc->getDescription()); | ||
|
||
$I->assertSame('2020-01-01T00:00:00+00:00', $dlc->getCreatedAt()->format(DATE_ATOM)); | ||
// $I->assertSame($user, $dlc->getCreatedBy()); // FIXME | ||
$I->assertSame(null, $dlc->getLastUpdatedAt()); | ||
$I->assertSame(null, $dlc->getLastUpdatedBy()); | ||
} | ||
|
||
public function createDlcAsAuthorizedUserWithNameProvidedBySteamWorkshop(FunctionalTester $I): void | ||
{ | ||
$user = $I->amDiscordAuthenticatedAs(RegularUserFixture::ID, function (User $user): void { | ||
$user->getPermissions()->dlcCreate = true; | ||
}); | ||
|
||
$I->amOnPage('/dlc/create'); | ||
|
||
// Default form values | ||
$I->seeInField('Steam Store URL', ''); | ||
$I->seeInField('DLC directory', ''); | ||
$I->seeInField('DLC name', ''); | ||
$I->seeInField('DLC description', ''); | ||
|
||
// Fill form | ||
$I->fillField('Steam Store URL', 'https://store.steampowered.com/app/1681170/Arma_3_Creator_DLC_Western_Sahara'); | ||
$I->fillField('DLC directory', 'ws'); | ||
$I->fillField('DLC name', ''); | ||
$I->fillField('DLC description', ''); | ||
$I->click('Create DLC'); | ||
|
||
$I->seeResponseRedirectsTo('/dlc/list'); | ||
|
||
/** @var Dlc $dlc */ | ||
$dlc = $I->grabEntityFromRepository(Dlc::class, ['appId' => 1681170]); | ||
$I->assertSame(1681170, $dlc->getAppId()); | ||
$I->assertSame('ws', $dlc->getDirectory()); | ||
$I->assertSame('Arma 3 Creator DLC: Western Sahara', $dlc->getName()); // From Steam Workshop | ||
$I->assertSame(null, $dlc->getDescription()); | ||
|
||
$I->assertSame('2020-01-01T00:00:00+00:00', $dlc->getCreatedAt()->format(DATE_ATOM)); | ||
// $I->assertSame($user, $dlc->getCreatedBy()); // FIXME | ||
$I->assertSame(null, $dlc->getLastUpdatedAt()); | ||
$I->assertSame(null, $dlc->getLastUpdatedBy()); | ||
} | ||
|
||
public function createDlcAsAuthorizedUserWhenDlcAlreadyExists(FunctionalTester $I): void | ||
{ | ||
$I->amDiscordAuthenticatedAs(RegularUserFixture::ID, function (User $user): void { | ||
$user->getPermissions()->dlcCreate = true; | ||
}); | ||
|
||
$I->amOnPage('/dlc/create'); | ||
|
||
$url = 'https://store.steampowered.com/app/1227700/Arma_3_Creator_DLC_SOG_Prairie_Fire/'; | ||
$I->fillField('Steam Store URL', $url); | ||
$I->fillField('DLC directory', 'vn'); | ||
$I->click('Create DLC'); | ||
|
||
$message = sprintf('DLC associated with url "%s" already exist.', $url); | ||
$I->canSeeFormErrorMessage('url', $message); | ||
$I->canSeeFormErrorMessage('directory', 'DLC associated with directory "vn" already exist.'); | ||
} | ||
|
||
public function createDlcAsAuthorizedUserWithInvalidDlcUrl(FunctionalTester $I): void | ||
{ | ||
$I->amDiscordAuthenticatedAs(RegularUserFixture::ID, function (User $user): void { | ||
$user->getPermissions()->dlcCreate = true; | ||
}); | ||
|
||
$I->amOnPage('/dlc/create'); | ||
|
||
$I->fillField('Steam Store URL', 'https://example.com'); | ||
$I->fillField('DLC directory', 'ws'); | ||
$I->click('Create DLC'); | ||
|
||
$I->canSeeFormErrorMessage('url', 'Invalid Steam Store DLC url.'); | ||
} | ||
|
||
public function createDlcAsAuthorizedUserWhenDlcDoesNotExist(FunctionalTester $I): void | ||
{ | ||
$I->amDiscordAuthenticatedAs(RegularUserFixture::ID, function (User $user): void { | ||
$user->getPermissions()->dlcCreate = true; | ||
}); | ||
|
||
$I->amOnPage('/dlc/create'); | ||
|
||
$url = SteamHelper::appIdToAppUrl(9999999); | ||
$I->fillField('Steam Store URL', $url); | ||
$I->fillField('DLC directory', 'ws'); | ||
$I->click('Create DLC'); | ||
|
||
$I->canSeeFormErrorMessage('url', 'DLC not found.'); | ||
} | ||
|
||
public function createDlcAsAuthorizedUserWhenUrlIsNotAnArma3Dlc(FunctionalTester $I): void | ||
{ | ||
$I->amDiscordAuthenticatedAs(RegularUserFixture::ID, function (User $user): void { | ||
$user->getPermissions()->dlcCreate = true; | ||
}); | ||
|
||
$I->amOnPage('/dlc/create'); | ||
|
||
$url = SteamHelper::appIdToAppUrl(2138330); | ||
$I->fillField('Steam Store URL', $url); | ||
$I->fillField('DLC directory', 'ws'); | ||
$I->click('Create DLC'); | ||
|
||
$I->canSeeFormErrorMessage('url', 'Url is not an Arma 3 DLC.'); | ||
} | ||
|
||
public function createDlcAsAuthorizedUserWithInvalidDirectoryName(FunctionalTester $I): void | ||
{ | ||
$I->amDiscordAuthenticatedAs(RegularUserFixture::ID, function (User $user): void { | ||
$user->getPermissions()->dlcCreate = true; | ||
}); | ||
|
||
$I->amOnPage('/dlc/create'); | ||
|
||
$I->fillField('Steam Store URL', 'https://store.steampowered.com/app/1681170/Arma_3_Creator_DLC_Western_Sahara'); | ||
$I->fillField('DLC directory', 'w/s'); | ||
$I->click('Create DLC'); | ||
|
||
$I->canSeeFormErrorMessage('directory', 'Invalid directory name.'); | ||
} | ||
|
||
public function createDlcAsAuthorizedUserWithoutRequiredData(FunctionalTester $I): void | ||
{ | ||
$I->amDiscordAuthenticatedAs(RegularUserFixture::ID, function (User $user): void { | ||
$user->getPermissions()->dlcCreate = true; | ||
}); | ||
|
||
$I->amOnPage('/dlc/create'); | ||
|
||
$I->fillField('Steam Store URL', ''); | ||
$I->fillField('DLC directory', ''); | ||
$I->click('Create DLC'); | ||
|
||
$I->canSeeFormErrorMessage('url', 'This value should not be blank.'); | ||
$I->canSeeFormErrorMessage('directory', 'This value should not be blank.'); | ||
} | ||
|
||
public function createDlcAsAuthorizedUserWithDataTooLong(FunctionalTester $I): void | ||
{ | ||
$I->amDiscordAuthenticatedAs(RegularUserFixture::ID, function (User $user): void { | ||
$user->getPermissions()->dlcCreate = true; | ||
}); | ||
|
||
$I->amOnPage('/dlc/create'); | ||
|
||
$I->fillField('Steam Store URL', 'https://store.steampowered.com/app/1681170/Arma_3_Creator_DLC_Western_Sahara'); | ||
$I->fillField('DLC directory', 'ws'); | ||
$I->fillField('DLC name', str_repeat('a', 256)); | ||
$I->fillField('DLC description', str_repeat('a', 256)); | ||
$I->click('Create DLC'); | ||
|
||
$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.'); | ||
} | ||
} |
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\Tests\Functional\Web\Dlc; | ||
|
||
use App\DataFixtures\Dlc\SogPrairieFireDlcFixture; | ||
use App\DataFixtures\User\RegularUserFixture; | ||
use App\Entity\Dlc\Dlc; | ||
use App\Entity\User\User; | ||
use App\Tests\FunctionalTester; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class DeleteDlcCest | ||
{ | ||
public function _before(FunctionalTester $I): void | ||
{ | ||
$I->stopFollowingRedirects(); | ||
} | ||
|
||
public function deleteDlcAsUnauthenticatedUser(FunctionalTester $I): void | ||
{ | ||
$id = SogPrairieFireDlcFixture::ID; | ||
$I->amOnPage(sprintf('/dlc/%s/delete', $id)); | ||
$I->seeResponseRedirectsToDiscordAuth(); | ||
|
||
$I->seeInRepository(Dlc::class, ['appId' => SogPrairieFireDlcFixture::APP_ID]); | ||
} | ||
|
||
public function deleteDlcAsUnauthorizedUser(FunctionalTester $I): void | ||
{ | ||
$I->amDiscordAuthenticatedAs(RegularUserFixture::ID); | ||
|
||
$id = SogPrairieFireDlcFixture::ID; | ||
$I->amOnPage(sprintf('/dlc/%s/delete', $id)); | ||
$I->seeResponseCodeIs(Response::HTTP_FORBIDDEN); | ||
|
||
$I->seeInRepository(Dlc::class, ['appId' => SogPrairieFireDlcFixture::APP_ID]); | ||
} | ||
|
||
public function deleteDlcAsAuthorizedUser(FunctionalTester $I): void | ||
{ | ||
$I->amDiscordAuthenticatedAs(RegularUserFixture::ID, function (User $user): void { | ||
$user->getPermissions()->dlcDelete = true; | ||
}); | ||
|
||
$id = SogPrairieFireDlcFixture::ID; | ||
$I->amOnPage(sprintf('/dlc/%s/delete', $id)); | ||
$I->seeResponseRedirectsTo('/dlc/list'); | ||
|
||
$I->dontSeeInRepository(Dlc::class, ['appId' => SogPrairieFireDlcFixture::APP_ID]); | ||
} | ||
} |
Oops, something went wrong.