-
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
52dd192
commit 8018da0
Showing
17 changed files
with
294 additions
and
125 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Traits; | ||
|
||
trait DataTableAssertsTrait | ||
{ | ||
public function seeActionButton(string $tooltip, string $url = null): void | ||
{ | ||
$selector = sprintf('a i[title="%s"]', $tooltip); | ||
if ($url) { | ||
$selector = sprintf('a[href="%s"] i[title="%s"]', $url, $tooltip); | ||
} | ||
$this->seeElement($selector); | ||
} | ||
|
||
public function dontSeeActionButton(string $tooltip, string $url = null): void | ||
{ | ||
$selector = sprintf('a i[title="%s"]', $tooltip); | ||
if ($url) { | ||
$selector = sprintf('a[href="%s"] i[title="%s"]', $url, $tooltip); | ||
} | ||
$this->dontSeeElement($selector); | ||
} | ||
|
||
public function checkTableRowCheckbox(string $value): void | ||
{ | ||
$this->checkOption(sprintf('[value="%s"]', $value)); | ||
} | ||
|
||
public function uncheckTableRowCheckbox(string $value): void | ||
{ | ||
$this->uncheckOption(sprintf('[value="%s"]', $value)); | ||
} | ||
|
||
public function seeTableRowCheckboxesAreChecked(array $values = []): void | ||
{ | ||
$valueSelector = array_map(fn (string $value) => sprintf('[value="%s"]', $value), $values); | ||
$checkboxSelector = implode(', ', $valueSelector); | ||
|
||
$this->seeCheckboxIsChecked($checkboxSelector); | ||
} | ||
|
||
public function seeTableRowCheckboxesAreUnchecked(string $idPrefix, array $valuesToExclude = []): void | ||
{ | ||
$checkboxSelector = sprintf('[id^="%s"]', $idPrefix); | ||
if ($valuesToExclude) { | ||
$valueSelector = array_map(fn (string $value) => sprintf(':not([value^="%s"])', $value), $valuesToExclude); | ||
$checkboxSelector .= implode('', $valueSelector); | ||
} | ||
|
||
$this->dontSeeCheckboxIsChecked($checkboxSelector); | ||
} | ||
} |
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,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Traits; | ||
|
||
use App\Entity\Dlc\Dlc; | ||
use App\Entity\Mod\SteamWorkshopMod; | ||
use Symfony\Component\DomCrawler\Crawler; | ||
|
||
trait ResponseAssertTrait | ||
{ | ||
public function seeResponseRedirectsTo(string $url): void | ||
{ | ||
$this->seeResponseCodeIsRedirection(); | ||
$this->seeHttpHeader('Location', $url); | ||
} | ||
|
||
public function seeResponseRedirectsToLogInAction(): void | ||
{ | ||
$this->seeResponseRedirectsTo('/security/connect/discord'); | ||
} | ||
|
||
public function seeResponseRedirectsToDiscordOauth(): void | ||
{ | ||
$this->seeResponseCodeIsRedirection(); | ||
$redirect = $this->grabHttpHeader('Location'); | ||
$this->assertTrue(str_starts_with($redirect, 'https://discord.com/oauth2/authorize')); | ||
} | ||
|
||
public function seeResponseContainsModListPresetWithMods( | ||
string $fileName, | ||
array $expectedDlcs, | ||
array $expectedMods, | ||
): void { | ||
$extractSteamWorkshopItems = function (Crawler $crawler, string $containerName) { | ||
$containerSelector = sprintf('[data-type="%s"]', $containerName); | ||
$containerCrawler = $crawler->filter($containerSelector); | ||
|
||
return array_map(static function (\DOMNode $steamWorkshopItemNode) { | ||
$steamWorkshopItemNodeCrawler = (new Crawler($steamWorkshopItemNode)); | ||
|
||
return [ | ||
'name' => $steamWorkshopItemNodeCrawler->filter('[data-type="DisplayName"]')->html(), | ||
'url' => $steamWorkshopItemNodeCrawler->filter('[data-type="Link"]')->attr('href'), | ||
]; | ||
}, iterator_to_array($containerCrawler->getIterator())); | ||
}; | ||
|
||
$this->seeHttpHeader('Content-Disposition', sprintf('attachment; filename="%s"', $fileName)); | ||
|
||
$crawler = new Crawler($this->grabResponse()); | ||
$includedDlcs = $extractSteamWorkshopItems($crawler, 'DlcContainer'); | ||
$includedMods = $extractSteamWorkshopItems($crawler, 'ModContainer'); | ||
|
||
$expectedDlcs = array_map(static function (Dlc $dlc) { | ||
return [ | ||
'name' => $dlc->getName(), | ||
'url' => "https://store.steampowered.com/app/{$dlc->getAppId()}", | ||
]; | ||
}, $expectedDlcs); | ||
|
||
$expectedMods = array_map(static function (SteamWorkshopMod $steamWorkshopMod) { | ||
return [ | ||
'name' => $steamWorkshopMod->getName(), | ||
'url' => "https://steamcommunity.com/sharedfiles/filedetails/?id={$steamWorkshopMod->getItemId()}", | ||
]; | ||
}, $expectedMods); | ||
|
||
$this->assertSame($expectedDlcs, $includedDlcs); | ||
$this->assertSame($expectedMods, $includedMods); | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Traits; | ||
|
||
use App\Entity\User\User; | ||
|
||
trait SecurityAssertsTrait | ||
{ | ||
public function amDiscordAuthenticatedAs(string $id, callable $preAuthCallback = null): User | ||
{ | ||
/** @var User $user */ | ||
$user = $this->grabEntityFromRepository(User::class, ['id' => $id]); | ||
if ($preAuthCallback) { | ||
$preAuthCallback($user); | ||
|
||
// Refresh user entity to avoid permission issues in subsequent requests | ||
$this->haveInRepository($user); | ||
} | ||
$this->amLoggedInAs($user); | ||
|
||
return $user; | ||
} | ||
|
||
public function amApiKeyAuthenticatedAs(string $id, callable $preAuthCallback = null): User | ||
{ | ||
/** @var User $user */ | ||
$user = $this->grabEntityFromRepository(User::class, ['id' => $id]); | ||
if ($preAuthCallback) { | ||
$preAuthCallback($user); | ||
|
||
// Refresh user entity to avoid permission issues in subsequent requests | ||
$this->haveInRepository($user); | ||
} | ||
$this->amLoggedInAs($user); | ||
|
||
return $user; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -14,4 +14,3 @@ modules: | |
url: / | ||
depends: Symfony | ||
- Asserts | ||
- \App\Tests\Helper\Functional |
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Functional\Web\ModListPublic; | ||
|
||
class CustomizeModListCest | ||
{ | ||
} |
Oops, something went wrong.