refactor filter usage
This commit is contained in:
parent
a451c498d6
commit
f78d37cd6e
@ -168,7 +168,7 @@ class PlayerController extends Controller
|
||||
|
||||
$dispatcher->dispatch('player.renaming', [$player, $name]);
|
||||
|
||||
$can = $filter->apply('user_can_rename_player', true, [$player, $name]);
|
||||
$can = $filter->apply('can_rename_player', true, [$player, $name]);
|
||||
if ($can instanceof Rejection) {
|
||||
return json($can->getReason(), 1);
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ class ClosetControllerTest extends TestCase
|
||||
}
|
||||
);
|
||||
Event::assertNotDispatched('closet.added');
|
||||
Fakes\Filter::fake();
|
||||
$filter->remove('can_add_closet_item');
|
||||
|
||||
// the user doesn't have enough score to add a texture
|
||||
$this->user->score = 0;
|
||||
@ -278,10 +278,10 @@ class ClosetControllerTest extends TestCase
|
||||
}
|
||||
);
|
||||
Event::assertNotDispatched('closet.renamed');
|
||||
$filter->remove('can_rename_closet_item');
|
||||
$this->user->closet()->detach($texture->tid);
|
||||
|
||||
// rename a not-existed texture
|
||||
Fakes\Filter::fake();
|
||||
$this->putJson(
|
||||
route('user.closet.rename', ['tid' => -1]),
|
||||
['name' => $name]
|
||||
@ -352,7 +352,7 @@ class ClosetControllerTest extends TestCase
|
||||
$this->deleteJson(route('user.closet.remove', ['tid' => $texture->tid]))
|
||||
->assertJson(['code' => 1, 'message' => 'rejected']);
|
||||
$this->user->closet()->detach($texture->tid);
|
||||
Fakes\Filter::fake();
|
||||
$filter->remove('can_remove_closet_item');
|
||||
|
||||
// should return score if `return_score` is true
|
||||
Event::fake();
|
||||
|
@ -103,10 +103,10 @@ class PlayerControllerTest extends TestCase
|
||||
Event::assertDispatched('player.add.attempt');
|
||||
Event::assertNotDispatched('player.adding');
|
||||
Event::assertNotDispatched('player.added');
|
||||
$filter->remove('can_add_player');
|
||||
|
||||
// Allowed to use CJK characters
|
||||
Event::fake();
|
||||
Fakes\Filter::fake();
|
||||
option(['player_name_rule' => 'cjk']);
|
||||
$user = factory(User::class)->create();
|
||||
$score = $user->score;
|
||||
@ -172,9 +172,9 @@ class PlayerControllerTest extends TestCase
|
||||
$this->actingAs($user)
|
||||
->deleteJson(route('user.player.delete', ['player' => $player]))
|
||||
->assertJson(['code' => 1, 'message' => 'rejected']);
|
||||
$filter->remove('can_delete_player');
|
||||
|
||||
// success
|
||||
$filter = Fakes\Filter::fake();
|
||||
$this->deleteJson(route('user.player.delete', ['player' => $player]))
|
||||
->assertJson([
|
||||
'code' => 0,
|
||||
@ -236,7 +236,6 @@ class PlayerControllerTest extends TestCase
|
||||
public function testRename()
|
||||
{
|
||||
Event::fake();
|
||||
$filter = Fakes\Filter::fake();
|
||||
$player = factory(Player::class)->create();
|
||||
$user = $player->user;
|
||||
|
||||
@ -268,7 +267,7 @@ class PlayerControllerTest extends TestCase
|
||||
|
||||
// Rejected by filter
|
||||
$filter = Fakes\Filter::fake();
|
||||
$filter->add('user_can_rename_player', function ($can, $p, $name) use ($player) {
|
||||
$filter->add('can_rename_player', function ($can, $p, $name) use ($player) {
|
||||
$this->assertTrue($player->is($p));
|
||||
$this->assertEquals('new', $name);
|
||||
|
||||
@ -282,7 +281,7 @@ class PlayerControllerTest extends TestCase
|
||||
'code' => 1,
|
||||
'message' => 'rejected',
|
||||
]);
|
||||
$filter->remove('user_can_rename_player');
|
||||
$filter->remove('can_rename_player');
|
||||
|
||||
// Success
|
||||
Event::fake();
|
||||
|
@ -176,9 +176,8 @@ class SkinlibControllerTest extends TestCase
|
||||
->assertSee('primary')
|
||||
->assertSee('STAFF');
|
||||
$uid = $uploader->uid;
|
||||
resolve(Filter::class)->add('user_badges', function ($badges, $uploader) use ($uid) {
|
||||
$filter->add('user_badges', function ($badges, $uploader) use ($uid) {
|
||||
$this->assertEquals($uid, $uploader->uid);
|
||||
|
||||
$badges[] = ['text' => 'badge-test', 'color' => 'maroon'];
|
||||
|
||||
return $badges;
|
||||
|
Loading…
Reference in New Issue
Block a user