From 146c12f26e50723d260563fb865f46317fc8af1c Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Tue, 17 Sep 2019 23:57:29 +0800 Subject: [PATCH] Restructure tests --- .../AdminFormsTest.php} | 2 +- .../ControllersTest}/AdminControllerTest.php | 0 .../ControllersTest}/AuthControllerTest.php | 0 .../ControllersTest}/ClosetControllerTest.php | 0 .../ControllersTest}/HomeControllerTest.php | 0 .../ControllersTest}/MarketControllerTest.php | 0 .../ControllersTest}/PlayerControllerTest.php | 0 .../ControllersTest}/PluginControllerTest.php | 0 .../ControllersTest}/ReportControllerTest.php | 0 .../ControllersTest}/SetupControllerTest.php | 0 .../SkinlibControllerTest.php | 0 .../TextureControllerTest.php | 0 .../TranslationsControllerTest.php | 0 .../ControllersTest}/UpdateControllerTest.php | 0 .../ControllersTest}/UserControllerTest.php | 0 .../MiddlewareTest/AuthenticateTest.php | 16 ++ .../MiddlewareTest/CheckAdministratorTest.php | 29 ++ .../MiddlewareTest/CheckInstallationTest.php | 40 +++ .../MiddlewareTest/CheckPlayerExistTest.php | 45 ++++ .../MiddlewareTest/CheckPlayerOwnerTest.php | 30 +++ .../MiddlewareTest/CheckSuperAdminTest.php | 21 ++ .../MiddlewareTest/CheckUserVerifiedTest.php | 38 +++ .../MiddlewareTest/EnsureEmailFilledTest.php | 17 ++ .../FireUserAuthenticatedTest.php | 21 ++ .../MiddlewareTest/ForbiddenIETest.php | 12 + .../RedirectIfAuthenticatedTest.php | 19 ++ .../MiddlewareTest/RedirectToSetupTest.php | 36 +++ .../MiddlewareTest/RejectBannedUserTest.php | 17 ++ .../MiddlewareTest/RequireBindPlayerTest.php | 30 +++ tests/MiddlewareTest.php | 247 ------------------ 30 files changed, 372 insertions(+), 248 deletions(-) rename tests/{AdminConfigurationsTest.php => BrowserKitTests/AdminFormsTest.php} (99%) rename tests/{ => HttpTest/ControllersTest}/AdminControllerTest.php (100%) rename tests/{ => HttpTest/ControllersTest}/AuthControllerTest.php (100%) rename tests/{ => HttpTest/ControllersTest}/ClosetControllerTest.php (100%) rename tests/{ => HttpTest/ControllersTest}/HomeControllerTest.php (100%) rename tests/{ => HttpTest/ControllersTest}/MarketControllerTest.php (100%) rename tests/{ => HttpTest/ControllersTest}/PlayerControllerTest.php (100%) rename tests/{ => HttpTest/ControllersTest}/PluginControllerTest.php (100%) rename tests/{ => HttpTest/ControllersTest}/ReportControllerTest.php (100%) rename tests/{ => HttpTest/ControllersTest}/SetupControllerTest.php (100%) rename tests/{ => HttpTest/ControllersTest}/SkinlibControllerTest.php (100%) rename tests/{ => HttpTest/ControllersTest}/TextureControllerTest.php (100%) rename tests/{ => HttpTest/ControllersTest}/TranslationsControllerTest.php (100%) rename tests/{ => HttpTest/ControllersTest}/UpdateControllerTest.php (100%) rename tests/{ => HttpTest/ControllersTest}/UserControllerTest.php (100%) create mode 100644 tests/HttpTest/MiddlewareTest/AuthenticateTest.php create mode 100644 tests/HttpTest/MiddlewareTest/CheckAdministratorTest.php create mode 100644 tests/HttpTest/MiddlewareTest/CheckInstallationTest.php create mode 100644 tests/HttpTest/MiddlewareTest/CheckPlayerExistTest.php create mode 100644 tests/HttpTest/MiddlewareTest/CheckPlayerOwnerTest.php create mode 100644 tests/HttpTest/MiddlewareTest/CheckSuperAdminTest.php create mode 100644 tests/HttpTest/MiddlewareTest/CheckUserVerifiedTest.php create mode 100644 tests/HttpTest/MiddlewareTest/EnsureEmailFilledTest.php create mode 100644 tests/HttpTest/MiddlewareTest/FireUserAuthenticatedTest.php create mode 100644 tests/HttpTest/MiddlewareTest/ForbiddenIETest.php create mode 100644 tests/HttpTest/MiddlewareTest/RedirectIfAuthenticatedTest.php create mode 100644 tests/HttpTest/MiddlewareTest/RedirectToSetupTest.php create mode 100644 tests/HttpTest/MiddlewareTest/RejectBannedUserTest.php create mode 100644 tests/HttpTest/MiddlewareTest/RequireBindPlayerTest.php delete mode 100644 tests/MiddlewareTest.php diff --git a/tests/AdminConfigurationsTest.php b/tests/BrowserKitTests/AdminFormsTest.php similarity index 99% rename from tests/AdminConfigurationsTest.php rename to tests/BrowserKitTests/AdminFormsTest.php index e2b0be39..b78569c2 100644 --- a/tests/AdminConfigurationsTest.php +++ b/tests/BrowserKitTests/AdminFormsTest.php @@ -8,7 +8,7 @@ use Illuminate\Support\Facades\Redis; use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\DatabaseTransactions; -class AdminConfigurationsTest extends BrowserKitTestCase +class AdminFormsTest extends BrowserKitTestCase { use DatabaseTransactions; diff --git a/tests/AdminControllerTest.php b/tests/HttpTest/ControllersTest/AdminControllerTest.php similarity index 100% rename from tests/AdminControllerTest.php rename to tests/HttpTest/ControllersTest/AdminControllerTest.php diff --git a/tests/AuthControllerTest.php b/tests/HttpTest/ControllersTest/AuthControllerTest.php similarity index 100% rename from tests/AuthControllerTest.php rename to tests/HttpTest/ControllersTest/AuthControllerTest.php diff --git a/tests/ClosetControllerTest.php b/tests/HttpTest/ControllersTest/ClosetControllerTest.php similarity index 100% rename from tests/ClosetControllerTest.php rename to tests/HttpTest/ControllersTest/ClosetControllerTest.php diff --git a/tests/HomeControllerTest.php b/tests/HttpTest/ControllersTest/HomeControllerTest.php similarity index 100% rename from tests/HomeControllerTest.php rename to tests/HttpTest/ControllersTest/HomeControllerTest.php diff --git a/tests/MarketControllerTest.php b/tests/HttpTest/ControllersTest/MarketControllerTest.php similarity index 100% rename from tests/MarketControllerTest.php rename to tests/HttpTest/ControllersTest/MarketControllerTest.php diff --git a/tests/PlayerControllerTest.php b/tests/HttpTest/ControllersTest/PlayerControllerTest.php similarity index 100% rename from tests/PlayerControllerTest.php rename to tests/HttpTest/ControllersTest/PlayerControllerTest.php diff --git a/tests/PluginControllerTest.php b/tests/HttpTest/ControllersTest/PluginControllerTest.php similarity index 100% rename from tests/PluginControllerTest.php rename to tests/HttpTest/ControllersTest/PluginControllerTest.php diff --git a/tests/ReportControllerTest.php b/tests/HttpTest/ControllersTest/ReportControllerTest.php similarity index 100% rename from tests/ReportControllerTest.php rename to tests/HttpTest/ControllersTest/ReportControllerTest.php diff --git a/tests/SetupControllerTest.php b/tests/HttpTest/ControllersTest/SetupControllerTest.php similarity index 100% rename from tests/SetupControllerTest.php rename to tests/HttpTest/ControllersTest/SetupControllerTest.php diff --git a/tests/SkinlibControllerTest.php b/tests/HttpTest/ControllersTest/SkinlibControllerTest.php similarity index 100% rename from tests/SkinlibControllerTest.php rename to tests/HttpTest/ControllersTest/SkinlibControllerTest.php diff --git a/tests/TextureControllerTest.php b/tests/HttpTest/ControllersTest/TextureControllerTest.php similarity index 100% rename from tests/TextureControllerTest.php rename to tests/HttpTest/ControllersTest/TextureControllerTest.php diff --git a/tests/TranslationsControllerTest.php b/tests/HttpTest/ControllersTest/TranslationsControllerTest.php similarity index 100% rename from tests/TranslationsControllerTest.php rename to tests/HttpTest/ControllersTest/TranslationsControllerTest.php diff --git a/tests/UpdateControllerTest.php b/tests/HttpTest/ControllersTest/UpdateControllerTest.php similarity index 100% rename from tests/UpdateControllerTest.php rename to tests/HttpTest/ControllersTest/UpdateControllerTest.php diff --git a/tests/UserControllerTest.php b/tests/HttpTest/ControllersTest/UserControllerTest.php similarity index 100% rename from tests/UserControllerTest.php rename to tests/HttpTest/ControllersTest/UserControllerTest.php diff --git a/tests/HttpTest/MiddlewareTest/AuthenticateTest.php b/tests/HttpTest/MiddlewareTest/AuthenticateTest.php new file mode 100644 index 00000000..d97a733b --- /dev/null +++ b/tests/HttpTest/MiddlewareTest/AuthenticateTest.php @@ -0,0 +1,16 @@ +get('/user')->assertRedirect('auth/login'); + + $user = factory(User::class)->make(); + $this->actingAs($user)->assertAuthenticated(); + } +} diff --git a/tests/HttpTest/MiddlewareTest/CheckAdministratorTest.php b/tests/HttpTest/MiddlewareTest/CheckAdministratorTest.php new file mode 100644 index 00000000..d7ad0184 --- /dev/null +++ b/tests/HttpTest/MiddlewareTest/CheckAdministratorTest.php @@ -0,0 +1,29 @@ +get('/admin')->assertRedirect('/auth/login'); + + // Normal user + $this->actingAs(factory(User::class)->make()) + ->get('/admin') + ->assertStatus(403); + + // Admin + $this->actingAs(factory(User::class, 'admin')->make()) + ->get('/admin') + ->assertSuccessful(); + + // Super admin + $this->actingAs(factory(User::class, 'superAdmin')->make()) + ->get('/admin') + ->assertSuccessful(); + } +} diff --git a/tests/HttpTest/MiddlewareTest/CheckInstallationTest.php b/tests/HttpTest/MiddlewareTest/CheckInstallationTest.php new file mode 100644 index 00000000..c63c9107 --- /dev/null +++ b/tests/HttpTest/MiddlewareTest/CheckInstallationTest.php @@ -0,0 +1,40 @@ +get('/setup')->assertSee('Already installed'); + + $this->mock(Filesystem::class, function ($mock) { + $mock->shouldReceive('exists') + ->with(storage_path('install.lock')) + ->twice() + ->andReturn(false); + $mock->shouldReceive('exists') + ->with(base_path('.env')) + ->andReturn(true); + }); + $this->get('/setup')->assertSee(trans( + 'setup.wizard.welcome.text', + ['version' => config('app.version')] + )); + + $this->actingAs(factory(User::class, 'superAdmin')->make()); + $this->mock(Filesystem::class, function ($mock) { + $mock->shouldReceive('exists') + ->with(storage_path('install.lock')) + ->andReturn(true); + }); + config(['app.version' => '100.0.0']); + $this->get('/setup/update')->assertSee(trans('setup.updates.welcome.title')); + } +} diff --git a/tests/HttpTest/MiddlewareTest/CheckPlayerExistTest.php b/tests/HttpTest/MiddlewareTest/CheckPlayerExistTest.php new file mode 100644 index 00000000..bbbfd04b --- /dev/null +++ b/tests/HttpTest/MiddlewareTest/CheckPlayerExistTest.php @@ -0,0 +1,45 @@ +getJson('/nope.json') + ->assertStatus(404) + ->assertSee(trans('general.unexistent-player')); + + $this->get('/skin/nope.png') + ->assertStatus(404) + ->assertSee(trans('general.unexistent-player')); + + option(['return_204_when_notfound' => true]); + $this->getJson('/nope.json')->assertStatus(204); + + $player = factory(Player::class)->create(); + $this->getJson("/{$player->name}.json") + ->assertJson(['username' => $player->name]); // Default is CSL API + + $this->getJson("/{$player->name}.json"); + Event::assertDispatched(\App\Events\CheckPlayerExists::class); + + $player = factory(Player::class)->create(); + $user = $player->user; + $this->actingAs($user) + ->postJson('/user/player/rename/-1', ['name' => 'name']) + ->assertJson([ + 'code' => 1, + 'message' => trans('general.unexistent-player'), + ]); + } +} diff --git a/tests/HttpTest/MiddlewareTest/CheckPlayerOwnerTest.php b/tests/HttpTest/MiddlewareTest/CheckPlayerOwnerTest.php new file mode 100644 index 00000000..1ea49a36 --- /dev/null +++ b/tests/HttpTest/MiddlewareTest/CheckPlayerOwnerTest.php @@ -0,0 +1,30 @@ +create(); + $player = factory(Player::class)->create(); + $owner = $player->user; + + $this->actingAs($other_user) + ->get('/user/player') + ->assertSuccessful(); + + $this->actingAs($other_user) + ->postJson('/user/player/rename/'.$player->pid) + ->assertJson([ + 'code' => 1, + 'message' => trans('admin.players.no-permission'), + ]); + } +} diff --git a/tests/HttpTest/MiddlewareTest/CheckSuperAdminTest.php b/tests/HttpTest/MiddlewareTest/CheckSuperAdminTest.php new file mode 100644 index 00000000..f7126e89 --- /dev/null +++ b/tests/HttpTest/MiddlewareTest/CheckSuperAdminTest.php @@ -0,0 +1,21 @@ +actAs(factory(User::class, 'admin')->make()) + ->get('/admin/plugins/manage') + ->assertForbidden(); + + // Super admin + $this->actAs(factory(User::class, 'superAdmin')->make()) + ->get('/admin/plugins/manage') + ->assertSuccessful(); + } +} diff --git a/tests/HttpTest/MiddlewareTest/CheckUserVerifiedTest.php b/tests/HttpTest/MiddlewareTest/CheckUserVerifiedTest.php new file mode 100644 index 00000000..e4b58267 --- /dev/null +++ b/tests/HttpTest/MiddlewareTest/CheckUserVerifiedTest.php @@ -0,0 +1,38 @@ +create(['verified' => false]); + + option(['require_verification' => false]); + $this->actingAs($unverified) + ->get('/skinlib/upload') + ->assertSuccessful(); + + option(['require_verification' => true]); + $this->actingAs($unverified) + ->get('/skinlib/upload') + ->assertStatus(403) + ->assertSee(trans('auth.check.verified')); + + $this->actAs('normal') + ->get('/skinlib/upload') + ->assertSuccessful(); + + $user = factory(User::class)->create(['verified' => false]); + $this->actingAs($user)->get('/user/oauth/manage')->assertForbidden(); + $this->getJson('/oauth/clients')->assertForbidden(); + $user->verified = true; + $user->save(); + $this->getJson('/oauth/clients')->assertSuccessful(); + } +} diff --git a/tests/HttpTest/MiddlewareTest/EnsureEmailFilledTest.php b/tests/HttpTest/MiddlewareTest/EnsureEmailFilledTest.php new file mode 100644 index 00000000..ce5fdebf --- /dev/null +++ b/tests/HttpTest/MiddlewareTest/EnsureEmailFilledTest.php @@ -0,0 +1,17 @@ +make(['email' => '']); + $this->actingAs($noEmailUser)->get('/user')->assertRedirect('/auth/bind'); + + $normalUser = factory(User::class)->make(); + $this->actingAs($normalUser)->get('/auth/bind')->assertRedirect('/user'); + } +} diff --git a/tests/HttpTest/MiddlewareTest/FireUserAuthenticatedTest.php b/tests/HttpTest/MiddlewareTest/FireUserAuthenticatedTest.php new file mode 100644 index 00000000..52f0cc65 --- /dev/null +++ b/tests/HttpTest/MiddlewareTest/FireUserAuthenticatedTest.php @@ -0,0 +1,21 @@ +make(); + $this->actingAs($user)->get('/user'); + Event::assertDispatched(\App\Events\UserAuthenticated::class, function ($event) use ($user) { + $this->assertEquals($user->uid, $event->user->uid); + + return true; + }); + } +} diff --git a/tests/HttpTest/MiddlewareTest/ForbiddenIETest.php b/tests/HttpTest/MiddlewareTest/ForbiddenIETest.php new file mode 100644 index 00000000..443f0497 --- /dev/null +++ b/tests/HttpTest/MiddlewareTest/ForbiddenIETest.php @@ -0,0 +1,12 @@ +get('/', ['user-agent' => 'MSIE'])->assertSee(trans('errors.http.ie')); + $this->get('/', ['user-agent' => 'Trident'])->assertSee(trans('errors.http.ie')); + } +} diff --git a/tests/HttpTest/MiddlewareTest/RedirectIfAuthenticatedTest.php b/tests/HttpTest/MiddlewareTest/RedirectIfAuthenticatedTest.php new file mode 100644 index 00000000..2d06bba0 --- /dev/null +++ b/tests/HttpTest/MiddlewareTest/RedirectIfAuthenticatedTest.php @@ -0,0 +1,19 @@ +get('/auth/login') + ->assertViewIs('auth.login') + ->assertDontSee(trans('general.user-center')); + + $this->actingAs(factory(User::class)->make()) + ->get('/auth/login') + ->assertRedirect('/user'); + } +} diff --git a/tests/HttpTest/MiddlewareTest/RedirectToSetupTest.php b/tests/HttpTest/MiddlewareTest/RedirectToSetupTest.php new file mode 100644 index 00000000..ddbd5627 --- /dev/null +++ b/tests/HttpTest/MiddlewareTest/RedirectToSetupTest.php @@ -0,0 +1,36 @@ +make(); + + $current = config('app.version'); + config(['app.version' => '100.0.0']); + $this->get('/')->assertStatus(503); + $this->actingAs($superAdmin)->get('/')->assertRedirect('/setup/update'); + config(['app.version' => $current]); + + $this->mock(Filesystem::class, function ($mock) { + $mock->shouldReceive('exists') + ->with(storage_path('install.lock')) + ->andReturn(true, false, false); + + $mock->shouldReceive('exists') + ->with(base_path('.env')) + ->andReturn(true); + }); + $this->get('/')->assertViewIs('index'); + $this->get('/setup')->assertViewIs('setup.wizard.welcome'); + $this->get('/')->assertRedirect('/setup'); + } +} diff --git a/tests/HttpTest/MiddlewareTest/RejectBannedUserTest.php b/tests/HttpTest/MiddlewareTest/RejectBannedUserTest.php new file mode 100644 index 00000000..edd6691b --- /dev/null +++ b/tests/HttpTest/MiddlewareTest/RejectBannedUserTest.php @@ -0,0 +1,17 @@ +make(); + $this->actingAs($user)->get('/user')->assertForbidden(); + $this->get('/user', ['accept' => 'application/json']) + ->assertForbidden() + ->assertJson(['code' => -1, 'message' => trans('auth.check.banned')]); + } +} diff --git a/tests/HttpTest/MiddlewareTest/RequireBindPlayerTest.php b/tests/HttpTest/MiddlewareTest/RequireBindPlayerTest.php new file mode 100644 index 00000000..7a5159f1 --- /dev/null +++ b/tests/HttpTest/MiddlewareTest/RequireBindPlayerTest.php @@ -0,0 +1,30 @@ +create(); + $this->actingAs($user)->get('/user')->assertViewIs('user.index'); + $this->get('/user/player/bind')->assertRedirect('/user'); + + option(['single_player' => true]); + + $this->getJson('/user/player/list')->assertHeader('content-type', 'application/json'); + + $this->get('/user/player/bind')->assertViewIs('user.bind'); + $this->get('/user')->assertRedirect('/user/player/bind'); + + factory(Player::class)->create(['uid' => $user->uid]); + $this->get('/user')->assertViewIs('user.index'); + $this->get('/user/player/bind')->assertRedirect('/user'); + } +} diff --git a/tests/MiddlewareTest.php b/tests/MiddlewareTest.php deleted file mode 100644 index 17e74abd..00000000 --- a/tests/MiddlewareTest.php +++ /dev/null @@ -1,247 +0,0 @@ -get('/user')->assertRedirect('auth/login'); - $this->actAs('normal')->assertAuthenticated(); - } - - public function testCheckUserVerified() - { - $unverified = factory(User::class)->create(['verified' => false]); - - option(['require_verification' => false]); - $this->actingAs($unverified) - ->get('/skinlib/upload') - ->assertSuccessful(); - - option(['require_verification' => true]); - $this->actingAs($unverified) - ->get('/skinlib/upload') - ->assertStatus(403) - ->assertSee(trans('auth.check.verified')); - - $this->actAs('normal') - ->get('/skinlib/upload') - ->assertSuccessful(); - - $user = factory(User::class)->create(['verified' => false]); - $this->actingAs($user)->get('/user/oauth/manage')->assertForbidden(); - $this->getJson('/oauth/clients')->assertForbidden(); - $user->verified = true; - $user->save(); - $this->getJson('/oauth/clients')->assertSuccessful(); - } - - public function testCheckAdministrator() - { - // Without logged in - $this->get('/admin')->assertRedirect('/auth/login'); - - // Normal user - $this->actAs('normal') - ->get('/admin') - ->assertStatus(403); - - // Admin - $this->actAs('admin') - ->get('/admin') - ->assertSuccessful(); - - // Super admin - $this->actAs('superAdmin') - ->get('/admin') - ->assertSuccessful(); - } - - public function testCheckSuperAdmin() - { - // Admin - $this->actAs('admin') - ->get('/admin/plugins/manage') - ->assertForbidden(); - - // Super admin - $this->actAs('superAdmin') - ->get('/admin/plugins/manage') - ->assertSuccessful(); - } - - public function testCheckInstallation() - { - $this->get('/setup')->assertSee('Already installed'); - - $this->mock(Filesystem::class, function ($mock) { - $mock->shouldReceive('exists') - ->with(storage_path('install.lock')) - ->twice() - ->andReturn(false); - $mock->shouldReceive('exists') - ->with(base_path('.env')) - ->andReturn(true); - }); - $this->get('/setup')->assertSee(trans( - 'setup.wizard.welcome.text', - ['version' => config('app.version')] - )); - - $this->actAs('superAdmin'); - $this->mock(Filesystem::class, function ($mock) { - $mock->shouldReceive('exists') - ->with(storage_path('install.lock')) - ->andReturn(true); - }); - config(['app.version' => '100.0.0']); - $this->get('/setup/update')->assertSee(trans('setup.updates.welcome.title')); - } - - public function testCheckPlayerExist() - { - Event::fake(); - - $this->getJson('/nope.json') - ->assertStatus(404) - ->assertSee(trans('general.unexistent-player')); - - $this->get('/skin/nope.png') - ->assertStatus(404) - ->assertSee(trans('general.unexistent-player')); - - Option::set('return_204_when_notfound', true); - $this->getJson('/nope.json')->assertStatus(204); - - $player = factory(\App\Models\Player::class)->create(); - $this->getJson("/{$player->name}.json") - ->assertJson(['username' => $player->name]); // Default is CSL API - - $this->getJson("/{$player->name}.json"); - Event::assertDispatched(\App\Events\CheckPlayerExists::class); - - $player = factory(\App\Models\Player::class)->create(); - $user = $player->user; - $this->actingAs($user) - ->postJson('/user/player/rename/-1', ['name' => 'name']) - ->assertJson([ - 'code' => 1, - 'message' => trans('general.unexistent-player'), - ]); - } - - public function testCheckPlayerOwner() - { - $other_user = factory(\App\Models\User::class)->create(); - $player = factory(\App\Models\Player::class)->create(); - $owner = $player->user; - - $this->actingAs($other_user) - ->get('/user/player') - ->assertSuccessful(); - - $this->actingAs($other_user) - ->postJson('/user/player/rename/'.$player->pid) - ->assertJson([ - 'code' => 1, - 'message' => trans('admin.players.no-permission'), - ]); - } - - public function testEnsureEmailFilled() - { - $noEmailUser = factory(User::class)->create(['email' => '']); - $this->actingAs($noEmailUser)->get('/user')->assertRedirect('/auth/bind'); - - $normalUser = factory(User::class)->create(); - $this->actingAs($normalUser)->get('/auth/bind')->assertRedirect('/user'); - } - - public function testFireUserAuthenticated() - { - Event::fake(); - $user = factory(User::class)->create(); - $this->actingAs($user)->get('/user'); - Event::assertDispatched(\App\Events\UserAuthenticated::class, function ($event) use ($user) { - $this->assertEquals($user->uid, $event->user->uid); - - return true; - }); - } - - public function testRedirectIfAuthenticated() - { - $this->get('/auth/login') - ->assertViewIs('auth.login') - ->assertDontSee(trans('general.user-center')); - - $this->actingAs(factory(User::class)->create()) - ->get('/auth/login') - ->assertRedirect('/user'); - } - - public function testRedirectToSetup() - { - $current = config('app.version'); - config(['app.version' => '100.0.0']); - $this->get('/')->assertStatus(503); - $this->actAs('superAdmin')->get('/')->assertRedirect('/setup/update'); - config(['app.version' => $current]); - - $this->mock(Filesystem::class, function ($mock) { - $mock->shouldReceive('exists') - ->with(storage_path('install.lock')) - ->andReturn(true, false, false); - - $mock->shouldReceive('exists') - ->with(base_path('.env')) - ->andReturn(true); - }); - $this->get('/')->assertViewIs('index'); - $this->get('/setup')->assertViewIs('setup.wizard.welcome'); - $this->get('/')->assertRedirect('/setup'); - } - - public function testRejectBannedUser() - { - $user = factory(User::class, 'banned')->create(); - $this->actingAs($user)->get('/user')->assertForbidden(); - $this->get('/user', ['accept' => 'application/json']) - ->assertForbidden() - ->assertJson(['code' => -1, 'message' => trans('auth.check.banned')]); - } - - public function testRequireBindPlayer() - { - $user = factory(User::class)->create(); - $this->actingAs($user)->get('/user')->assertViewIs('user.index'); - $this->get('/user/player/bind')->assertRedirect('/user'); - - option(['single_player' => true]); - - $this->getJson('/user/player/list')->assertHeader('content-type', 'application/json'); - - $this->get('/user/player/bind')->assertViewIs('user.bind'); - $this->get('/user')->assertRedirect('/user/player/bind'); - - factory(Player::class)->create(['uid' => $user->uid]); - $this->get('/user')->assertViewIs('user.index'); - $this->get('/user/player/bind')->assertRedirect('/user'); - } - - public function testForbiddenIE() - { - $this->get('/', ['user-agent' => 'MSIE'])->assertSee(trans('errors.http.ie')); - $this->get('/', ['user-agent' => 'Trident'])->assertSee(trans('errors.http.ie')); - } -}