Simplify tests

This commit is contained in:
Pig Fang 2019-03-14 00:30:53 +08:00
parent acacd09253
commit c4d26a4c10
6 changed files with 69 additions and 181 deletions

View File

@ -28,13 +28,11 @@ class AdminControllerTest extends BrowserKitTestCase
public function testCustomize() public function testCustomize()
{ {
// Check if `color_scheme` is existed or not // Check if `color_scheme` is existed or not
$this->get('/admin/customize?action=color', [ $this->getJson('/admin/customize?action=color')
'Accept' => 'application/json', ->seeJson([
'X-Requested-With' => 'XMLHttpRequest', 'errno' => 1,
])->seeJson([ 'msg' => trans('validation.required', ['attribute' => 'color scheme']),
'errno' => 1, ]);
'msg' => trans('validation.required', ['attribute' => 'color scheme']),
]);
// Change color // Change color
$this->get('/admin/customize?action=color&color_scheme=purple') $this->get('/admin/customize?action=color&color_scheme=purple')

View File

@ -35,21 +35,16 @@ class AuthControllerTest extends TestCase
); );
// Should return a warning if `identification` is empty // Should return a warning if `identification` is empty
$this->postJson( $this->postJson('/auth/login')
'/auth/login', [], [ ->assertJson([
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => trans('validation.attributes.identification')]), 'msg' => trans('validation.required', ['attribute' => trans('validation.attributes.identification')]),
]); ]);
// Should return a warning if `password` is empty // Should return a warning if `password` is empty
$this->postJson( $this->postJson(
'/auth/login', [ '/auth/login', ['identification' => $user->email]
'identification' => $user->email, )->assertJson([
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'password']), 'msg' => trans('validation.required', ['attribute' => 'password']),
]); ]);
@ -59,8 +54,6 @@ class AuthControllerTest extends TestCase
'/auth/login', [ '/auth/login', [
'identification' => $user->email, 'identification' => $user->email,
'password' => '123', 'password' => '123',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.min.string', ['attribute' => 'password', 'min' => 6]), 'msg' => trans('validation.min.string', ['attribute' => 'password', 'min' => 6]),
@ -71,8 +64,6 @@ class AuthControllerTest extends TestCase
'/auth/login', [ '/auth/login', [
'identification' => $user->email, 'identification' => $user->email,
'password' => Str::random(80), 'password' => Str::random(80),
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.max.string', ['attribute' => 'password', 'max' => 32]), 'msg' => trans('validation.max.string', ['attribute' => 'password', 'max' => 32]),
@ -186,20 +177,16 @@ class AuthControllerTest extends TestCase
$this->expectsEvents(Events\UserRegistered::class); $this->expectsEvents(Events\UserRegistered::class);
// Should return a warning if `email` is empty // Should return a warning if `email` is empty
$this->postJson( $this->postJson('/auth/register')
'/auth/register', ->assertJson([
[], 'errno' => 1,
['X-Requested-With' => 'XMLHttpRequest'] 'msg' => trans('validation.required', ['attribute' => 'email']),
)->assertJson([ ]);
'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'email']),
]);
// Should return a warning if `email` is invalid // Should return a warning if `email` is invalid
$this->postJson( $this->postJson(
'/auth/register', '/auth/register',
['email' => 'not_an_email'], ['email' => 'not_an_email']
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.email', ['attribute' => 'email']), 'msg' => trans('validation.email', ['attribute' => 'email']),
@ -209,8 +196,7 @@ class AuthControllerTest extends TestCase
$existedUser = factory(User::class)->create(); $existedUser = factory(User::class)->create();
$this->postJson( $this->postJson(
'/auth/register', '/auth/register',
['email' => $existedUser->email], ['email' => $existedUser->email]
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.unique', ['attribute' => 'email']), 'msg' => trans('validation.unique', ['attribute' => 'email']),
@ -219,8 +205,7 @@ class AuthControllerTest extends TestCase
// Should return a warning if `password` is empty // Should return a warning if `password` is empty
$this->postJson( $this->postJson(
'/auth/register', '/auth/register',
['email' => 'a@b.c'], ['email' => 'a@b.c']
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'password']), 'msg' => trans('validation.required', ['attribute' => 'password']),
@ -232,8 +217,7 @@ class AuthControllerTest extends TestCase
[ [
'email' => 'a@b.c', 'email' => 'a@b.c',
'password' => '1', 'password' => '1',
], ]
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.min.string', ['attribute' => 'password', 'min' => 8]), 'msg' => trans('validation.min.string', ['attribute' => 'password', 'min' => 8]),
@ -321,8 +305,7 @@ class AuthControllerTest extends TestCase
'email' => 'a@b.c', 'email' => 'a@b.c',
'password' => '12345678', 'password' => '12345678',
'captcha' => 'a', 'captcha' => 'a',
], ]
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'nickname']), 'msg' => trans('validation.required', ['attribute' => 'nickname']),
@ -336,8 +319,7 @@ class AuthControllerTest extends TestCase
'password' => '12345678', 'password' => '12345678',
'nickname' => '\\', 'nickname' => '\\',
'captcha' => 'a', 'captcha' => 'a',
], ]
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.no_special_chars', ['attribute' => 'nickname']), 'msg' => trans('validation.no_special_chars', ['attribute' => 'nickname']),
@ -351,8 +333,7 @@ class AuthControllerTest extends TestCase
'password' => '12345678', 'password' => '12345678',
'nickname' => Str::random(256), 'nickname' => Str::random(256),
'captcha' => 'a', 'captcha' => 'a',
], ]
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.max.string', ['attribute' => 'nickname', 'max' => 255]), 'msg' => trans('validation.max.string', ['attribute' => 'nickname', 'max' => 255]),
@ -365,8 +346,7 @@ class AuthControllerTest extends TestCase
'email' => 'a@b.c', 'email' => 'a@b.c',
'password' => '12345678', 'password' => '12345678',
'nickname' => 'nickname', 'nickname' => 'nickname',
], ]
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'captcha']), 'msg' => trans('validation.required', ['attribute' => 'captcha']),
@ -381,8 +361,7 @@ class AuthControllerTest extends TestCase
'password' => '12345678', 'password' => '12345678',
'nickname' => 'nickname', 'nickname' => 'nickname',
'captcha' => 'a', 'captcha' => 'a',
], ]
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 7, 'errno' => 7,
'msg' => trans('auth.register.close'), 'msg' => trans('auth.register.close'),
@ -544,20 +523,16 @@ class AuthControllerTest extends TestCase
$url = URL::temporarySignedRoute('auth.reset', now()->addHour(), ['uid' => $user->uid]); $url = URL::temporarySignedRoute('auth.reset', now()->addHour(), ['uid' => $user->uid]);
// Should return a warning if `password` is empty // Should return a warning if `password` is empty
$this->postJson( $this->postJson($url)
$url, [], [ ->assertJson([
'X-Requested-With' => 'XMLHttpRequest', 'errno' => 1,
])->assertJson([ 'msg' => trans('validation.required', ['attribute' => 'password']),
'errno' => 1, ]);
'msg' => trans('validation.required', ['attribute' => 'password']),
]);
// Should return a warning if `password` is too short // Should return a warning if `password` is too short
$this->postJson( $this->postJson(
$url, [ $url, [
'password' => '123', 'password' => '123',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.min.string', ['attribute' => 'password', 'min' => 8]), 'msg' => trans('validation.min.string', ['attribute' => 'password', 'min' => 8]),
@ -567,8 +542,6 @@ class AuthControllerTest extends TestCase
$this->postJson( $this->postJson(
$url, [ $url, [
'password' => Str::random(33), 'password' => Str::random(33),
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.max.string', ['attribute' => 'password', 'max' => 32]), 'msg' => trans('validation.max.string', ['attribute' => 'password', 'max' => 32]),

View File

@ -91,7 +91,7 @@ class ClosetControllerTest extends TestCase
option(['score_per_closet_item' => 10]); option(['score_per_closet_item' => 10]);
// Missing `tid` field // Missing `tid` field
$this->postJson('/user/closet/add', [], ['X-Requested-With' => 'XMLHttpRequest']) $this->postJson('/user/closet/add')
->assertJson([ ->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'tid']), 'msg' => trans('validation.required', ['attribute' => 'tid']),
@ -100,8 +100,7 @@ class ClosetControllerTest extends TestCase
// `tid` is not a integer // `tid` is not a integer
$this->postJson( $this->postJson(
'/user/closet/add', '/user/closet/add',
['tid' => 'string'], ['tid' => 'string']
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.integer', ['attribute' => 'tid']), 'msg' => trans('validation.integer', ['attribute' => 'tid']),
@ -110,8 +109,7 @@ class ClosetControllerTest extends TestCase
// Missing `name` field // Missing `name` field
$this->postJson( $this->postJson(
'/user/closet/add', '/user/closet/add',
['tid' => 0], ['tid' => 0]
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'name']), 'msg' => trans('validation.required', ['attribute' => 'name']),
@ -120,8 +118,7 @@ class ClosetControllerTest extends TestCase
// `name` field has special characters // `name` field has special characters
$this->postJson( $this->postJson(
'/user/closet/add', '/user/closet/add',
['tid' => 0, 'name' => '\\'], ['tid' => 0, 'name' => '\\']
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.no_special_chars', ['attribute' => 'name']), 'msg' => trans('validation.no_special_chars', ['attribute' => 'name']),
@ -177,7 +174,7 @@ class ClosetControllerTest extends TestCase
$name = 'new'; $name = 'new';
// Missing `tid` field // Missing `tid` field
$this->postJson('/user/closet/rename', [], ['X-Requested-With' => 'XMLHttpRequest']) $this->postJson('/user/closet/rename')
->assertJson([ ->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'tid']), 'msg' => trans('validation.required', ['attribute' => 'tid']),
@ -186,8 +183,7 @@ class ClosetControllerTest extends TestCase
// `tid` is not a integer // `tid` is not a integer
$this->postJson( $this->postJson(
'/user/closet/rename', '/user/closet/rename',
['tid' => 'string'], ['tid' => 'string']
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.integer', ['attribute' => 'tid']), 'msg' => trans('validation.integer', ['attribute' => 'tid']),
@ -196,8 +192,7 @@ class ClosetControllerTest extends TestCase
// Missing `new_name` field // Missing `new_name` field
$this->postJson( $this->postJson(
'/user/closet/rename', '/user/closet/rename',
['tid' => 0], ['tid' => 0]
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'new name']), 'msg' => trans('validation.required', ['attribute' => 'new name']),
@ -206,8 +201,7 @@ class ClosetControllerTest extends TestCase
// `new_name` field has special characters // `new_name` field has special characters
$this->postJson( $this->postJson(
'/user/closet/rename', '/user/closet/rename',
['tid' => 0, 'new_name' => '\\'], ['tid' => 0, 'new_name' => '\\']
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.no_special_chars', ['attribute' => 'new name']), 'msg' => trans('validation.no_special_chars', ['attribute' => 'new name']),
@ -244,7 +238,7 @@ class ClosetControllerTest extends TestCase
$texture = factory(Texture::class)->create(); $texture = factory(Texture::class)->create();
// Missing `tid` field // Missing `tid` field
$this->postJson('/user/closet/remove', [], ['X-Requested-With' => 'XMLHttpRequest']) $this->postJson('/user/closet/remove')
->assertJson([ ->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'tid']), 'msg' => trans('validation.required', ['attribute' => 'tid']),
@ -253,8 +247,7 @@ class ClosetControllerTest extends TestCase
// `tid` is not a integer // `tid` is not a integer
$this->postJson( $this->postJson(
'/user/closet/remove', '/user/closet/remove',
['tid' => 'string'], ['tid' => 'string']
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.integer', ['attribute' => 'tid']), 'msg' => trans('validation.integer', ['attribute' => 'tid']),

View File

@ -42,7 +42,7 @@ class PlayerControllerTest extends TestCase
public function testAdd() public function testAdd()
{ {
// Without player name // Without player name
$this->postJson('/user/player/add', [], ['X-Requested-With' => 'XMLHttpRequest']) $this->postJson('/user/player/add')
->assertJson([ ->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => trans('validation.attributes.player_name')]), 'msg' => trans('validation.required', ['attribute' => trans('validation.attributes.player_name')]),
@ -52,8 +52,7 @@ class PlayerControllerTest extends TestCase
option(['player_name_rule' => 'official']); option(['player_name_rule' => 'official']);
$this->postJson( $this->postJson(
'/user/player/add', '/user/player/add',
['player_name' => '角色名'], ['player_name' => '角色名']
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.player_name', ['attribute' => trans('validation.attributes.player_name')]), 'msg' => trans('validation.player_name', ['attribute' => trans('validation.attributes.player_name')]),
@ -64,8 +63,7 @@ class PlayerControllerTest extends TestCase
option(['custom_player_name_regexp' => '/^([0-9]+)$/']); option(['custom_player_name_regexp' => '/^([0-9]+)$/']);
$this->postJson( $this->postJson(
'/user/player/add', '/user/player/add',
['player_name' => 'yjsnpi'], ['player_name' => 'yjsnpi']
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.player_name', ['attribute' => trans('validation.attributes.player_name')]), 'msg' => trans('validation.player_name', ['attribute' => trans('validation.attributes.player_name')]),
@ -76,8 +74,7 @@ class PlayerControllerTest extends TestCase
$user = factory(User::class)->create(['score' => 0]); $user = factory(User::class)->create(['score' => 0]);
$this->actAs($user)->postJson( $this->actAs($user)->postJson(
'/user/player/add', '/user/player/add',
['player_name' => 'no_score'], ['player_name' => 'no_score']
['X-Requested-With' => 'XMLHttpRequest']
)->assertJson([ )->assertJson([
'errno' => 7, 'errno' => 7,
'msg' => trans('user.player.add.lack-score'), 'msg' => trans('user.player.add.lack-score'),
@ -164,9 +161,8 @@ class PlayerControllerTest extends TestCase
$this->actAs($user) $this->actAs($user)
->postJson('/user/player/rename', [ ->postJson('/user/player/rename', [
'pid' => $player->pid, 'pid' => $player->pid,
], [ ])
'X-Requested-With' => 'XMLHttpRequest', ->assertJson([
])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => trans('validation.attributes.player_name')]), 'msg' => trans('validation.required', ['attribute' => trans('validation.attributes.player_name')]),
]); ]);
@ -176,8 +172,6 @@ class PlayerControllerTest extends TestCase
$this->postJson('/user/player/rename', [ $this->postJson('/user/player/rename', [
'pid' => $player->pid, 'pid' => $player->pid,
'new_player_name' => '角色名', 'new_player_name' => '角色名',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.player_name', ['attribute' => trans('validation.attributes.player_name')]), 'msg' => trans('validation.player_name', ['attribute' => trans('validation.attributes.player_name')]),
@ -188,9 +182,8 @@ class PlayerControllerTest extends TestCase
$this->postJson('/user/player/rename', [ $this->postJson('/user/player/rename', [
'pid' => $player->pid, 'pid' => $player->pid,
'new_player_name' => '\\', 'new_player_name' => '\\',
], [ ])
'X-Requested-With' => 'XMLHttpRequest', ->assertJson([
])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.player_name', ['attribute' => trans('validation.attributes.player_name')]), 'msg' => trans('validation.player_name', ['attribute' => trans('validation.attributes.player_name')]),
]); ]);

View File

@ -403,29 +403,22 @@ class SkinlibControllerTest extends TestCase
]); ]);
// Without `name` field // Without `name` field
$this->postJson('/skinlib/upload', [], [ $this->postJson('/skinlib/upload')->assertJson([
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'name']), 'msg' => trans('validation.required', ['attribute' => 'name']),
]); ]);
// With some special chars // With some special chars
$this->postJson('/skinlib/upload', [ $this->postJson('/skinlib/upload', ['name' => '\\'])
'name' => '\\', ->assertJson([
], [ 'errno' => 1,
'X-Requested-With' => 'XMLHttpRequest', 'msg' => trans('validation.no_special_chars', ['attribute' => 'name']),
])->assertJson([ ]);
'errno' => 1,
'msg' => trans('validation.no_special_chars', ['attribute' => 'name']),
]);
// Specified regular expression for texture name // Specified regular expression for texture name
option(['texture_name_regexp' => '/\\d+/']); option(['texture_name_regexp' => '/\\d+/']);
$this->postJson('/skinlib/upload', [ $this->postJson('/skinlib/upload', [
'name' => 'abc', 'name' => 'abc',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.regex', ['attribute' => 'name']), 'msg' => trans('validation.regex', ['attribute' => 'name']),
@ -435,8 +428,6 @@ class SkinlibControllerTest extends TestCase
// Without file // Without file
$this->postJson('/skinlib/upload', [ $this->postJson('/skinlib/upload', [
'name' => 'texture', 'name' => 'texture',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'file']), 'msg' => trans('validation.required', ['attribute' => 'file']),
@ -448,8 +439,6 @@ class SkinlibControllerTest extends TestCase
$this->postJson('/skinlib/upload', [ $this->postJson('/skinlib/upload', [
'name' => 'texture', 'name' => 'texture',
'file' => $upload, 'file' => $upload,
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.max.file', ['attribute' => 'file', 'max' => '2']), 'msg' => trans('validation.max.file', ['attribute' => 'file', 'max' => '2']),
@ -460,8 +449,6 @@ class SkinlibControllerTest extends TestCase
$this->postJson('/skinlib/upload', [ $this->postJson('/skinlib/upload', [
'name' => 'texture', 'name' => 'texture',
'file' => 'content', // Though it is not a file, it is OK 'file' => 'content', // Though it is not a file, it is OK
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'public']), 'msg' => trans('validation.required', ['attribute' => 'public']),
@ -799,9 +786,7 @@ class SkinlibControllerTest extends TestCase
// Without `tid` field // Without `tid` field
$this->actAs($uploader) $this->actAs($uploader)
->postJson('/skinlib/rename', [], [ ->postJson('/skinlib/rename')
'X-Requested-With' => 'XMLHttpRequest',
])
->assertJson([ ->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'tid']), 'msg' => trans('validation.required', ['attribute' => 'tid']),
@ -810,8 +795,6 @@ class SkinlibControllerTest extends TestCase
// `tid` is not a integer // `tid` is not a integer
$this->postJson('/skinlib/rename', [ $this->postJson('/skinlib/rename', [
'tid' => 'str', 'tid' => 'str',
], [
'X-Requested-With' => 'XMLHttpRequest',
]) ])
->assertJson([ ->assertJson([
'errno' => 1, 'errno' => 1,
@ -821,8 +804,6 @@ class SkinlibControllerTest extends TestCase
// Without `new_name` field // Without `new_name` field
$this->postJson('/skinlib/rename', [ $this->postJson('/skinlib/rename', [
'tid' => $texture->tid, 'tid' => $texture->tid,
], [
'X-Requested-With' => 'XMLHttpRequest',
]) ])
->assertJson([ ->assertJson([
'errno' => 1, 'errno' => 1,
@ -833,8 +814,6 @@ class SkinlibControllerTest extends TestCase
$this->postJson('/skinlib/rename', [ $this->postJson('/skinlib/rename', [
'tid' => $texture->tid, 'tid' => $texture->tid,
'new_name' => '\\', 'new_name' => '\\',
], [
'X-Requested-With' => 'XMLHttpRequest',
]) ])
->assertJson([ ->assertJson([
'errno' => 1, 'errno' => 1,

View File

@ -219,21 +219,16 @@ class UserControllerTest extends TestCase
]); ]);
// Change nickname without `new_nickname` field // Change nickname without `new_nickname` field
$this->postJson('/user/profile', [ $this->postJson('/user/profile', ['action' => 'nickname'])
'action' => 'nickname', ->assertJson([
], [ 'errno' => 1,
'X-Requested-With' => 'XMLHttpRequest', 'msg' => trans('validation.required', ['attribute' => 'new nickname']),
])->assertJson([ ]);
'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'new nickname']),
]);
// Invalid nickname // Invalid nickname
$this->postJson('/user/profile', [ $this->postJson('/user/profile', [
'action' => 'nickname', 'action' => 'nickname',
'new_nickname' => '\\', 'new_nickname' => '\\',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.no_special_chars', ['attribute' => 'new nickname']), 'msg' => trans('validation.no_special_chars', ['attribute' => 'new nickname']),
@ -243,8 +238,6 @@ class UserControllerTest extends TestCase
$this->postJson('/user/profile', [ $this->postJson('/user/profile', [
'action' => 'nickname', 'action' => 'nickname',
'new_nickname' => Str::random(256), 'new_nickname' => Str::random(256),
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.max.string', ['attribute' => 'new nickname', 'max' => 255]), 'msg' => trans('validation.max.string', ['attribute' => 'new nickname', 'max' => 255]),
@ -255,8 +248,6 @@ class UserControllerTest extends TestCase
$this->postJson('/user/profile', [ $this->postJson('/user/profile', [
'action' => 'nickname', 'action' => 'nickname',
'new_nickname' => 'nickname', 'new_nickname' => 'nickname',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 0, 'errno' => 0,
'msg' => trans('user.profile.nickname.success', ['nickname' => 'nickname']), 'msg' => trans('user.profile.nickname.success', ['nickname' => 'nickname']),
@ -264,22 +255,17 @@ class UserControllerTest extends TestCase
$this->assertEquals('nickname', User::find($user->uid)->nickname); $this->assertEquals('nickname', User::find($user->uid)->nickname);
// Change password without `current_password` field // Change password without `current_password` field
$this->postJson('/user/profile', [ $this->postJson('/user/profile', ['action' => 'password'])
'action' => 'password', ->assertJson([
], [ 'errno' => 1,
'X-Requested-With' => 'XMLHttpRequest', 'msg' => trans('validation.required', ['attribute' => 'current password']),
])->assertJson([ ]);
'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'current password']),
]);
// Too short current password // Too short current password
$this->postJson('/user/profile', [ $this->postJson('/user/profile', [
'action' => 'password', 'action' => 'password',
'current_password' => '1', 'current_password' => '1',
'new_password' => '12345678', 'new_password' => '12345678',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.min.string', ['attribute' => 'current password', 'min' => 6]), 'msg' => trans('validation.min.string', ['attribute' => 'current password', 'min' => 6]),
@ -290,8 +276,6 @@ class UserControllerTest extends TestCase
'action' => 'password', 'action' => 'password',
'current_password' => Str::random(33), 'current_password' => Str::random(33),
'new_password' => '12345678', 'new_password' => '12345678',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.max.string', ['attribute' => 'current password', 'max' => 32]), 'msg' => trans('validation.max.string', ['attribute' => 'current password', 'max' => 32]),
@ -302,8 +286,6 @@ class UserControllerTest extends TestCase
'action' => 'password', 'action' => 'password',
'current_password' => '12345678', 'current_password' => '12345678',
'new_password' => '1', 'new_password' => '1',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.min.string', ['attribute' => 'new password', 'min' => 8]), 'msg' => trans('validation.min.string', ['attribute' => 'new password', 'min' => 8]),
@ -314,8 +296,6 @@ class UserControllerTest extends TestCase
'action' => 'password', 'action' => 'password',
'current_password' => '12345678', 'current_password' => '12345678',
'new_password' => Str::random(33), 'new_password' => Str::random(33),
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.max.string', ['attribute' => 'new password', 'max' => 32]), 'msg' => trans('validation.max.string', ['attribute' => 'new password', 'max' => 32]),
@ -326,8 +306,6 @@ class UserControllerTest extends TestCase
'action' => 'password', 'action' => 'password',
'current_password' => '1234567', 'current_password' => '1234567',
'new_password' => '87654321', 'new_password' => '87654321',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('user.profile.password.wrong-password'), 'msg' => trans('user.profile.password.wrong-password'),
@ -339,8 +317,6 @@ class UserControllerTest extends TestCase
'action' => 'password', 'action' => 'password',
'current_password' => '12345678', 'current_password' => '12345678',
'new_password' => '87654321', 'new_password' => '87654321',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 0, 'errno' => 0,
'msg' => trans('user.profile.password.success'), 'msg' => trans('user.profile.password.success'),
@ -354,8 +330,8 @@ class UserControllerTest extends TestCase
$this->actAs($user) $this->actAs($user)
->postJson( ->postJson(
'/user/profile', '/user/profile',
['action' => 'email'], ['action' => 'email']
['X-Requested-With' => 'XMLHttpRequest']) )
->assertJson([ ->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'new email']), 'msg' => trans('validation.required', ['attribute' => 'new email']),
@ -365,8 +341,6 @@ class UserControllerTest extends TestCase
$this->postJson('/user/profile', [ $this->postJson('/user/profile', [
'action' => 'email', 'action' => 'email',
'new_email' => 'not_an_email', 'new_email' => 'not_an_email',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.email', ['attribute' => 'new email']), 'msg' => trans('validation.email', ['attribute' => 'new email']),
@ -377,8 +351,6 @@ class UserControllerTest extends TestCase
'action' => 'email', 'action' => 'email',
'new_email' => 'a@b.c', 'new_email' => 'a@b.c',
'password' => '1', 'password' => '1',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.min.string', ['attribute' => 'password', 'min' => 6]), 'msg' => trans('validation.min.string', ['attribute' => 'password', 'min' => 6]),
@ -389,8 +361,6 @@ class UserControllerTest extends TestCase
'action' => 'email', 'action' => 'email',
'new_email' => 'a@b.c', 'new_email' => 'a@b.c',
'password' => Str::random(33), 'password' => Str::random(33),
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.max.string', ['attribute' => 'password', 'max' => 32]), 'msg' => trans('validation.max.string', ['attribute' => 'password', 'max' => 32]),
@ -401,8 +371,6 @@ class UserControllerTest extends TestCase
'action' => 'email', 'action' => 'email',
'new_email' => $user->email, 'new_email' => $user->email,
'password' => '87654321', 'password' => '87654321',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('user.profile.email.existed'), 'msg' => trans('user.profile.email.existed'),
@ -413,8 +381,6 @@ class UserControllerTest extends TestCase
'action' => 'email', 'action' => 'email',
'new_email' => 'a@b.c', 'new_email' => 'a@b.c',
'password' => '7654321', 'password' => '7654321',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('user.profile.email.wrong-password'), 'msg' => trans('user.profile.email.wrong-password'),
@ -425,8 +391,6 @@ class UserControllerTest extends TestCase
'action' => 'email', 'action' => 'email',
'new_email' => 'a@b.c', 'new_email' => 'a@b.c',
'password' => '87654321', 'password' => '87654321',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 0, 'errno' => 0,
'msg' => trans('user.profile.email.success'), 'msg' => trans('user.profile.email.success'),
@ -443,8 +407,8 @@ class UserControllerTest extends TestCase
$this->actAs($user) $this->actAs($user)
->postJson( ->postJson(
'/user/profile', '/user/profile',
['action' => 'delete'], ['action' => 'delete']
['X-Requested-With' => 'XMLHttpRequest']) )
->assertJson([ ->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'password']), 'msg' => trans('validation.required', ['attribute' => 'password']),
@ -454,8 +418,6 @@ class UserControllerTest extends TestCase
$this->postJson('/user/profile', [ $this->postJson('/user/profile', [
'action' => 'delete', 'action' => 'delete',
'password' => '1', 'password' => '1',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.min.string', ['attribute' => 'password', 'min' => 6]), 'msg' => trans('validation.min.string', ['attribute' => 'password', 'min' => 6]),
@ -465,8 +427,6 @@ class UserControllerTest extends TestCase
$this->postJson('/user/profile', [ $this->postJson('/user/profile', [
'action' => 'delete', 'action' => 'delete',
'password' => Str::random(33), 'password' => Str::random(33),
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.max.string', ['attribute' => 'password', 'max' => 32]), 'msg' => trans('validation.max.string', ['attribute' => 'password', 'max' => 32]),
@ -476,8 +436,6 @@ class UserControllerTest extends TestCase
$this->postJson('/user/profile', [ $this->postJson('/user/profile', [
'action' => 'delete', 'action' => 'delete',
'password' => '7654321', 'password' => '7654321',
], [
'X-Requested-With' => 'XMLHttpRequest',
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('user.profile.delete.wrong-password'), 'msg' => trans('user.profile.delete.wrong-password'),
@ -512,9 +470,7 @@ class UserControllerTest extends TestCase
// Without `tid` field // Without `tid` field
$this->actAs($user) $this->actAs($user)
->postJson('/user/profile/avatar', [], [ ->postJson('/user/profile/avatar')
'X-Requested-With' => 'XMLHttpRequest',
])
->assertJson([ ->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.required', ['attribute' => 'tid']), 'msg' => trans('validation.required', ['attribute' => 'tid']),
@ -522,11 +478,7 @@ class UserControllerTest extends TestCase
// TID is not a integer // TID is not a integer
$this->actAs($user) $this->actAs($user)
->postJson('/user/profile/avatar', [ ->postJson('/user/profile/avatar', ['tid' => 'string'])
'tid' => 'string',
], [
'X-Requested-With' => 'XMLHttpRequest',
])
->assertJson([ ->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('validation.integer', ['attribute' => 'tid']), 'msg' => trans('validation.integer', ['attribute' => 'tid']),