2017-11-02 16:50:00 +08:00
|
|
|
<?php
|
|
|
|
|
2018-08-17 15:25:08 +08:00
|
|
|
namespace Tests;
|
|
|
|
|
2017-11-02 16:50:00 +08:00
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\Player;
|
|
|
|
use App\Models\Texture;
|
2019-02-27 23:44:50 +08:00
|
|
|
use Illuminate\Support\Str;
|
2017-11-02 16:50:00 +08:00
|
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
|
2018-07-13 16:48:15 +08:00
|
|
|
class AdminControllerTest extends BrowserKitTestCase
|
2017-11-02 16:50:00 +08:00
|
|
|
{
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
2019-02-27 23:44:50 +08:00
|
|
|
protected function setUp(): void
|
2017-11-02 16:50:00 +08:00
|
|
|
{
|
|
|
|
// Do not use `WithoutMiddleware` trait
|
|
|
|
parent::setUp();
|
2019-02-27 23:44:50 +08:00
|
|
|
$this->actAs('admin');
|
2017-11-02 16:50:00 +08:00
|
|
|
}
|
|
|
|
|
2019-03-19 19:16:03 +08:00
|
|
|
public function testChartData()
|
2017-11-02 16:50:00 +08:00
|
|
|
{
|
2019-03-19 19:16:03 +08:00
|
|
|
$this->getJson('/admin/chart')->seeJsonStructure(['labels', 'xAxis', 'data']);
|
2017-11-02 16:50:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCustomize()
|
|
|
|
{
|
|
|
|
// Check if `color_scheme` is existed or not
|
2019-03-14 00:30:53 +08:00
|
|
|
$this->getJson('/admin/customize?action=color')
|
|
|
|
->seeJson([
|
|
|
|
'errno' => 1,
|
|
|
|
'msg' => trans('validation.required', ['attribute' => 'color scheme']),
|
|
|
|
]);
|
2017-11-02 16:50:00 +08:00
|
|
|
|
|
|
|
// Change color
|
|
|
|
$this->get('/admin/customize?action=color&color_scheme=purple')
|
|
|
|
->seeJson([
|
|
|
|
'errno' => 0,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.customize.change-color.success'),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
$this->assertEquals('purple', option('color_scheme'));
|
|
|
|
|
|
|
|
$this->visit('/admin/customize')
|
|
|
|
->type('url', 'home_pic_url')
|
|
|
|
->type('url', 'favicon_url')
|
|
|
|
->select('1', 'copyright_prefer')
|
|
|
|
->type('copyright', 'copyright_text')
|
|
|
|
->press('submit_homepage');
|
|
|
|
$this->assertEquals('url', option('home_pic_url'));
|
|
|
|
$this->assertEquals('url', option('favicon_url'));
|
|
|
|
$this->assertEquals('1', option('copyright_prefer'));
|
|
|
|
$this->assertEquals('copyright', option('copyright_text'));
|
|
|
|
|
|
|
|
$this->visit('/admin/customize')
|
|
|
|
->type('css', 'custom_css')
|
|
|
|
->type('js', 'custom_js')
|
|
|
|
->press('submit_customJsCss');
|
|
|
|
$this->assertEquals('css', option('custom_css'));
|
|
|
|
$this->assertEquals('js', option('custom_js'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testScore()
|
|
|
|
{
|
|
|
|
$this->visit('/admin/score')
|
|
|
|
->type('4', 'score_per_storage')
|
|
|
|
->type('6', 'private_score_per_storage')
|
|
|
|
->type('8', 'score_per_closet_item')
|
|
|
|
->uncheck('return_score')
|
|
|
|
->type('12', 'score_per_player')
|
|
|
|
->type('500', 'user_initial_score')
|
|
|
|
->press('submit_rate');
|
|
|
|
$this->assertEquals('4', option('score_per_storage'));
|
|
|
|
$this->assertEquals('6', option('private_score_per_storage'));
|
|
|
|
$this->assertEquals('8', option('score_per_closet_item'));
|
|
|
|
$this->assertFalse(option('return_score'));
|
|
|
|
$this->assertEquals('12', option('score_per_player'));
|
|
|
|
$this->assertEquals('500', option('user_initial_score'));
|
|
|
|
|
|
|
|
$this->visit('/admin/score')
|
|
|
|
->type('233', 'sign_score_from')
|
|
|
|
->type('666', 'sign_score_to')
|
|
|
|
->type('7', 'sign_gap_time')
|
|
|
|
->check('sign_after_zero')
|
|
|
|
->press('submit_sign');
|
|
|
|
$this->assertEquals('233,666', option('sign_score'));
|
|
|
|
$this->assertEquals('7', option('sign_gap_time'));
|
|
|
|
$this->assertTrue(option('sign_after_zero'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOptions()
|
|
|
|
{
|
|
|
|
$this->visit('/admin/options')
|
|
|
|
->type('My Site', 'site_name')
|
|
|
|
->type('hi', 'site_description')
|
|
|
|
->type('http://blessing.skin/', 'site_url')
|
|
|
|
->uncheck('user_can_register')
|
|
|
|
->type('8', 'regs_per_ip')
|
|
|
|
->select('1', 'ip_get_method')
|
|
|
|
->type('2048', 'max_upload_file_size')
|
|
|
|
->see(trans(
|
|
|
|
'options.general.max_upload_file_size.hint',
|
|
|
|
['size' => ini_get('upload_max_filesize')]
|
|
|
|
))
|
2018-06-19 11:51:34 +08:00
|
|
|
->select('cjk', 'player_name_rule')
|
|
|
|
->type('/^([0-9]+)$/', 'custom_player_name_regexp')
|
2017-11-02 16:50:00 +08:00
|
|
|
->select('1', 'api_type')
|
|
|
|
->check('auto_del_invalid_texture')
|
|
|
|
->type('code', 'comment_script')
|
|
|
|
->press('submit_general');
|
2018-07-06 14:49:39 +08:00
|
|
|
$this->assertEquals('My Site', option_localized('site_name'));
|
|
|
|
$this->assertEquals('hi', option_localized('site_description'));
|
2017-11-02 16:50:00 +08:00
|
|
|
$this->assertEquals('http://blessing.skin', option('site_url'));
|
|
|
|
$this->assertFalse(option('user_can_register'));
|
|
|
|
$this->assertEquals('8', option('regs_per_ip'));
|
|
|
|
$this->assertEquals('1', option('ip_get_method'));
|
|
|
|
$this->assertEquals('2048', option('max_upload_file_size'));
|
2018-06-19 11:51:34 +08:00
|
|
|
$this->assertEquals('cjk', option('player_name_rule'));
|
|
|
|
$this->assertEquals('/^([0-9]+)$/', option('custom_player_name_regexp'));
|
2017-11-02 16:50:00 +08:00
|
|
|
$this->assertEquals('1', option('api_type'));
|
|
|
|
$this->assertTrue(option('auto_del_invalid_texture'));
|
|
|
|
$this->assertEquals('code', option('comment_script'));
|
|
|
|
|
2017-11-08 17:57:12 +08:00
|
|
|
$this->visit('/admin/options')
|
|
|
|
->type('http://blessing.skin/index.php', 'site_url')
|
|
|
|
->press('submit_general');
|
|
|
|
$this->assertEquals('http://blessing.skin', option('site_url'));
|
|
|
|
|
2017-11-02 16:50:00 +08:00
|
|
|
$this->visit('/admin/options')
|
|
|
|
->type('announcement', 'announcement')
|
|
|
|
->press('submit_announ');
|
|
|
|
$this->assertEquals('announcement', option('announcement'));
|
|
|
|
|
|
|
|
$this->visit('/admin/options')
|
|
|
|
->check('force_ssl')
|
|
|
|
->uncheck('auto_detect_asset_url')
|
2018-07-22 16:42:58 +08:00
|
|
|
->check('return_204_when_notfound')
|
2017-11-02 16:50:00 +08:00
|
|
|
->type('0', 'cache_expire_time')
|
2019-03-16 19:56:50 +08:00
|
|
|
->type('url/', 'cdn_address')
|
2017-11-02 16:50:00 +08:00
|
|
|
->press('submit_resources');
|
|
|
|
$this->assertTrue(option('force_ssl'));
|
|
|
|
$this->assertFalse(option('auto_detect_asset_url'));
|
2018-07-22 16:42:58 +08:00
|
|
|
$this->assertTrue(option('return_204_when_notfound'));
|
2017-11-02 16:50:00 +08:00
|
|
|
$this->assertEquals('0', option('cache_expire_time'));
|
2019-03-16 19:56:50 +08:00
|
|
|
$this->visit('/')->see('url/app/index.js');
|
|
|
|
|
|
|
|
$this->visit('/admin/options')
|
|
|
|
->type('', 'cdn_address')
|
|
|
|
->press('submit_resources');
|
|
|
|
$this->visit('/')->dontSee('url/app/index.js');
|
2019-03-16 21:52:09 +08:00
|
|
|
|
|
|
|
$this->visit('/admin/options')
|
|
|
|
->type('kw', 'meta_keywords')
|
|
|
|
->type('desc', 'meta_description')
|
|
|
|
->type('<!-- nothing -->', 'meta_extras')
|
|
|
|
->press('submit_meta');
|
|
|
|
$this->visit('/')
|
|
|
|
->see('<meta name="keywords" content="kw">')
|
|
|
|
->see('<meta name="description" content="desc">')
|
|
|
|
->see('<!-- nothing -->');
|
2017-11-02 16:50:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUsers()
|
|
|
|
{
|
|
|
|
$this->visit('/admin/users')->see(trans('general.user-manage'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetUserData()
|
|
|
|
{
|
2018-08-13 11:08:14 +08:00
|
|
|
$this->getJson('/admin/user-data')
|
2017-11-02 16:50:00 +08:00
|
|
|
->seeJsonStructure([
|
|
|
|
'data' => [[
|
|
|
|
'uid',
|
|
|
|
'email',
|
|
|
|
'nickname',
|
|
|
|
'score',
|
|
|
|
'permission',
|
|
|
|
'register_at',
|
|
|
|
'operations',
|
2019-03-02 22:58:37 +08:00
|
|
|
'players_count',
|
|
|
|
]],
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
$user = factory(User::class)->create();
|
2018-08-13 11:08:14 +08:00
|
|
|
$this->getJson('/admin/user-data?uid='.$user->uid)
|
2017-11-02 16:50:00 +08:00
|
|
|
->seeJsonSubset([
|
|
|
|
'data' => [[
|
|
|
|
'uid' => $user->uid,
|
|
|
|
'email' => $user->email,
|
|
|
|
'nickname' => $user->nickname,
|
|
|
|
'score' => $user->score,
|
|
|
|
'permission' => $user->permission,
|
2019-03-02 22:58:37 +08:00
|
|
|
'players_count' => 0,
|
|
|
|
]],
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPlayers()
|
|
|
|
{
|
|
|
|
$this->visit('/admin/players')->see(trans('general.player-manage'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPlayerData()
|
|
|
|
{
|
|
|
|
$player = factory(Player::class)->create();
|
2018-07-16 10:22:19 +08:00
|
|
|
$user = $player->user;
|
2017-11-02 16:50:00 +08:00
|
|
|
|
2018-08-13 11:08:14 +08:00
|
|
|
$this->getJson('/admin/player-data')
|
2017-11-02 16:50:00 +08:00
|
|
|
->seeJsonStructure([
|
|
|
|
'data' => [[
|
|
|
|
'pid',
|
|
|
|
'uid',
|
2019-03-13 13:16:51 +08:00
|
|
|
'name',
|
2019-03-02 21:13:17 +08:00
|
|
|
'tid_skin',
|
2017-11-02 16:50:00 +08:00
|
|
|
'tid_cape',
|
2019-03-02 22:58:37 +08:00
|
|
|
'last_modified',
|
|
|
|
]],
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
2018-08-13 11:08:14 +08:00
|
|
|
$this->getJson('/admin/player-data?uid='.$user->uid)
|
2017-11-02 16:50:00 +08:00
|
|
|
->seeJsonSubset([
|
|
|
|
'data' => [[
|
|
|
|
'pid' => $player->pid,
|
|
|
|
'uid' => $user->uid,
|
2019-03-13 13:16:51 +08:00
|
|
|
'name' => $player->name,
|
2019-03-02 21:13:17 +08:00
|
|
|
'tid_skin' => $player->tid_skin,
|
2019-03-02 22:58:37 +08:00
|
|
|
'tid_cape' => $player->tid_cape,
|
|
|
|
]],
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUserAjaxHandler()
|
|
|
|
{
|
|
|
|
// Operate on an not-existed user
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/users')
|
2017-11-02 16:50:00 +08:00
|
|
|
->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.users.operations.non-existent'),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
$user = factory(User::class)->create();
|
|
|
|
|
|
|
|
// Operate without `action` field
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/users', ['uid' => $user->uid])
|
2017-11-02 16:50:00 +08:00
|
|
|
->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.users.operations.invalid'),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// An admin operating on a super admin should be forbidden
|
|
|
|
$superAdmin = factory(User::class, 'superAdmin')->create();
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/users', ['uid' => $superAdmin->uid])
|
2017-11-02 16:50:00 +08:00
|
|
|
->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.users.operations.no-permission'),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Action is `email` but without `email` field
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/users',
|
|
|
|
['uid' => $user->uid, 'action' => 'email'],
|
2018-08-17 14:44:22 +08:00
|
|
|
['Accept' => 'application/json']
|
2017-11-02 16:50:00 +08:00
|
|
|
)->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('validation.required', ['attribute' => 'email']),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Action is `email` but with an invalid email address
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/users',
|
|
|
|
['uid' => $user->uid, 'action' => 'email', 'email' => 'invalid'],
|
2018-08-17 14:44:22 +08:00
|
|
|
['Accept' => 'application/json']
|
2017-11-02 16:50:00 +08:00
|
|
|
)->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('validation.email', ['attribute' => 'email']),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Using an existed email address
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/users',
|
|
|
|
['uid' => $user->uid, 'action' => 'email', 'email' => $superAdmin->email]
|
|
|
|
)->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.users.operations.email.existed', ['email' => $superAdmin->email]),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Set email successfully
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/users',
|
|
|
|
['uid' => $user->uid, 'action' => 'email', 'email' => 'a@b.c']
|
|
|
|
)->seeJson([
|
|
|
|
'errno' => 0,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.users.operations.email.success'),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
$this->seeInDatabase('users', [
|
|
|
|
'uid' => $user->uid,
|
2019-03-02 22:58:37 +08:00
|
|
|
'email' => 'a@b.c',
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
2018-08-17 14:44:22 +08:00
|
|
|
// Toggle verification
|
|
|
|
$this->postJson(
|
|
|
|
'/admin/users',
|
|
|
|
['uid' => $user->uid, 'action' => 'verification']
|
|
|
|
)->seeJson([
|
|
|
|
'errno' => 0,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.users.operations.verification.success'),
|
2018-08-17 14:44:22 +08:00
|
|
|
]);
|
|
|
|
$this->seeInDatabase('users', [
|
|
|
|
'uid' => $user->uid,
|
2019-03-02 22:58:37 +08:00
|
|
|
'verified' => 0,
|
2018-08-17 14:44:22 +08:00
|
|
|
]);
|
|
|
|
|
2017-11-02 16:50:00 +08:00
|
|
|
// Action is `nickname` but without `nickname` field
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/users',
|
|
|
|
['uid' => $user->uid, 'action' => 'nickname'],
|
2018-08-17 14:44:22 +08:00
|
|
|
['Accept' => 'application/json']
|
2017-11-02 16:50:00 +08:00
|
|
|
)->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('validation.required', ['attribute' => 'nickname']),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
2018-06-19 11:51:34 +08:00
|
|
|
// Action is `nickname` but with an invalid nickname
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/users',
|
|
|
|
['uid' => $user->uid, 'action' => 'nickname', 'nickname' => '\\'],
|
2018-08-17 14:44:22 +08:00
|
|
|
['Accept' => 'application/json']
|
2017-11-02 16:50:00 +08:00
|
|
|
)->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('validation.no_special_chars', ['attribute' => 'nickname']),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Set nickname successfully
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/users',
|
|
|
|
['uid' => $user->uid, 'action' => 'nickname', 'nickname' => 'nickname']
|
|
|
|
)->seeJson([
|
|
|
|
'errno' => 0,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.users.operations.nickname.success', ['new' => 'nickname']),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
$this->seeInDatabase('users', [
|
|
|
|
'uid' => $user->uid,
|
2019-03-02 22:58:37 +08:00
|
|
|
'nickname' => 'nickname',
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Action is `password` but without `password` field
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/users',
|
|
|
|
['uid' => $user->uid, 'action' => 'password'],
|
2018-08-17 14:44:22 +08:00
|
|
|
['Accept' => 'application/json']
|
2017-11-02 16:50:00 +08:00
|
|
|
)->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('validation.required', ['attribute' => 'password']),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Set a too short password
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/users',
|
|
|
|
['uid' => $user->uid, 'action' => 'password', 'password' => '1'],
|
2018-08-17 14:44:22 +08:00
|
|
|
['Accept' => 'application/json']
|
2017-11-02 16:50:00 +08:00
|
|
|
)->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('validation.min.string', ['attribute' => 'password', 'min' => 8]),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Set a too long password
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/users',
|
2019-02-27 23:44:50 +08:00
|
|
|
['uid' => $user->uid, 'action' => 'password', 'password' => Str::random(17)],
|
2018-08-17 14:44:22 +08:00
|
|
|
['Accept' => 'application/json']
|
2017-11-02 16:50:00 +08:00
|
|
|
)->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('validation.max.string', ['attribute' => 'password', 'max' => 16]),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Set password successfully
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/users',
|
|
|
|
['uid' => $user->uid, 'action' => 'password', 'password' => '12345678']
|
|
|
|
)->seeJson([
|
|
|
|
'errno' => 0,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.users.operations.password.success'),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
$user = User::find($user->uid);
|
|
|
|
$this->assertTrue($user->verifyPassword('12345678'));
|
|
|
|
|
|
|
|
// Action is `score` but without `score` field
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/users',
|
|
|
|
['uid' => $user->uid, 'action' => 'score'],
|
2018-08-17 14:44:22 +08:00
|
|
|
['Accept' => 'application/json']
|
2017-11-02 16:50:00 +08:00
|
|
|
)->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('validation.required', ['attribute' => 'score']),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Action is `score` but with an not-an-integer value
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/users',
|
|
|
|
['uid' => $user->uid, 'action' => 'score', 'score' => 'string'],
|
2018-08-17 14:44:22 +08:00
|
|
|
['Accept' => 'application/json']
|
2017-11-02 16:50:00 +08:00
|
|
|
)->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('validation.integer', ['attribute' => 'score']),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Set score successfully
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/users',
|
|
|
|
['uid' => $user->uid, 'action' => 'score', 'score' => 123]
|
|
|
|
)->seeJson([
|
|
|
|
'errno' => 0,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.users.operations.score.success'),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
$this->seeInDatabase('users', [
|
|
|
|
'uid' => $user->uid,
|
2019-03-02 22:58:37 +08:00
|
|
|
'score' => 123,
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
2019-03-18 13:24:03 +08:00
|
|
|
// Invalid permission value
|
|
|
|
$this->postJson('/admin/users', [
|
|
|
|
'uid' => $user->uid,
|
|
|
|
'action' => 'permission',
|
|
|
|
'permission' => -2
|
|
|
|
])->seeJson([
|
|
|
|
'errno' => 1,
|
|
|
|
'msg' => trans('validation.in', ['attribute' => 'permission']),
|
|
|
|
]);
|
2017-11-02 16:50:00 +08:00
|
|
|
$user = User::find($user->uid);
|
|
|
|
$this->assertEquals(User::NORMAL, $user->getPermission());
|
|
|
|
|
2019-03-18 13:24:03 +08:00
|
|
|
// Update permission successfully
|
|
|
|
$this->postJson('/admin/users', [
|
|
|
|
'uid' => $user->uid,
|
|
|
|
'action' => 'permission',
|
|
|
|
'permission' => -1
|
|
|
|
])->seeJson([
|
|
|
|
'errno' => 0,
|
|
|
|
'msg' => trans('admin.users.operations.permission'),
|
|
|
|
]);
|
2017-11-02 16:50:00 +08:00
|
|
|
$user = User::find($user->uid);
|
2019-03-18 13:24:03 +08:00
|
|
|
$this->assertEquals(User::BANNED, $user->getPermission());
|
2017-11-02 16:50:00 +08:00
|
|
|
|
|
|
|
// Delete a user
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/users', ['uid' => $user->uid, 'action' => 'delete'])
|
2017-11-02 16:50:00 +08:00
|
|
|
->seeJson([
|
|
|
|
'errno' => 0,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.users.operations.delete.success'),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
$this->assertNull(User::find($user->uid));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPlayerAjaxHandler()
|
|
|
|
{
|
|
|
|
$player = factory(Player::class)->create();
|
|
|
|
|
|
|
|
// Operate on a not-existed player
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/players', ['pid' => -1])
|
2017-11-02 16:50:00 +08:00
|
|
|
->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('general.unexistent-player'),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// An admin cannot operate another admin's player
|
|
|
|
$admin = factory(User::class, 'admin')->create();
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/players',
|
|
|
|
['pid' => factory(Player::class)->create(['uid' => $admin->uid])->pid]
|
|
|
|
)->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.players.no-permission'),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
$superAdmin = factory(User::class, 'superAdmin')->create();
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/players',
|
|
|
|
['pid' => factory(Player::class)->create(['uid' => $superAdmin->uid])->pid]
|
|
|
|
)->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.players.no-permission'),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
// For self is OK
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->actAs($admin)->postJson(
|
2017-11-02 16:50:00 +08:00
|
|
|
'/admin/players',
|
|
|
|
['pid' => factory(Player::class)->create(['uid' => $admin->uid])->pid]
|
|
|
|
)->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.users.operations.invalid'),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
2019-03-02 21:13:17 +08:00
|
|
|
// Change texture without `type` field
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/players', [
|
2017-11-02 16:50:00 +08:00
|
|
|
'pid' => $player->pid,
|
2019-03-02 22:58:37 +08:00
|
|
|
'action' => 'texture',
|
2018-08-12 10:01:13 +08:00
|
|
|
], [
|
|
|
|
'Accept' => 'application/json',
|
|
|
|
])->seeJson([
|
2017-11-02 16:50:00 +08:00
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('validation.required', ['attribute' => 'type']),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Change texture without `tid` field
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/players', [
|
2017-11-02 16:50:00 +08:00
|
|
|
'pid' => $player->pid,
|
|
|
|
'action' => 'texture',
|
2019-03-02 22:58:37 +08:00
|
|
|
'type' => 'skin',
|
2018-08-12 10:01:13 +08:00
|
|
|
], [
|
|
|
|
'Accept' => 'application/json',
|
|
|
|
])->seeJson([
|
2017-11-02 16:50:00 +08:00
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('validation.required', ['attribute' => 'tid']),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Change texture with a not-integer value
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/players', [
|
2017-11-02 16:50:00 +08:00
|
|
|
'pid' => $player->pid,
|
|
|
|
'action' => 'texture',
|
2019-03-02 21:13:17 +08:00
|
|
|
'type' => 'skin',
|
2019-03-02 22:58:37 +08:00
|
|
|
'tid' => 'string',
|
2018-08-12 10:01:13 +08:00
|
|
|
], [
|
|
|
|
'Accept' => 'application/json',
|
|
|
|
])->seeJson([
|
2017-11-02 16:50:00 +08:00
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('validation.integer', ['attribute' => 'tid']),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Invalid texture
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/players', [
|
2017-11-02 16:50:00 +08:00
|
|
|
'pid' => $player->pid,
|
|
|
|
'action' => 'texture',
|
2019-03-02 21:13:17 +08:00
|
|
|
'type' => 'skin',
|
2019-03-02 22:58:37 +08:00
|
|
|
'tid' => -1,
|
2017-11-02 16:50:00 +08:00
|
|
|
])->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.players.textures.non-existent', ['tid' => -1]),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
2019-03-02 21:13:17 +08:00
|
|
|
$skin = factory(Texture::class)->create();
|
2017-11-02 16:50:00 +08:00
|
|
|
$cape = factory(Texture::class, 'cape')->create();
|
|
|
|
|
2019-03-02 21:13:17 +08:00
|
|
|
// Skin
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/players', [
|
2017-11-02 16:50:00 +08:00
|
|
|
'pid' => $player->pid,
|
|
|
|
'action' => 'texture',
|
2019-03-02 21:13:17 +08:00
|
|
|
'type' => 'skin',
|
2019-03-02 22:58:37 +08:00
|
|
|
'tid' => $skin->tid,
|
2017-11-02 16:50:00 +08:00
|
|
|
])->seeJson([
|
|
|
|
'errno' => 0,
|
2019-03-13 13:16:51 +08:00
|
|
|
'msg' => trans('admin.players.textures.success', ['player' => $player->name]),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
$player = Player::find($player->pid);
|
2019-03-02 21:13:17 +08:00
|
|
|
$this->assertEquals($skin->tid, $player->tid_skin);
|
2017-11-02 16:50:00 +08:00
|
|
|
|
|
|
|
// Cape
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/players', [
|
2017-11-02 16:50:00 +08:00
|
|
|
'pid' => $player->pid,
|
|
|
|
'action' => 'texture',
|
2019-03-02 21:13:17 +08:00
|
|
|
'type' => 'cape',
|
2019-03-02 22:58:37 +08:00
|
|
|
'tid' => $cape->tid,
|
2017-11-02 16:50:00 +08:00
|
|
|
])->seeJson([
|
|
|
|
'errno' => 0,
|
2019-03-13 13:16:51 +08:00
|
|
|
'msg' => trans('admin.players.textures.success', ['player' => $player->name]),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
$player = Player::find($player->pid);
|
|
|
|
$this->assertEquals($cape->tid, $player->tid_cape);
|
|
|
|
|
|
|
|
// Reset texture
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/players', [
|
2017-11-02 16:50:00 +08:00
|
|
|
'pid' => $player->pid,
|
|
|
|
'action' => 'texture',
|
2019-03-02 21:13:17 +08:00
|
|
|
'type' => 'skin',
|
2019-03-02 22:58:37 +08:00
|
|
|
'tid' => 0,
|
2017-11-02 16:50:00 +08:00
|
|
|
])->seeJson([
|
|
|
|
'errno' => 0,
|
2019-03-13 13:16:51 +08:00
|
|
|
'msg' => trans('admin.players.textures.success', ['player' => $player->name]),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
$player = Player::find($player->pid);
|
2019-03-02 21:13:17 +08:00
|
|
|
$this->assertEquals(0, $player->tid_skin);
|
2017-11-02 16:50:00 +08:00
|
|
|
$this->assertNotEquals(0, $player->tid_cape);
|
2019-03-02 21:13:17 +08:00
|
|
|
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/players', [
|
2017-11-02 16:50:00 +08:00
|
|
|
'pid' => $player->pid,
|
|
|
|
'action' => 'texture',
|
2019-03-02 21:13:17 +08:00
|
|
|
'type' => 'cape',
|
2019-03-02 22:58:37 +08:00
|
|
|
'tid' => 0,
|
2017-11-02 16:50:00 +08:00
|
|
|
])->seeJson([
|
|
|
|
'errno' => 0,
|
2019-03-13 13:16:51 +08:00
|
|
|
'msg' => trans('admin.players.textures.success', ['player' => $player->name]),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
$player = Player::find($player->pid);
|
|
|
|
$this->assertEquals(0, $player->tid_cape);
|
|
|
|
|
|
|
|
// Change owner without `uid` field
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/players', [
|
2017-11-02 16:50:00 +08:00
|
|
|
'pid' => $player->pid,
|
2019-03-02 22:58:37 +08:00
|
|
|
'action' => 'owner',
|
2018-08-12 10:01:13 +08:00
|
|
|
], [
|
|
|
|
'Accept' => 'application/json',
|
|
|
|
])->seeJson([
|
2017-11-02 16:50:00 +08:00
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('validation.required', ['attribute' => 'uid']),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Change owner with a not-integer `uid` value
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/players', [
|
2017-11-02 16:50:00 +08:00
|
|
|
'pid' => $player->pid,
|
|
|
|
'action' => 'owner',
|
2019-03-02 22:58:37 +08:00
|
|
|
'uid' => 'string',
|
2018-08-12 10:01:13 +08:00
|
|
|
], [
|
|
|
|
'Accept' => 'application/json',
|
|
|
|
])->seeJson([
|
2017-11-02 16:50:00 +08:00
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('validation.integer', ['attribute' => 'uid']),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Change owner to a not-existed user
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/players', [
|
2017-11-02 16:50:00 +08:00
|
|
|
'pid' => $player->pid,
|
|
|
|
'action' => 'owner',
|
2019-03-02 22:58:37 +08:00
|
|
|
'uid' => -1,
|
2017-11-02 16:50:00 +08:00
|
|
|
])->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.users.operations.non-existent'),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Change owner successfully
|
|
|
|
$user = factory(User::class)->create();
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/players', [
|
2017-11-02 16:50:00 +08:00
|
|
|
'pid' => $player->pid,
|
|
|
|
'action' => 'owner',
|
2019-03-02 22:58:37 +08:00
|
|
|
'uid' => $user->uid,
|
2017-11-02 16:50:00 +08:00
|
|
|
])->seeJson([
|
|
|
|
'errno' => 0,
|
|
|
|
'msg' => trans(
|
|
|
|
'admin.players.owner.success',
|
2019-03-13 13:16:51 +08:00
|
|
|
['player' => $player->name, 'user' => $user->nickname]
|
2019-03-02 22:58:37 +08:00
|
|
|
),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Rename a player without `name` field
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/players', [
|
2017-11-02 16:50:00 +08:00
|
|
|
'pid' => $player->pid,
|
2019-03-02 22:58:37 +08:00
|
|
|
'action' => 'name',
|
2018-08-12 10:01:13 +08:00
|
|
|
], [
|
|
|
|
'Accept' => 'application/json',
|
|
|
|
])->seeJson([
|
2017-11-02 16:50:00 +08:00
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('validation.required', ['attribute' => 'name']),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Rename a player successfully
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/players', [
|
2017-11-02 16:50:00 +08:00
|
|
|
'pid' => $player->pid,
|
|
|
|
'action' => 'name',
|
2019-03-02 22:58:37 +08:00
|
|
|
'name' => 'new_name',
|
2017-11-02 16:50:00 +08:00
|
|
|
])->seeJson([
|
|
|
|
'errno' => 0,
|
|
|
|
'msg' => trans('admin.players.name.success', ['player' => 'new_name']),
|
2019-03-02 22:58:37 +08:00
|
|
|
'name' => 'new_name',
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Delete a player
|
2018-08-17 14:44:22 +08:00
|
|
|
$this->postJson('/admin/players', [
|
2017-11-02 16:50:00 +08:00
|
|
|
'pid' => $player->pid,
|
2019-03-02 22:58:37 +08:00
|
|
|
'action' => 'delete',
|
2017-11-02 16:50:00 +08:00
|
|
|
])->seeJson([
|
|
|
|
'errno' => 0,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => trans('admin.players.delete.success'),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
$this->assertNull(Player::find($player->pid));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetOneUser()
|
|
|
|
{
|
|
|
|
$user = factory(User::class)->create();
|
|
|
|
$this->get('/admin/user/'.$user->uid)
|
|
|
|
->seeJson([
|
|
|
|
'errno' => 0,
|
|
|
|
'msg' => 'success',
|
|
|
|
'user' => [
|
|
|
|
'uid' => $user->uid,
|
|
|
|
'email' => $user->email,
|
|
|
|
'nickname' => $user->nickname,
|
|
|
|
'score' => $user->score,
|
|
|
|
'avatar' => $user->avatar,
|
2018-08-17 12:32:44 +08:00
|
|
|
'permission' => $user->permission,
|
|
|
|
'verified' => (bool) $user->verified,
|
2019-03-02 22:58:37 +08:00
|
|
|
'verification_token' => (string) $user->verification_token,
|
|
|
|
],
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->get('/admin/user/-1')
|
|
|
|
->seeJson([
|
|
|
|
'errno' => 1,
|
2019-03-02 22:58:37 +08:00
|
|
|
'msg' => 'No such user.',
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|