-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10696 from bdach/multiplayer-allowed-mod-validati…
…on-wrong Fix multiplayer score mods not being validated properly when playlist item has no allowed mods
- Loading branch information
Showing
2 changed files
with
172 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
<?php | ||
|
||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Models\Multiplayer; | ||
|
||
use App\Exceptions\InvariantException; | ||
use App\Models\Multiplayer\PlaylistItem; | ||
use App\Models\Multiplayer\ScoreLink; | ||
use App\Models\User; | ||
use Carbon\Carbon; | ||
use Tests\TestCase; | ||
|
||
class ScoreLinkTest extends TestCase | ||
{ | ||
public function testRequiredModsMissing() | ||
{ | ||
$user = User::factory()->create(); | ||
$playlistItem = PlaylistItem::factory()->create([ | ||
'required_mods' => [[ | ||
'acronym' => 'HD', | ||
]], | ||
]); | ||
$scoreLink = ScoreLink::factory()->make([ | ||
'score_id' => null, | ||
'user_id' => $user, | ||
'playlist_item_id' => $playlistItem, | ||
]); | ||
|
||
$this->expectException(InvariantException::class); | ||
$this->expectExceptionMessage('This play does not include the mods required.'); | ||
$scoreLink->complete([ | ||
'beatmap_id' => $playlistItem->beatmap_id, | ||
'ruleset_id' => $playlistItem->ruleset_id, | ||
'user_id' => $user->getKey(), | ||
'ended_at' => json_date(Carbon::now()), | ||
'mods' => [], | ||
'statistics' => [ | ||
'great' => 1, | ||
], | ||
]); | ||
} | ||
|
||
public function testRequiredModsPresent() | ||
{ | ||
$user = User::factory()->create(); | ||
$playlistItem = PlaylistItem::factory()->create([ | ||
'required_mods' => [[ | ||
'acronym' => 'HD', | ||
]], | ||
]); | ||
$scoreLink = ScoreLink::factory()->make([ | ||
'score_id' => null, | ||
'user_id' => $user, | ||
'playlist_item_id' => $playlistItem, | ||
]); | ||
|
||
$this->expectNotToPerformAssertions(); | ||
$scoreLink->complete([ | ||
'beatmap_id' => $playlistItem->beatmap_id, | ||
'ruleset_id' => $playlistItem->ruleset_id, | ||
'user_id' => $user->getKey(), | ||
'ended_at' => json_date(Carbon::now()), | ||
'mods' => [['acronym' => 'HD']], | ||
'statistics' => [ | ||
'great' => 1, | ||
], | ||
]); | ||
} | ||
|
||
public function testExpectedAllowedMod() | ||
{ | ||
$user = User::factory()->create(); | ||
$playlistItem = PlaylistItem::factory()->create([ | ||
'required_mods' => [[ | ||
'acronym' => 'DT', | ||
]], | ||
'allowed_mods' => [[ | ||
'acronym' => 'HD', | ||
]], | ||
]); | ||
$scoreLink = ScoreLink::factory()->make([ | ||
'score_id' => null, | ||
'user_id' => $user, | ||
'playlist_item_id' => $playlistItem, | ||
]); | ||
|
||
$this->expectNotToPerformAssertions(); | ||
$scoreLink->complete([ | ||
'beatmap_id' => $playlistItem->beatmap_id, | ||
'ruleset_id' => $playlistItem->ruleset_id, | ||
'user_id' => $user->getKey(), | ||
'ended_at' => json_date(Carbon::now()), | ||
'mods' => [ | ||
['acronym' => 'DT'], | ||
['acronym' => 'HD'], | ||
], | ||
'statistics' => [ | ||
'great' => 1, | ||
], | ||
]); | ||
} | ||
|
||
public function testUnexpectedAllowedMod() | ||
{ | ||
$user = User::factory()->create(); | ||
$playlistItem = PlaylistItem::factory()->create([ | ||
'required_mods' => [[ | ||
'acronym' => 'DT', | ||
]], | ||
'allowed_mods' => [[ | ||
'acronym' => 'HR', | ||
]], | ||
]); | ||
$scoreLink = ScoreLink::factory()->make([ | ||
'score_id' => null, | ||
'user_id' => $user, | ||
'playlist_item_id' => $playlistItem, | ||
]); | ||
|
||
$this->expectException(InvariantException::class); | ||
$this->expectExceptionMessage('This play includes mods that are not allowed.'); | ||
$scoreLink->complete([ | ||
'beatmap_id' => $playlistItem->beatmap_id, | ||
'ruleset_id' => $playlistItem->ruleset_id, | ||
'user_id' => $user->getKey(), | ||
'ended_at' => json_date(Carbon::now()), | ||
'mods' => [ | ||
['acronym' => 'DT'], | ||
['acronym' => 'HD'], | ||
], | ||
'statistics' => [ | ||
'great' => 1, | ||
], | ||
]); | ||
} | ||
|
||
public function testUnexpectedModWhenNoModsAreAllowed() | ||
{ | ||
$user = User::factory()->create(); | ||
$playlistItem = PlaylistItem::factory()->create(); // no required or allowed mods. | ||
$scoreLink = ScoreLink::factory()->make([ | ||
'score_id' => null, | ||
'user_id' => $user, | ||
'playlist_item_id' => $playlistItem, | ||
]); | ||
|
||
$this->expectException(InvariantException::class); | ||
$this->expectExceptionMessage('This play includes mods that are not allowed.'); | ||
$scoreLink->complete([ | ||
'beatmap_id' => $playlistItem->beatmap_id, | ||
'ruleset_id' => $playlistItem->ruleset_id, | ||
'user_id' => $user->getKey(), | ||
'ended_at' => json_date(Carbon::now()), | ||
'mods' => [['acronym' => 'HD']], | ||
'statistics' => [ | ||
'great' => 1, | ||
], | ||
]); | ||
} | ||
} |