diff --git a/tests/BrowserKitTestCase.php b/tests/BrowserKitTestCase.php index 6eb89941..7ef0d128 100644 --- a/tests/BrowserKitTestCase.php +++ b/tests/BrowserKitTestCase.php @@ -33,22 +33,4 @@ class BrowserKitTestCase extends TestCase return $app; } - - /** - * @param \App\Models\User|string $role - * - * @return $this - */ - public function actAs($role) - { - if (is_string($role)) { - if ($role == 'normal') { - $role = factory(\App\Models\User::class)->create(); - } else { - $role = factory(\App\Models\User::class)->states($role)->create(); - } - } - - return $this->actingAs($role); - } } diff --git a/tests/BrowserKitTests/AdminFormsTest.php b/tests/BrowserKitTests/AdminFormsTest.php index 0ac1c755..54ab5fcb 100644 --- a/tests/BrowserKitTests/AdminFormsTest.php +++ b/tests/BrowserKitTests/AdminFormsTest.php @@ -4,7 +4,6 @@ namespace Tests; use Cache; use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; use Mockery; class AdminFormsTest extends BrowserKitTestCase @@ -19,7 +18,7 @@ class AdminFormsTest extends BrowserKitTestCase \App\Services\Translations\JavaScript::class, Mockery::spy(\App\Services\Translations\JavaScript::class) ); - $this->actAs('admin'); + $this->actingAs(factory(\App\Models\User::class)->states('admin')->create()); } public function testCustomize() diff --git a/tests/HttpTest/ControllersTest/AdminControllerTest.php b/tests/HttpTest/ControllersTest/AdminControllerTest.php index 339c2113..f8d61c5f 100644 --- a/tests/HttpTest/ControllersTest/AdminControllerTest.php +++ b/tests/HttpTest/ControllersTest/AdminControllerTest.php @@ -8,7 +8,6 @@ use App\Models\User; use App\Notifications; use App\Services\Plugin; use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Support\Str; use Notification; @@ -20,7 +19,7 @@ class AdminControllerTest extends TestCase { // Do not use `WithoutMiddleware` trait parent::setUp(); - $this->actAs('admin'); + $this->actingAs(factory(\App\Models\User::class)->states('admin')->create()); } public function testIndex() diff --git a/tests/HttpTest/ControllersTest/PlayerControllerTest.php b/tests/HttpTest/ControllersTest/PlayerControllerTest.php index 77f75861..0538f63c 100644 --- a/tests/HttpTest/ControllersTest/PlayerControllerTest.php +++ b/tests/HttpTest/ControllersTest/PlayerControllerTest.php @@ -18,7 +18,7 @@ class PlayerControllerTest extends TestCase protected function setUp(): void { parent::setUp(); - $this->actAs('normal'); + $this->actingAs(factory(User::class)->create()); } public function testIndex() diff --git a/tests/HttpTest/ControllersTest/PluginControllerTest.php b/tests/HttpTest/ControllersTest/PluginControllerTest.php index ca144258..a487cc5c 100644 --- a/tests/HttpTest/ControllersTest/PluginControllerTest.php +++ b/tests/HttpTest/ControllersTest/PluginControllerTest.php @@ -13,7 +13,7 @@ class PluginControllerTest extends TestCase protected function setUp(): void { parent::setUp(); - $this->actAs('superAdmin'); + $this->actingAs(factory(\App\Models\User::class)->states('superAdmin')->create()); } public function testShowManage() diff --git a/tests/HttpTest/ControllersTest/SkinlibControllerTest.php b/tests/HttpTest/ControllersTest/SkinlibControllerTest.php index e0cd8b5e..7111bfba 100644 --- a/tests/HttpTest/ControllersTest/SkinlibControllerTest.php +++ b/tests/HttpTest/ControllersTest/SkinlibControllerTest.php @@ -305,12 +305,12 @@ class SkinlibControllerTest extends TestCase ->assertSee(trans('skinlib.show.private')); // Other user should not see private texture - $this->actAs('normal') + $this->actingAs(factory(User::class)->create()) ->get('/skinlib/show/'.$texture->tid) ->assertSee(trans('skinlib.show.private')); // Administrators should be able to see private textures - $this->actAs('admin') + $this->actingAs(factory(User::class)->states('admin')->create()) ->get('/skinlib/show/'.$texture->tid) ->assertViewHas('texture'); @@ -362,7 +362,7 @@ class SkinlibControllerTest extends TestCase { $filter = Fakes\Filter::fake(); - $this->actAs('normal')->get('/skinlib/upload'); + $this->actingAs(factory(User::class)->create())->get('/skinlib/upload'); $filter->assertApplied('grid:skinlib.upload'); option(['texture_name_regexp' => 'abc']); @@ -382,7 +382,7 @@ class SkinlibControllerTest extends TestCase UPLOAD_ERR_NO_TMP_DIR, true ); - $this->actAs('normal') + $this->actingAs(factory(User::class)->create()) ->postJson( '/skinlib/upload', ['file' => $upload] @@ -614,7 +614,7 @@ class SkinlibControllerTest extends TestCase ]); // Administrators can delete it - $this->actAs('admin') + $this->actingAs(factory(User::class)->states('admin')->create()) ->postJson('/skinlib/delete', ['tid' => $texture->tid]) ->assertJson([ 'code' => 0, @@ -742,7 +742,7 @@ class SkinlibControllerTest extends TestCase // Administrators can change it $uploader->score += $texture->size * option('private_score_per_storage'); $uploader->save(); - $this->actAs('admin') + $this->actingAs(factory(User::class)->states('admin')->create()) ->postJson('/skinlib/privacy', ['tid' => $texture->tid]) ->assertJson([ 'code' => 0, @@ -863,7 +863,7 @@ class SkinlibControllerTest extends TestCase ]); // Administrators should be able to rename - $this->actAs('admin') + $this->actingAs(factory(User::class)->states('admin')->create()) ->postJson('/skinlib/rename', [ 'tid' => $texture->tid, 'new_name' => 'name', @@ -916,7 +916,7 @@ class SkinlibControllerTest extends TestCase ]); // Administrators should be able to change model - $this->actAs('admin') + $this->actingAs(factory(User::class)->states('admin')->create()) ->postJson('/skinlib/model', [ 'tid' => $texture->tid, 'model' => 'alex', diff --git a/tests/HttpTest/ControllersTest/TranslationsControllerTest.php b/tests/HttpTest/ControllersTest/TranslationsControllerTest.php index 57ea4429..74c69a4e 100644 --- a/tests/HttpTest/ControllersTest/TranslationsControllerTest.php +++ b/tests/HttpTest/ControllersTest/TranslationsControllerTest.php @@ -13,7 +13,7 @@ class TranslationsControllerTest extends TestCase protected function setUp(): void { parent::setUp(); - $this->actAs('admin'); + $this->actingAs(factory(\App\Models\User::class)->states('admin')->create()); } public function testList() diff --git a/tests/HttpTest/ControllersTest/UpdateControllerTest.php b/tests/HttpTest/ControllersTest/UpdateControllerTest.php index 198fdff8..a5cd8613 100644 --- a/tests/HttpTest/ControllersTest/UpdateControllerTest.php +++ b/tests/HttpTest/ControllersTest/UpdateControllerTest.php @@ -110,7 +110,7 @@ class UpdateControllerTest extends TestCase }); config(['app.version' => '100.0.0']); - $this->actAs('superAdmin') + $this->actingAs(factory(\App\Models\User::class)->states('superAdmin')->create()) ->get('/setup/exec-update') ->assertViewIs('setup.updates.success'); $this->assertEquals('100.0.0', option('version')); diff --git a/tests/HttpTest/ControllersTest/UserControllerTest.php b/tests/HttpTest/ControllersTest/UserControllerTest.php index 16bb6a9b..18f2639f 100644 --- a/tests/HttpTest/ControllersTest/UserControllerTest.php +++ b/tests/HttpTest/ControllersTest/UserControllerTest.php @@ -231,7 +231,9 @@ class UserControllerTest extends TestCase { $filter = Fakes\Filter::fake(); - $this->actAs('normal')->get('/user/profile')->assertViewIs('user.profile'); + $this->actingAs(factory(User::class)->create()) + ->get('/user/profile') + ->assertViewIs('user.profile'); $filter->assertApplied('grid:user.profile'); } @@ -498,7 +500,7 @@ class UserControllerTest extends TestCase $this->assertNull(User::find($user->uid)); // Administrator cannot be deleted - $this->actAs('admin') + $this->actingAs(factory(User::class)->states('admin')->create()) ->postJson('/user/profile', [ 'action' => 'delete', 'password' => '87654321', diff --git a/tests/HttpTest/MiddlewareTest/CheckRoleTest.php b/tests/HttpTest/MiddlewareTest/CheckRoleTest.php index 2f305472..e7046d86 100644 --- a/tests/HttpTest/MiddlewareTest/CheckRoleTest.php +++ b/tests/HttpTest/MiddlewareTest/CheckRoleTest.php @@ -8,17 +8,17 @@ class CheckRole extends TestCase { public function testHandle() { - $this->actAs(factory(User::class)->create()) + $this->actingAs(factory(User::class)->create()) ->get('/admin') ->assertForbidden(); - $this->actAs(factory(User::class)->states('admin')->create()) + $this->actingAs(factory(User::class)->states('admin')->create()) ->get('/admin') ->assertSuccessful(); $this->get('/admin/update')->assertForbidden(); - $this->actAs(factory(User::class)->states('superAdmin')->create()) + $this->actingAs(factory(User::class)->states('superAdmin')->create()) ->get('/admin/update') ->assertSuccessful(); } diff --git a/tests/HttpTest/MiddlewareTest/CheckUserVerifiedTest.php b/tests/HttpTest/MiddlewareTest/CheckUserVerifiedTest.php index e4b58267..a3389bd5 100644 --- a/tests/HttpTest/MiddlewareTest/CheckUserVerifiedTest.php +++ b/tests/HttpTest/MiddlewareTest/CheckUserVerifiedTest.php @@ -24,7 +24,7 @@ class CheckUserVerifiedTest extends TestCase ->assertStatus(403) ->assertSee(trans('auth.check.verified')); - $this->actAs('normal') + $this->actingAs(factory(User::class)->create()) ->get('/skinlib/upload') ->assertSuccessful(); diff --git a/tests/ServicesTest/HookTest.php b/tests/ServicesTest/HookTest.php index 47f679f8..c7b56b51 100644 --- a/tests/ServicesTest/HookTest.php +++ b/tests/ServicesTest/HookTest.php @@ -15,7 +15,7 @@ class HookTest extends TestCase 'icon' => 'fa-book', 'new-tab' => true, ]); - $this->actAs('normal') + $this->actingAs(factory(User::class)->create()) ->get('/user') ->assertSee('Link A') ->assertSee('/to/a') @@ -28,7 +28,7 @@ class HookTest extends TestCase 'link' => '/to/b', 'icon' => 'fa-book', ]); - $this->actAs('normal') + $this->actingAs(factory(User::class)->create()) ->get('/user') ->assertSee('Link B') ->assertSee('/to/b'); @@ -80,7 +80,7 @@ class HookTest extends TestCase public function testAddUserBadge() { Hook::addUserBadge('hi', 'green'); - $this->actAs('normal') + $this->actingAs(factory(User::class)->create()) ->get('/user') ->assertSee('hi', false); } diff --git a/tests/TestCase.php b/tests/TestCase.php index e0411ffb..746660d8 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -33,24 +33,6 @@ class TestCase extends \Illuminate\Foundation\Testing\TestCase return $app; } - /** - * @param \App\Models\User|string $role - * - * @return $this - */ - public function actAs($role) - { - if (is_string($role)) { - if ($role == 'normal') { - $role = factory(\App\Models\User::class)->create(); - } else { - $role = factory(\App\Models\User::class)->states($role)->create(); - } - } - - return $this->actingAs($role); - } - protected function setUp(): void { parent::setUp();