refactor tests
This commit is contained in:
parent
ccfcceed37
commit
ba757d98a8
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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('<span class="badge bg-green mb-1 mr-2">hi</span>', false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user