upgrade Laravel to 8

This commit is contained in:
Pig Fang 2020-10-14 11:56:34 +08:00
parent a5921770f0
commit 311b0690fc
No known key found for this signature in database
GPG Key ID: A8198F548DADA9E2
52 changed files with 1400 additions and 618 deletions

View File

@ -5,6 +5,7 @@ namespace App\Models;
use App\Events\PlayerProfileUpdated; use App\Events\PlayerProfileUpdated;
use App\Models; use App\Models;
use DateTimeInterface; use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Lorisleiva\LaravelSearchString\Concerns\SearchString; use Lorisleiva\LaravelSearchString\Concerns\SearchString;
@ -23,6 +24,7 @@ use Lorisleiva\LaravelSearchString\Concerns\SearchString;
*/ */
class Player extends Model class Player extends Model
{ {
use HasFactory;
use SearchString; use SearchString;
public const CREATED_AT = null; public const CREATED_AT = null;

View File

@ -4,6 +4,7 @@ namespace App\Models;
use DateTimeInterface; use DateTimeInterface;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
@ -23,6 +24,8 @@ use Illuminate\Support\Carbon;
*/ */
class Texture extends Model class Texture extends Model
{ {
use HasFactory;
public $primaryKey = 'tid'; public $primaryKey = 'tid';
public const CREATED_AT = 'upload_at'; public const CREATED_AT = 'upload_at';
public const UPDATED_AT = null; public const UPDATED_AT = null;

View File

@ -4,6 +4,7 @@ namespace App\Models;
use App\Models\Concerns\HasPassword; use App\Models\Concerns\HasPassword;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens; use Laravel\Passport\HasApiTokens;
@ -30,6 +31,7 @@ use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends Authenticatable implements JWTSubject class User extends Authenticatable implements JWTSubject
{ {
use Notifiable; use Notifiable;
use HasFactory;
use HasPassword; use HasPassword;
use HasApiTokens; use HasApiTokens;
use SearchString; use SearchString;

View File

@ -4,6 +4,7 @@ namespace App\Providers;
use App\Services; use App\Services;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider class AppServiceProvider extends ServiceProvider
@ -18,6 +19,8 @@ class AppServiceProvider extends ServiceProvider
public function boot(Request $request) public function boot(Request $request)
{ {
Paginator::useBootstrap();
$this->configureUrlGenerator($request); $this->configureUrlGenerator($request);
} }

View File

@ -24,36 +24,33 @@
"gregwar/captcha": "1.*", "gregwar/captcha": "1.*",
"guzzlehttp/guzzle": "^7.0", "guzzlehttp/guzzle": "^7.0",
"intervention/image": "^2.5", "intervention/image": "^2.5",
"laravel/framework": "^7.0", "laravel/framework": "^8.0",
"laravel/passport": "^9.2", "laravel/passport": "^10.0",
"lorisleiva/laravel-search-string": "^0.1.6", "lorisleiva/laravel-search-string": "^1.0",
"nesbot/carbon": "^2.0", "nesbot/carbon": "^2.0",
"nunomaduro/collision": "^4.1", "nunomaduro/collision": "^5.0",
"rcrowe/twigbridge": "^0.11.3", "rcrowe/twigbridge": "^0.12",
"spatie/laravel-translation-loader": "^2.6", "spatie/laravel-translation-loader": "^2.6",
"symfony/process": "^5.0", "symfony/process": "^5.0",
"symfony/yaml": "^5.0", "symfony/yaml": "^5.0",
"twig/twig": "^2.11", "twig/twig": "^2.11",
"tymon/jwt-auth": "dev-develop", "tymon/jwt-auth": "^1.0",
"vectorface/whip": "^0.3.2" "vectorface/whip": "^0.3.2"
}, },
"require-dev": { "require-dev": {
"barryvdh/laravel-debugbar": "^3.2", "barryvdh/laravel-debugbar": "^3.5",
"fzaninotto/faker": "~1.9", "fzaninotto/faker": "~1.9",
"laravel/browser-kit-testing": "^6.0", "laravel/browser-kit-testing": "^6.1",
"laravel/tinker": "^2.2", "laravel/tinker": "^2.4",
"mockery/mockery": "1.3.*", "mockery/mockery": "^1.4",
"phpunit/phpunit": "^9.4", "phpunit/phpunit": "^9.4",
"symfony/css-selector": "^5.0", "symfony/css-selector": "^5.0",
"symfony/dom-crawler": "^5.0" "symfony/dom-crawler": "^5.0"
}, },
"autoload": { "autoload": {
"classmap": [
"app/Models",
"database"
],
"psr-4": { "psr-4": {
"App\\": "app/" "App\\": "app/",
"Database\\Factories\\": "database/factories/"
}, },
"files": [ "files": [
"app/helpers.php" "app/helpers.php"

1296
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,21 @@
<?php
namespace Database\Factories;
use App\Models\Player;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class PlayerFactory extends Factory
{
protected $model = Player::class;
public function definition()
{
return [
'uid' => User::factory(),
'name' => $this->faker->firstName,
'tid_skin' => 0,
];
}
}

View File

@ -1,12 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use App\Models\Player;
$factory->define(Player::class, function (Faker\Generator $faker) {
return [
'uid' => factory(App\Models\User::class)->create()->uid,
'name' => $faker->firstName,
'tid_skin' => 0,
];
});

View File

@ -0,0 +1,41 @@
<?php
namespace Database\Factories;
use App\Models\Texture;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class TextureFactory extends Factory
{
protected $model = Texture::class;
public function definition()
{
return [
'name' => $this->faker->firstName,
'type' => 'steve',
'hash' => $this->faker->sha256,
'size' => rand(1, 2048),
'likes' => rand(1, 10),
'uploader' => User::factory(),
'public' => true,
'upload_at' => $this->faker->dateTime,
];
}
public function alex()
{
return $this->state(['type' => 'alex']);
}
public function cape()
{
return $this->state(['type' => 'cape']);
}
public function private()
{
return $this->state(['public' => false]);
}
}

View File

@ -1,23 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use App\Models\Texture;
$factory->define(Texture::class, function (Faker\Generator $faker) {
return [
'name' => $faker->firstName,
'type' => 'steve',
'hash' => $faker->sha256,
'size' => rand(1, 2048),
'likes' => rand(1, 10),
'uploader' => factory(App\Models\User::class)->create()->uid,
'public' => true,
'upload_at' => $faker->dateTime,
];
});
$factory->state(Texture::class, 'alex', ['type' => 'alex']);
$factory->state(Texture::class, 'cape', ['type' => 'cape']);
$factory->state(Texture::class, 'private', ['public' => false]);

View File

@ -0,0 +1,44 @@
<?php
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class UserFactory extends Factory
{
protected $model = User::class;
public function definition()
{
return [
'email' => $this->faker->email,
'nickname' => $this->faker->name,
'locale' => null,
'score' => 1000,
'avatar' => 0,
'password' => app('cipher')->hash(Str::random(10), config('secure.salt')),
'ip' => $this->faker->ipv4,
'permission' => 0,
'verified' => true,
'last_sign_at' => $this->faker->dateTime->format('d-M-Y H:i:s'),
'register_at' => $this->faker->dateTime->format('d-M-Y H:i:s'),
];
}
public function admin()
{
return $this->state(['permission' => 1]);
}
public function superAdmin()
{
return $this->state(['permission' => 2]);
}
public function banned()
{
return $this->state(['permission' => -1]);
}
}

View File

@ -1,27 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use App\Models\User;
use Illuminate\Support\Str;
$factory->define(User::class, function (Faker\Generator $faker) {
return [
'email' => $faker->email,
'nickname' => $faker->name,
'locale' => null,
'score' => 1000,
'avatar' => 0,
'password' => app('cipher')->hash(Str::random(10), config('secure.salt')),
'ip' => '127.0.0.1',
'permission' => 0,
'verified' => true,
'last_sign_at' => $faker->dateTime->format('d-M-Y H:i:s'),
'register_at' => $faker->dateTime->format('d-M-Y H:i:s'),
];
});
$factory->state(User::class, 'admin', ['permission' => 1]);
$factory->state(User::class, 'superAdmin', ['permission' => 2]);
$factory->state(User::class, 'banned', ['permission' => -1]);

View File

@ -2,6 +2,10 @@
define('LARAVEL_START', microtime(true)); define('LARAVEL_START', microtime(true));
if (file_exists(__DIR__.'/../storage/framework/maintenance.php')) {
require __DIR__.'/../storage/framework/maintenance.php';
}
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Register The Auto Loader | Register The Auto Loader

View File

@ -8,7 +8,7 @@ class HandlerTest extends TestCase
{ {
public function testRenderAjaxException() public function testRenderAjaxException()
{ {
$json = $this->get('/abc', ['Accept' => 'application/json'])->decodeResponseJson(); $json = $this->get('/abc', ['Accept' => 'application/json'])->json();
$this->assertIsString($json['message']); $this->assertIsString($json['message']);
$this->assertTrue($json['exception']); $this->assertTrue($json['exception']);
$this->assertTrue(collect($json['trace'])->every( $this->assertTrue(collect($json['trace'])->every(

View File

@ -15,7 +15,7 @@ class AdminControllerTest extends TestCase
{ {
// Do not use `WithoutMiddleware` trait // Do not use `WithoutMiddleware` trait
parent::setUp(); parent::setUp();
$this->actingAs(factory(\App\Models\User::class)->states('admin')->create()); $this->actingAs(User::factory()->admin()->create());
} }
public function testIndex() public function testIndex()
@ -28,9 +28,9 @@ class AdminControllerTest extends TestCase
public function testChartData() public function testChartData()
{ {
factory(User::class)->create(); User::factory()->create();
factory(User::class)->create(['register_at' => '2019-01-01 00:00:00']); User::factory()->create(['register_at' => '2019-01-01 00:00:00']);
factory(Texture::class)->create(); Texture::factory()->create();
$this->getJson('/admin/chart') $this->getJson('/admin/chart')
->assertJson(['labels' => [ ->assertJson(['labels' => [
trans('admin.index.user-registration'), trans('admin.index.user-registration'),

View File

@ -45,9 +45,9 @@ class AuthControllerTest extends TestCase
{ {
Event::fake(); Event::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
$user->changePassword('12345678'); $user->changePassword('12345678');
$player = factory(Player::class)->create(['uid' => $user->uid]); $player = Player::factory()->create(['uid' => $user->uid]);
// Should return a warning if `identification` is empty // Should return a warning if `identification` is empty
$this->postJson('/auth/login')->assertJsonValidationErrors('identification'); $this->postJson('/auth/login')->assertJsonValidationErrors('identification');
@ -218,7 +218,7 @@ class AuthControllerTest extends TestCase
{ {
Event::fake(); Event::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
$this->actingAs($user)->postJson('/auth/logout')->assertJson( $this->actingAs($user)->postJson('/auth/logout')->assertJson(
[ [
'code' => 0, 'code' => 0,
@ -263,7 +263,7 @@ class AuthControllerTest extends TestCase
)->assertJsonValidationErrors('email'); )->assertJsonValidationErrors('email');
// An existed user // An existed user
$existedUser = factory(User::class)->create(); $existedUser = User::factory()->create();
$this->postJson( $this->postJson(
'/auth/register', '/auth/register',
['email' => $existedUser->email] ['email' => $existedUser->email]
@ -328,7 +328,7 @@ class AuthControllerTest extends TestCase
)->assertJsonValidationErrors('player_name'); )->assertJsonValidationErrors('player_name');
// Existed player // Existed player
$player = factory(Player::class)->create(); $player = Player::factory()->create();
$this->postJson( $this->postJson(
'/auth/register', '/auth/register',
[ [
@ -559,7 +559,7 @@ class AuthControllerTest extends TestCase
$this->flushSession(); $this->flushSession();
// Should return a warning if user is not existed // Should return a warning if user is not existed
$user = factory(User::class)->create(); $user = User::factory()->create();
$this->withSession(['phrase' => 'a'])->postJson('/auth/forgot', [ $this->withSession(['phrase' => 'a'])->postJson('/auth/forgot', [
'email' => 'nope@nope.net', 'email' => 'nope@nope.net',
'captcha' => 'a', 'captcha' => 'a',
@ -630,7 +630,7 @@ class AuthControllerTest extends TestCase
public function testReset() public function testReset()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
$url = URL::temporarySignedRoute( $url = URL::temporarySignedRoute(
'auth.reset', 'auth.reset',
Carbon::now()->addHour(), Carbon::now()->addHour(),
@ -651,7 +651,7 @@ class AuthControllerTest extends TestCase
{ {
Event::fake(); Event::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
$url = URL::temporarySignedRoute( $url = URL::temporarySignedRoute(
'auth.reset', 'auth.reset',
Carbon::now()->addHour(), Carbon::now()->addHour(),
@ -711,8 +711,8 @@ class AuthControllerTest extends TestCase
public function testFillEmail() public function testFillEmail()
{ {
$user = factory(User::class)->create(['email' => '']); $user = User::factory()->create(['email' => '']);
$other = factory(User::class)->create(); $other = User::factory()->create();
$this->actingAs($user)->post('/auth/bind')->assertRedirect('/'); $this->actingAs($user)->post('/auth/bind')->assertRedirect('/');
$this->actingAs($user)->post('/auth/bind', ['email' => 'a'])->assertRedirect('/'); $this->actingAs($user)->post('/auth/bind', ['email' => 'a'])->assertRedirect('/');
$this->actingAs($user)->post('/auth/bind', ['email' => $other->email])->assertRedirect('/'); $this->actingAs($user)->post('/auth/bind', ['email' => $other->email])->assertRedirect('/');
@ -734,14 +734,14 @@ class AuthControllerTest extends TestCase
// invalid link // invalid link
$this->get(route('auth.verify', ['user' => 1]))->assertForbidden(); $this->get(route('auth.verify', ['user' => 1]))->assertForbidden();
$user = factory(User::class)->create(['verified' => false]); $user = User::factory()->create(['verified' => false]);
$url = URL::signedRoute('auth.verify', ['user' => $user], null, false); $url = URL::signedRoute('auth.verify', ['user' => $user], null, false);
$this->get($url)->assertViewIs('auth.verify'); $this->get($url)->assertViewIs('auth.verify');
} }
public function testHandleVerify() public function testHandleVerify()
{ {
$user = factory(User::class)->create(['verified' => false]); $user = User::factory()->create(['verified' => false]);
$url = URL::signedRoute('auth.verify', ['user' => $user], null, false); $url = URL::signedRoute('auth.verify', ['user' => $user], null, false);
// empty email // empty email
@ -761,14 +761,14 @@ class AuthControllerTest extends TestCase
public function testApiLogin() public function testApiLogin()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
$user->changePassword('12345678'); $user->changePassword('12345678');
$this->postJson('/api/auth/login')->assertJson(['token' => false]); $this->postJson('/api/auth/login')->assertJson(['token' => false]);
$token = $this->postJson('/api/auth/login', [ $token = $this->postJson('/api/auth/login', [
'email' => $user->email, 'email' => $user->email,
'password' => '12345678', 'password' => '12345678',
])->decodeResponseJson('token'); ])->json('token');
$this->assertTrue(is_string($token)); $this->assertTrue(is_string($token));
$this->postJson('/api/auth/login', [ $this->postJson('/api/auth/login', [
@ -779,12 +779,12 @@ class AuthControllerTest extends TestCase
public function testApiLogout() public function testApiLogout()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
$user->changePassword('12345678'); $user->changePassword('12345678');
$token = $this->postJson('/api/auth/login', [ $token = $this->postJson('/api/auth/login', [
'email' => $user->email, 'email' => $user->email,
'password' => '12345678', 'password' => '12345678',
])->decodeResponseJson('token'); ])->json('token');
$this->post('/api/auth/logout', [], [ $this->post('/api/auth/logout', [], [
'Authorization' => "Bearer $token", 'Authorization' => "Bearer $token",
@ -793,16 +793,16 @@ class AuthControllerTest extends TestCase
public function testApiRefresh() public function testApiRefresh()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
$user->changePassword('12345678'); $user->changePassword('12345678');
$token = $this->postJson('/api/auth/login', [ $token = $this->postJson('/api/auth/login', [
'email' => $user->email, 'email' => $user->email,
'password' => '12345678', 'password' => '12345678',
])->decodeResponseJson('token'); ])->json('token');
$token = $this->postJson('/api/auth/refresh', [], [ $token = $this->postJson('/api/auth/refresh', [], [
'Authorization' => "Bearer $token", 'Authorization' => "Bearer $token",
])->decodeResponseJson('token'); ])->json('token');
$this->assertTrue(is_string($token)); $this->assertTrue(is_string($token));
} }
} }

View File

@ -15,7 +15,7 @@ class ClosetControllerTest extends TestCase
public function testIndex() public function testIndex()
{ {
$filter = Fakes\Filter::fake(); $filter = Fakes\Filter::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
$this->actingAs($user)->get('/user/closet')->assertViewIs('user.closet'); $this->actingAs($user)->get('/user/closet')->assertViewIs('user.closet');
$filter->assertApplied('grid:user.closet'); $filter->assertApplied('grid:user.closet');
@ -23,8 +23,8 @@ class ClosetControllerTest extends TestCase
public function testGetClosetData() public function testGetClosetData()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
$textures = factory(Texture::class, 10)->create(); $textures = Texture::factory()->count(10)->create();
$textures->each(function ($t) use ($user) { $textures->each(function ($t) use ($user) {
$user->closet()->attach($t->tid, ['item_name' => $t->name]); $user->closet()->attach($t->tid, ['item_name' => $t->name]);
}); });
@ -37,7 +37,7 @@ class ClosetControllerTest extends TestCase
]); ]);
// Get capes // Get capes
$cape = factory(Texture::class)->states('cape')->create(); $cape = Texture::factory()->cape()->create();
$user->closet()->attach($cape->tid, ['item_name' => 'custom_name']); $user->closet()->attach($cape->tid, ['item_name' => 'custom_name']);
$this->getJson('/user/closet/list?category=cape') $this->getJson('/user/closet/list?category=cape')
->assertJson(['data' => [[ ->assertJson(['data' => [[
@ -60,8 +60,8 @@ class ClosetControllerTest extends TestCase
public function testAllIds() public function testAllIds()
{ {
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$user = factory(User::class)->create(); $user = User::factory()->create();
$user->closet()->attach($texture->tid, ['item_name' => '']); $user->closet()->attach($texture->tid, ['item_name' => '']);
$this->actingAs($user) $this->actingAs($user)
@ -72,9 +72,9 @@ class ClosetControllerTest extends TestCase
public function testAdd() public function testAdd()
{ {
Event::fake(); Event::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
$uploader = factory(User::class)->create(['score' => 0]); $uploader = User::factory()->create(['score' => 0]);
$texture = factory(Texture::class)->create(['uploader' => $uploader->uid]); $texture = Texture::factory()->create(['uploader' => $uploader->uid]);
$likes = $texture->likes; $likes = $texture->likes;
$name = 'my'; $name = 'my';
option(['score_per_closet_item' => 10]); option(['score_per_closet_item' => 10]);
@ -157,7 +157,7 @@ class ClosetControllerTest extends TestCase
// texture is private // texture is private
option(['score_award_per_like' => 5]); option(['score_award_per_like' => 5]);
$privateTexture = factory(Texture::class)->create([ $privateTexture = Texture::factory()->create([
'public' => false, 'public' => false,
'uploader' => $uploader->uid + 1, 'uploader' => $uploader->uid + 1,
]); ]);
@ -170,10 +170,10 @@ class ClosetControllerTest extends TestCase
]); ]);
// administrator can add it. // administrator can add it.
$privateTexture = factory(Texture::class)->state('private')->create([ $privateTexture = Texture::factory()->private()->create([
'uploader' => 0, 'uploader' => 0,
]); ]);
$this->actingAs(factory(User::class)->state('admin')->create()) $this->actingAs(User::factory()->admin()->create())
->postJson( ->postJson(
route('user.closet.add'), route('user.closet.add'),
['tid' => $privateTexture->tid, 'name' => $name] ['tid' => $privateTexture->tid, 'name' => $name]
@ -232,8 +232,8 @@ class ClosetControllerTest extends TestCase
public function testRename() public function testRename()
{ {
Event::fake(); Event::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$name = 'new'; $name = 'new';
// missing `name` field // missing `name` field
@ -325,9 +325,9 @@ class ClosetControllerTest extends TestCase
public function testRemove() public function testRemove()
{ {
Event::fake(); Event::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
$uploader = factory(User::class)->create(['score' => 5]); $uploader = User::factory()->create(['score' => 5]);
$texture = factory(Texture::class)->create(['uploader' => $uploader->uid]); $texture = Texture::factory()->create(['uploader' => $uploader->uid]);
$likes = $texture->likes; $likes = $texture->likes;
// rename a not-existed texture // rename a not-existed texture

View File

@ -14,13 +14,13 @@ class ClosetManagementControllerTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->actingAs(factory(User::class)->states('admin')->create()); $this->actingAs(User::factory()->admin()->create());
} }
public function testList() public function testList()
{ {
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$admin = factory(User::class)->states('admin')->create(); $admin = User::factory()->admin()->create();
$admin->closet()->attach($texture->tid); $admin->closet()->attach($texture->tid);
$this->actingAs($admin, 'oauth') $this->actingAs($admin, 'oauth')
@ -31,8 +31,8 @@ class ClosetManagementControllerTest extends TestCase
public function testAdd() public function testAdd()
{ {
Event::fake(); Event::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$this->postJson('/admin/closet/'.$user->uid, ['tid' => $texture->tid]) $this->postJson('/admin/closet/'.$user->uid, ['tid' => $texture->tid])
->assertJson([ ->assertJson([
@ -70,8 +70,8 @@ class ClosetManagementControllerTest extends TestCase
public function testRemove() public function testRemove()
{ {
Event::fake(); Event::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$user->closet()->attach($texture->tid, ['item_name' => '']); $user->closet()->attach($texture->tid, ['item_name' => '']);
$this->deleteJson('/admin/closet/'.$user->uid, ['tid' => $texture->tid]) $this->deleteJson('/admin/closet/'.$user->uid, ['tid' => $texture->tid])

View File

@ -2,6 +2,7 @@
namespace Tests; namespace Tests;
use App\Models\User;
use App\Services\Plugin; use App\Services\Plugin;
use App\Services\PluginManager; use App\Services\PluginManager;
use App\Services\Unzip; use App\Services\Unzip;
@ -12,7 +13,7 @@ class MarketControllerTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->actingAs(factory(\App\Models\User::class)->states('superAdmin')->create()); $this->actingAs(User::factory()->superAdmin()->create());
} }
public function testDownload() public function testDownload()

View File

@ -11,8 +11,8 @@ class NotificationsControllerTest extends TestCase
{ {
public function testSend() public function testSend()
{ {
$admin = factory(User::class)->states('admin')->create(); $admin = User::factory()->admin()->create();
$normal = factory(User::class)->create(); $normal = User::factory()->create();
Notification::fake(); Notification::fake();
$this->actingAs($admin) $this->actingAs($admin)
@ -93,7 +93,7 @@ class NotificationsControllerTest extends TestCase
public function testAll() public function testAll()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
$notification = new Notifications\SiteMessage('title', 'content'); $notification = new Notifications\SiteMessage('title', 'content');
Notification::send([$user], $notification); Notification::send([$user], $notification);
@ -107,7 +107,7 @@ class NotificationsControllerTest extends TestCase
public function testRead() public function testRead()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
$user->notify(new Notifications\SiteMessage('Hyouka', 'Kotenbu?')); $user->notify(new Notifications\SiteMessage('Hyouka', 'Kotenbu?'));
$user->refresh(); $user->refresh();
$notification = $user->unreadNotifications->first(); $notification = $user->unreadNotifications->first();

View File

@ -2,6 +2,7 @@
namespace Tests; namespace Tests;
use App\Models\User;
use Cache; use Cache;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Mockery; use Mockery;
@ -18,7 +19,7 @@ class OptionsControllerTest extends BrowserKitTestCase
\App\Services\Translations\JavaScript::class, \App\Services\Translations\JavaScript::class,
Mockery::spy(\App\Services\Translations\JavaScript::class) Mockery::spy(\App\Services\Translations\JavaScript::class)
); );
$this->actingAs(factory(\App\Models\User::class)->states('admin')->create()); $this->actingAs(User::factory()->admin()->create());
} }
public function testCustomize() public function testCustomize()

View File

@ -17,7 +17,7 @@ class PlayerControllerTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->actingAs(factory(User::class)->create()); $this->actingAs(User::factory()->create());
} }
public function testIndex() public function testIndex()
@ -30,8 +30,8 @@ class PlayerControllerTest extends TestCase
public function testList() public function testList()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
$player = factory(Player::class)->create(['uid' => $user->uid]); $player = Player::factory()->create(['uid' => $user->uid]);
$this->actingAs($user) $this->actingAs($user)
->get('/user/player/list') ->get('/user/player/list')
->assertJson([$player->toArray()]); ->assertJson([$player->toArray()]);
@ -39,8 +39,8 @@ class PlayerControllerTest extends TestCase
public function testAccessControl() public function testAccessControl()
{ {
$user = factory(User::class)->make(); $user = User::factory()->make();
$player = factory(Player::class)->create(); $player = Player::factory()->create();
$this->actingAs($user) $this->actingAs($user)
->deleteJson(route('user.player.delete', ['player' => $player])) ->deleteJson(route('user.player.delete', ['player' => $player]))
@ -76,12 +76,12 @@ class PlayerControllerTest extends TestCase
// with an existed player name // with an existed player name
option(['player_name_rule' => 'official']); option(['player_name_rule' => 'official']);
$existed = factory(Player::class)->create(); $existed = Player::factory()->create();
$this->postJson(route('user.player.add'), ['name' => $existed->name]) $this->postJson(route('user.player.add'), ['name' => $existed->name])
->assertJsonValidationErrors('name'); ->assertJsonValidationErrors('name');
// Lack of score // Lack of score
$user = factory(User::class)->create(['score' => 0]); $user = User::factory()->create(['score' => 0]);
$this->actingAs($user)->postJson( $this->actingAs($user)->postJson(
route('user.player.add'), route('user.player.add'),
['name' => 'no_score'] ['name' => 'no_score']
@ -122,7 +122,7 @@ class PlayerControllerTest extends TestCase
// Allowed to use CJK characters // Allowed to use CJK characters
Event::fake(); Event::fake();
option(['player_name_rule' => 'cjk']); option(['player_name_rule' => 'cjk']);
$user = factory(User::class)->create(); $user = User::factory()->create();
$score = $user->score; $score = $user->score;
$this->actingAs($user)->postJson(route('user.player.add'), [ $this->actingAs($user)->postJson(route('user.player.add'), [
'name' => '角色名', 'name' => '角色名',
@ -165,8 +165,8 @@ class PlayerControllerTest extends TestCase
Event::fake(); Event::fake();
$filter = Fakes\Filter::fake(); $filter = Fakes\Filter::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
$player = factory(Player::class)->create(['uid' => $user->uid]); $player = Player::factory()->create(['uid' => $user->uid]);
$score = $user->score; $score = $user->score;
// rejected // rejected
@ -214,7 +214,7 @@ class PlayerControllerTest extends TestCase
// No returning score // No returning score
option(['return_score' => false]); option(['return_score' => false]);
$player = factory(Player::class)->create(); $player = Player::factory()->create();
$user = $player->user; $user = $player->user;
$this->actingAs($user) $this->actingAs($user)
->deleteJson(route('user.player.delete', ['player' => $player])) ->deleteJson(route('user.player.delete', ['player' => $player]))
@ -231,7 +231,7 @@ class PlayerControllerTest extends TestCase
public function testRename() public function testRename()
{ {
Event::fake(); Event::fake();
$player = factory(Player::class)->create(); $player = Player::factory()->create();
$user = $player->user; $user = $player->user;
// Without new player name // Without new player name
@ -254,7 +254,7 @@ class PlayerControllerTest extends TestCase
)->assertJsonValidationErrors('name'); )->assertJsonValidationErrors('name');
// with an existed player name // with an existed player name
$existed = factory(Player::class)->create(); $existed = Player::factory()->create();
$this->putJson( $this->putJson(
route('user.player.rename', ['player' => $player]), route('user.player.rename', ['player' => $player]),
['name' => $existed->name] ['name' => $existed->name]
@ -268,7 +268,7 @@ class PlayerControllerTest extends TestCase
return new Rejection('rejected'); return new Rejection('rejected');
}); });
factory(Player::class)->create()->name; Player::factory()->create()->name;
$this->putJson( $this->putJson(
route('user.player.rename', ['player' => $player]), route('user.player.rename', ['player' => $player]),
['name' => 'new'] ['name' => 'new']
@ -314,10 +314,10 @@ class PlayerControllerTest extends TestCase
public function testSetTexture() public function testSetTexture()
{ {
$player = factory(Player::class)->create(); $player = Player::factory()->create();
$user = $player->user; $user = $player->user;
$skin = factory(Texture::class)->create(); $skin = Texture::factory()->create();
$cape = factory(Texture::class)->state('cape')->create(); $cape = Texture::factory()->cape()->create();
// rejected // rejected
$filter = Fakes\Filter::fake(); $filter = Fakes\Filter::fake();
@ -341,7 +341,7 @@ class PlayerControllerTest extends TestCase
]); ]);
// set a private texture // set a private texture
$private = factory(Texture::class)->state('private')->create(); $private = Texture::factory()->private()->create();
$this->putJson( $this->putJson(
route('user.player.set', ['player' => $player]), route('user.player.set', ['player' => $player]),
['skin' => $private->tid] ['skin' => $private->tid]
@ -397,7 +397,7 @@ class PlayerControllerTest extends TestCase
public function testClearTexture() public function testClearTexture()
{ {
Event::fake(); Event::fake();
$player = factory(Player::class)->create(); $player = Player::factory()->create();
$user = $player->user; $user = $player->user;
$player->tid_skin = 1; $player->tid_skin = 1;

View File

@ -15,12 +15,12 @@ class PlayersManagementControllerTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->actingAs(factory(User::class)->states('admin')->create()); $this->actingAs(User::factory()->admin()->create());
} }
public function testList() public function testList()
{ {
$player = factory(Player::class)->create(); $player = Player::factory()->create();
$this->getJson(route('admin.players.list')) $this->getJson(route('admin.players.list'))
->assertJson(['data' => [$player->toArray()]]); ->assertJson(['data' => [$player->toArray()]]);
@ -29,9 +29,9 @@ class PlayersManagementControllerTest extends TestCase
public function testAccessControl() public function testAccessControl()
{ {
// an admin can't operate another admin's player // an admin can't operate another admin's player
$admin = factory(User::class)->states('admin')->create(); $admin = User::factory()->admin()->create();
/** @var Player */ /** @var Player */
$player = factory(Player::class)->create(['uid' => $admin->uid]); $player = Player::factory()->create(['uid' => $admin->uid]);
$this->putJson( $this->putJson(
route('admin.players.name', ['player' => $player->pid]), route('admin.players.name', ['player' => $player->pid]),
['player_name' => 'abcd'] ['player_name' => 'abcd']
@ -48,9 +48,9 @@ class PlayersManagementControllerTest extends TestCase
)->assertJson(['code' => 0]); )->assertJson(['code' => 0]);
// super admin // super admin
$superAdmin = factory(User::class)->states('superAdmin')->create(); $superAdmin = User::factory()->superAdmin()->create();
/** @var Player */ /** @var Player */
$player = factory(Player::class)->create(['uid' => $superAdmin->uid]); $player = Player::factory()->create(['uid' => $superAdmin->uid]);
$this->putJson( $this->putJson(
route('admin.players.name', ['player' => $player->pid]), route('admin.players.name', ['player' => $player->pid]),
['player_name' => 'abcd'] ['player_name' => 'abcd']
@ -63,7 +63,7 @@ class PlayersManagementControllerTest extends TestCase
public function testName() public function testName()
{ {
/** @var Player */ /** @var Player */
$player = factory(Player::class)->create(); $player = Player::factory()->create();
// missing `player_name` field // missing `player_name` field
$this->putJson( $this->putJson(
@ -113,7 +113,7 @@ class PlayersManagementControllerTest extends TestCase
Event::fake(); Event::fake();
/** @var Player */ /** @var Player */
$player = factory(Player::class)->create(); $player = Player::factory()->create();
// missing `uid` field // missing `uid` field
$this->putJson(route('admin.players.owner', ['player' => $player->pid])) $this->putJson(route('admin.players.owner', ['player' => $player->pid]))
@ -147,7 +147,7 @@ class PlayersManagementControllerTest extends TestCase
// change owner successfully // change owner successfully
Event::fake(); Event::fake();
/** @var User */ /** @var User */
$user = factory(User::class)->create(); $user = User::factory()->create();
$this->putJson( $this->putJson(
route('admin.players.owner', ['player' => $player->pid]), route('admin.players.owner', ['player' => $player->pid]),
['uid' => $user->uid] ['uid' => $user->uid]
@ -183,7 +183,7 @@ class PlayersManagementControllerTest extends TestCase
Event::fake(); Event::fake();
/** @var Player */ /** @var Player */
$player = factory(Player::class)->create(); $player = Player::factory()->create();
// missing `tid` field // missing `tid` field
$this->putJson( $this->putJson(
@ -229,9 +229,9 @@ class PlayersManagementControllerTest extends TestCase
Event::assertNotDispatched('player.texture.updated'); Event::assertNotDispatched('player.texture.updated');
/** @var Texture */ /** @var Texture */
$skin = factory(Texture::class)->create(); $skin = Texture::factory()->create();
/** @var Texture */ /** @var Texture */
$cape = factory(Texture::class)->states('cape')->create(); $cape = Texture::factory()->cape()->create();
// skin // skin
Event::fake(); Event::fake();
@ -349,7 +349,7 @@ class PlayersManagementControllerTest extends TestCase
Event::fake(); Event::fake();
/** @var Player */ /** @var Player */
$player = factory(Player::class)->create(); $player = Player::factory()->create();
$this->deleteJson(route('admin.players.delete', ['player' => $player->pid])) $this->deleteJson(route('admin.players.delete', ['player' => $player->pid]))
->assertJson([ ->assertJson([

View File

@ -2,6 +2,7 @@
namespace Tests; namespace Tests;
use App\Models\User;
use App\Services\Plugin; use App\Services\Plugin;
use App\Services\PluginManager; use App\Services\PluginManager;
use App\Services\Unzip; use App\Services\Unzip;
@ -17,7 +18,7 @@ class PluginControllerTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->actingAs(factory(\App\Models\User::class)->states('superAdmin')->create()); $this->actingAs(User::factory()->superAdmin()->create());
} }
public function testShowManage() public function testShowManage()

View File

@ -20,8 +20,8 @@ class ReportControllerTest extends TestCase
Event::fake(); Event::fake();
$filter = resolve(Filter::class); $filter = resolve(Filter::class);
$user = factory(User::class)->create(); $user = User::factory()->create();
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
// without `tid` field // without `tid` field
$this->actingAs($user) $this->actingAs($user)
@ -104,7 +104,7 @@ class ReportControllerTest extends TestCase
public function testTrack() public function testTrack()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
$report = new Report(); $report = new Report();
$report->tid = 1; $report->tid = 1;
$report->uploader = 0; $report->uploader = 0;
@ -121,9 +121,9 @@ class ReportControllerTest extends TestCase
public function testManage() public function testManage()
{ {
$uploader = factory(User::class)->create(); $uploader = User::factory()->create();
$reporter = factory(User::class)->states('admin')->create(); $reporter = User::factory()->admin()->create();
$texture = factory(Texture::class)->create(['uploader' => $uploader->uid]); $texture = Texture::factory()->create(['uploader' => $uploader->uid]);
$report = new Report(); $report = new Report();
$report->tid = $texture->tid; $report->tid = $texture->tid;
@ -142,8 +142,8 @@ class ReportControllerTest extends TestCase
{ {
Event::fake(); Event::fake();
$admin = factory(User::class)->states('admin')->create(); $admin = User::factory()->admin()->create();
$texture = factory(Texture::class)->create(['uploader' => $admin->uid]); $texture = Texture::factory()->create(['uploader' => $admin->uid]);
$report = new Report(); $report = new Report();
$report->tid = $texture->tid; $report->tid = $texture->tid;
@ -180,10 +180,10 @@ class ReportControllerTest extends TestCase
{ {
Event::fake(); Event::fake();
$uploader = factory(User::class)->create(); $uploader = User::factory()->create();
$reporter = factory(User::class)->create(); $reporter = User::factory()->create();
$admin = factory(User::class)->states('admin')->create(); $admin = User::factory()->admin()->create();
$texture = factory(Texture::class)->create(['uploader' => $uploader->uid]); $texture = Texture::factory()->create(['uploader' => $uploader->uid]);
$report = new Report(); $report = new Report();
$report->tid = $texture->tid; $report->tid = $texture->tid;
@ -238,10 +238,10 @@ class ReportControllerTest extends TestCase
Event::fake(); Event::fake();
$disk = Storage::fake('textures'); $disk = Storage::fake('textures');
$uploader = factory(User::class)->create(); $uploader = User::factory()->create();
$reporter = factory(User::class)->create(); $reporter = User::factory()->create();
$admin = factory(User::class)->states('admin')->create(); $admin = User::factory()->admin()->create();
$texture = factory(Texture::class)->create(['uploader' => $uploader->uid]); $texture = Texture::factory()->create(['uploader' => $uploader->uid]);
$disk->put($texture->hash, ''); $disk->put($texture->hash, '');
$report = new Report(); $report = new Report();
@ -306,10 +306,10 @@ class ReportControllerTest extends TestCase
{ {
Event::fake(); Event::fake();
$uploader = factory(User::class)->create(); $uploader = User::factory()->create();
$reporter = factory(User::class)->create(); $reporter = User::factory()->create();
$admin = factory(User::class)->states('admin')->create(); $admin = User::factory()->admin()->create();
$texture = factory(Texture::class)->create(['uploader' => $uploader->uid]); $texture = Texture::factory()->create(['uploader' => $uploader->uid]);
$report = new Report(); $report = new Report();
$report->tid = $texture->tid; $report->tid = $texture->tid;
@ -351,10 +351,10 @@ class ReportControllerTest extends TestCase
{ {
Event::fake(); Event::fake();
$uploader = factory(User::class)->create(); $uploader = User::factory()->create();
$reporter = factory(User::class)->create(); $reporter = User::factory()->create();
$admin = factory(User::class)->states('admin')->create(); $admin = User::factory()->admin()->create();
$texture = factory(Texture::class)->create(['uploader' => $uploader->uid]); $texture = Texture::factory()->create(['uploader' => $uploader->uid]);
$report = new Report(); $report = new Report();
$report->tid = $texture->tid; $report->tid = $texture->tid;

View File

@ -20,8 +20,8 @@ class SkinlibControllerTest extends TestCase
{ {
Storage::fake('textures'); Storage::fake('textures');
$other = factory(User::class)->create(); $other = User::factory()->create();
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
// other user should not be able to delete // other user should not be able to delete
$this->actingAs($other) $this->actingAs($other)
@ -30,24 +30,24 @@ class SkinlibControllerTest extends TestCase
->assertForbidden(); ->assertForbidden();
// administrators can delete it // administrators can delete it
$this->actingAs(factory(User::class)->states('admin')->create()) $this->actingAs(User::factory()->admin()->create())
->deleteJson(route('texture.delete', ['texture' => $texture])) ->deleteJson(route('texture.delete', ['texture' => $texture]))
->assertJson(['code' => 0]); ->assertJson(['code' => 0]);
} }
public function testLibrary() public function testLibrary()
{ {
$steve = factory(Texture::class)->create([ $steve = Texture::factory()->create([
'name' => 'ab', 'name' => 'ab',
'upload_at' => Carbon::now()->subDays(2), 'upload_at' => Carbon::now()->subDays(2),
'likes' => 80, 'likes' => 80,
]); ]);
$alex = factory(Texture::class)->states('alex')->create([ $alex = Texture::factory()->alex()->create([
'name' => 'cd', 'name' => 'cd',
'upload_at' => Carbon::now()->subDays(1), 'upload_at' => Carbon::now()->subDays(1),
'likes' => 60, 'likes' => 60,
]); ]);
$private = factory(Texture::class)->states('private')->create([ $private = Texture::factory()->private()->create([
'upload_at' => Carbon::now(), 'upload_at' => Carbon::now(),
]); ]);
@ -75,10 +75,10 @@ class SkinlibControllerTest extends TestCase
['tid' => $steve->tid, 'nickname' => $steve->owner->nickname], ['tid' => $steve->tid, 'nickname' => $steve->owner->nickname],
], ],
]); ]);
$user = factory(User::class)->create(); $user = User::factory()->create();
$list = $this->actingAs($user) $list = $this->actingAs($user)
->getJson('/skinlib/list?keyword=a') ->getJson('/skinlib/list?keyword=a')
->decodeResponseJson('data'); ->json('data');
$this->assertCount(1, $list); $this->assertCount(1, $list);
// with uploader // with uploader
@ -99,7 +99,7 @@ class SkinlibControllerTest extends TestCase
]); ]);
// private textures are not available for other user // private textures are not available for other user
$this->actingAs(factory(User::class)->create()) $this->actingAs(User::factory()->create())
->getJson('/skinlib/list') ->getJson('/skinlib/list')
->assertJson([ ->assertJson([
'data' => [ 'data' => [
@ -120,7 +120,7 @@ class SkinlibControllerTest extends TestCase
]); ]);
// private textures are available for administrators // private textures are available for administrators
$this->actingAs(factory(User::class)->states('admin')->create()) $this->actingAs(User::factory()->admin()->create())
->getJson('/skinlib/list') ->getJson('/skinlib/list')
->assertJson([ ->assertJson([
'data' => [ 'data' => [
@ -138,7 +138,7 @@ class SkinlibControllerTest extends TestCase
// Invalid texture // Invalid texture
option(['auto_del_invalid_texture' => false]); option(['auto_del_invalid_texture' => false]);
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$this->get('/skinlib/show/'.$texture->tid) $this->get('/skinlib/show/'.$texture->tid)
->assertSee(trans('skinlib.show.deleted')); ->assertSee(trans('skinlib.show.deleted'));
$this->assertNotNull(Texture::find($texture->tid)); $this->assertNotNull(Texture::find($texture->tid));
@ -149,14 +149,14 @@ class SkinlibControllerTest extends TestCase
$this->assertNull(Texture::find($texture->tid)); $this->assertNull(Texture::find($texture->tid));
// Show a texture // Show a texture
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
Storage::disk('textures')->put($texture->hash, ''); Storage::disk('textures')->put($texture->hash, '');
$this->get('/skinlib/show/'.$texture->tid)->assertViewHas('texture'); $this->get('/skinlib/show/'.$texture->tid)->assertViewHas('texture');
$filter->assertApplied('grid:skinlib.show'); $filter->assertApplied('grid:skinlib.show');
// Guest should not see private texture // Guest should not see private texture
$uploader = factory(User::class)->create(); $uploader = User::factory()->create();
$texture = factory(Texture::class)->create([ $texture = Texture::factory()->create([
'uploader' => $uploader->uid, 'uploader' => $uploader->uid,
'public' => false, 'public' => false,
]); ]);
@ -172,12 +172,12 @@ class SkinlibControllerTest extends TestCase
option(['status_code_for_private' => 403]); option(['status_code_for_private' => 403]);
// Other user should not see private texture // Other user should not see private texture
$this->actingAs(factory(User::class)->create()) $this->actingAs(User::factory()->create())
->get('/skinlib/show/'.$texture->tid) ->get('/skinlib/show/'.$texture->tid)
->assertSee(trans('skinlib.show.private')); ->assertSee(trans('skinlib.show.private'));
// Administrators should be able to see private textures // Administrators should be able to see private textures
$this->actingAs(factory(User::class)->states('admin')->create()) $this->actingAs(User::factory()->admin()->create())
->get('/skinlib/show/'.$texture->tid) ->get('/skinlib/show/'.$texture->tid)
->assertViewHas('texture'); ->assertViewHas('texture');
@ -210,7 +210,7 @@ class SkinlibControllerTest extends TestCase
->assertNotFound() ->assertNotFound()
->assertSee(trans('skinlib.non-existent')); ->assertSee(trans('skinlib.non-existent'));
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$this->get(route('texture.info', ['texture' => $texture])) $this->get(route('texture.info', ['texture' => $texture]))
->assertJson($texture->toArray()); ->assertJson($texture->toArray());
} }
@ -219,7 +219,7 @@ class SkinlibControllerTest extends TestCase
{ {
$filter = Fakes\Filter::fake(); $filter = Fakes\Filter::fake();
$this->actingAs(factory(User::class)->create())->get('/skinlib/upload'); $this->actingAs(User::factory()->create())->get('/skinlib/upload');
$filter->assertApplied('grid:skinlib.upload'); $filter->assertApplied('grid:skinlib.upload');
option(['texture_name_regexp' => 'abc']); option(['texture_name_regexp' => 'abc']);
@ -232,7 +232,7 @@ class SkinlibControllerTest extends TestCase
/** @var FilesystemAdapter */ /** @var FilesystemAdapter */
$disk = Storage::fake('textures'); $disk = Storage::fake('textures');
$filter = Fakes\Filter::fake(); $filter = Fakes\Filter::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
// without file // without file
$this->actingAs($user) $this->actingAs($user)
@ -347,7 +347,7 @@ class SkinlibControllerTest extends TestCase
$upload = UploadedFile::fake()->image('texture.png', 64, 32); $upload = UploadedFile::fake()->image('texture.png', 64, 32);
// score is not enough // score is not enough
$user = factory(User::class)->create(['score' => 0]); $user = User::factory()->create(['score' => 0]);
$this->actingAs($user) $this->actingAs($user)
->postJson(route('texture.upload'), [ ->postJson(route('texture.upload'), [
'name' => 'texture', 'name' => 'texture',
@ -360,7 +360,7 @@ class SkinlibControllerTest extends TestCase
'message' => trans('skinlib.upload.lack-score'), 'message' => trans('skinlib.upload.lack-score'),
]); ]);
$user = factory(User::class)->create([ $user = User::factory()->create([
'score' => (int) option('score_per_closet_item') + (int) option('score_per_storage'), 'score' => (int) option('score_per_closet_item') + (int) option('score_per_storage'),
]); ]);
$this->actingAs($user)->postJson( $this->actingAs($user)->postJson(
@ -437,7 +437,7 @@ class SkinlibControllerTest extends TestCase
); );
// upload a duplicated texture // upload a duplicated texture
$user = factory(User::class)->create(); $user = User::factory()->create();
$this->actingAs($user) $this->actingAs($user)
->postJson(route('texture.upload'), [ ->postJson(route('texture.upload'), [
'name' => 'texture', 'name' => 'texture',
@ -487,10 +487,10 @@ class SkinlibControllerTest extends TestCase
/** @var FilesystemAdapter */ /** @var FilesystemAdapter */
$disk = Storage::fake('textures'); $disk = Storage::fake('textures');
$uploader = factory(User::class)->create(); $uploader = User::factory()->create();
$texture = factory(Texture::class)->create(['uploader' => $uploader->uid]); $texture = Texture::factory()->create(['uploader' => $uploader->uid]);
$duplicate = factory(Texture::class)->create([ $duplicate = Texture::factory()->create([
'hash' => $texture->hash, 'hash' => $texture->hash,
'uploader' => $uploader->uid, 'uploader' => $uploader->uid,
]); ]);
@ -545,12 +545,12 @@ class SkinlibControllerTest extends TestCase
public function testPrivacy() public function testPrivacy()
{ {
Event::fake(); Event::fake();
$uploader = factory(User::class)->create(); $uploader = User::factory()->create();
$other = factory(User::class)->create(); $other = User::factory()->create();
$texture = factory(Texture::class)->create(['uploader' => $uploader->uid]); $texture = Texture::factory()->create(['uploader' => $uploader->uid]);
// setting a texture to be private needs more scores // setting a texture to be private needs more scores
$texture = factory(Texture::class)->create(['uploader' => $uploader->uid]); $texture = Texture::factory()->create(['uploader' => $uploader->uid]);
$uploader->score = 0; $uploader->score = 0;
$uploader->save(); $uploader->save();
$this->actingAs($uploader) $this->actingAs($uploader)
@ -626,7 +626,7 @@ class SkinlibControllerTest extends TestCase
// When setting a texture to be private, // When setting a texture to be private,
// other players should not be able to use it. // other players should not be able to use it.
$texture = factory(Texture::class)->create(['uploader' => $uploader->uid]); $texture = Texture::factory()->create(['uploader' => $uploader->uid]);
$uploader->score += $texture->size * option('private_score_per_storage'); $uploader->score += $texture->size * option('private_score_per_storage');
$uploader->save(); $uploader->save();
$this->putJson(route('texture.privacy', ['texture' => $texture])) $this->putJson(route('texture.privacy', ['texture' => $texture]))
@ -637,7 +637,7 @@ class SkinlibControllerTest extends TestCase
// take back the score // take back the score
option(['score_award_per_texture' => 5]); option(['score_award_per_texture' => 5]);
$texture = factory(Texture::class)->create(['uploader' => $uploader->uid]); $texture = Texture::factory()->create(['uploader' => $uploader->uid]);
$uploader->score = $texture->size * ( $uploader->score = $texture->size * (
option('private_score_per_storage') - option('score_per_storage') option('private_score_per_storage') - option('score_per_storage')
); );
@ -651,8 +651,8 @@ class SkinlibControllerTest extends TestCase
option(['return_score' => false, 'private_score_per_storage' => 0]); option(['return_score' => false, 'private_score_per_storage' => 0]);
$uploader->score += 1000; $uploader->score += 1000;
$uploader->save(); $uploader->save();
$texture = factory(Texture::class)->create(['public' => 'false', 'uploader' => $uploader->uid]); $texture = Texture::factory()->private()->create(['uploader' => $uploader->uid]);
$other = factory(User::class)->create(); $other = User::factory()->create();
$other->closet()->attach($texture->tid, ['item_name' => 'a']); $other->closet()->attach($texture->tid, ['item_name' => 'a']);
$this->putJson(route('texture.privacy', ['texture' => $texture])) $this->putJson(route('texture.privacy', ['texture' => $texture]))
->assertJson(['code' => 0]); ->assertJson(['code' => 0]);
@ -662,8 +662,8 @@ class SkinlibControllerTest extends TestCase
public function testRename() public function testRename()
{ {
Event::fake(); Event::fake();
$uploader = factory(User::class)->create(); $uploader = User::factory()->create();
$texture = factory(Texture::class)->create(['uploader' => $uploader->uid]); $texture = Texture::factory()->create(['uploader' => $uploader->uid]);
// without `name` field // without `name` field
$this->actingAs($uploader) $this->actingAs($uploader)
@ -723,10 +723,10 @@ class SkinlibControllerTest extends TestCase
public function testType() public function testType()
{ {
Event::fake(); Event::fake();
$uploader = factory(User::class)->create(); $uploader = User::factory()->create();
$other = factory(User::class)->create(); $other = User::factory()->create();
$texture = factory(Texture::class) $texture = Texture::factory()
->states('alex') ->alex()
->create(['uploader' => $uploader->uid]); ->create(['uploader' => $uploader->uid]);
// missing `type` field // missing `type` field
@ -768,7 +768,7 @@ class SkinlibControllerTest extends TestCase
} }
); );
$duplicate = factory(Texture::class)->states('alex')->create([ $duplicate = Texture::factory()->alex()->create([
'uploader' => $other->uid, 'uploader' => $other->uid,
'hash' => $texture->hash, 'hash' => $texture->hash,
]); ]);

View File

@ -17,13 +17,13 @@ class TextureControllerTest extends TestCase
public function testJson() public function testJson()
{ {
$steve = factory(Texture::class)->create(); $steve = Texture::factory()->create();
// Player is not existed // Player is not existed
$this->get('/nope.json')->assertStatus(404); $this->get('/nope.json')->assertStatus(404);
// Player is banned // Player is banned
$player = factory(Player::class)->create(['tid_skin' => $steve->tid]); $player = Player::factory()->create(['tid_skin' => $steve->tid]);
$player->user->permission = User::BANNED; $player->user->permission = User::BANNED;
$player->user->save(); $player->user->save();
$this->get("/{$player->name}.json") $this->get("/{$player->name}.json")
@ -50,7 +50,7 @@ class TextureControllerTest extends TestCase
$mock->shouldReceive('renderCape')->andReturn(Image::canvas(1, 1)); $mock->shouldReceive('renderCape')->andReturn(Image::canvas(1, 1));
}); });
$skin = factory(Texture::class)->create(); $skin = Texture::factory()->create();
$disk->put($skin->hash, ''); $disk->put($skin->hash, '');
$this->get(route('preview.hash', ['hash' => $skin->hash])) $this->get(route('preview.hash', ['hash' => $skin->hash]))
->assertHeader('Content-Type', 'image/webp'); ->assertHeader('Content-Type', 'image/webp');
@ -65,7 +65,7 @@ class TextureControllerTest extends TestCase
$mock->shouldReceive('renderCape')->andReturn(Image::canvas(1, 1)); $mock->shouldReceive('renderCape')->andReturn(Image::canvas(1, 1));
}); });
$skin = factory(Texture::class)->create(); $skin = Texture::factory()->create();
$this->get(route('preview.texture', ['texture' => $skin]))->assertNotFound(); $this->get(route('preview.texture', ['texture' => $skin]))->assertNotFound();
$disk->put($skin->hash, ''); $disk->put($skin->hash, '');
@ -76,7 +76,7 @@ class TextureControllerTest extends TestCase
->assertHeader('Content-Type', 'image/png'); ->assertHeader('Content-Type', 'image/png');
$this->assertTrue(Cache::has('preview-t'.$skin->tid.'-png')); $this->assertTrue(Cache::has('preview-t'.$skin->tid.'-png'));
$cape = factory(Texture::class)->states('cape')->create(); $cape = Texture::factory()->cape()->create();
$disk->put($cape->hash, ''); $disk->put($cape->hash, '');
$this->get(route('preview.texture', ['texture' => $cape, 'height' => 100])) $this->get(route('preview.texture', ['texture' => $cape, 'height' => 100]))
->assertHeader('Content-Type', 'image/webp'); ->assertHeader('Content-Type', 'image/webp');
@ -86,7 +86,7 @@ class TextureControllerTest extends TestCase
public function testRaw() public function testRaw()
{ {
$disk = Storage::fake('textures'); $disk = Storage::fake('textures');
$skin = factory(Texture::class)->create(); $skin = Texture::factory()->create();
// Not found // Not found
$this->get('/raw/0')->assertNotFound(); $this->get('/raw/0')->assertNotFound();
@ -106,7 +106,7 @@ class TextureControllerTest extends TestCase
public function testTexture() public function testTexture()
{ {
$disk = Storage::fake('textures'); $disk = Storage::fake('textures');
$skin = factory(Texture::class)->create(); $skin = Texture::factory()->create();
$this->get('/textures/'.$skin->hash)->assertNotFound(); $this->get('/textures/'.$skin->hash)->assertNotFound();
@ -125,7 +125,7 @@ class TextureControllerTest extends TestCase
$this->get(route('avatar.player', ['name' => 'abc']))->assertNotFound(); $this->get(route('avatar.player', ['name' => 'abc']))->assertNotFound();
$player = factory(Player::class)->create(); $player = Player::factory()->create();
$this->get(route('avatar.player', ['name' => $player->name])) $this->get(route('avatar.player', ['name' => $player->name]))
->assertSuccessful() ->assertSuccessful()
->assertHeader('Content-Type', 'image/webp'); ->assertHeader('Content-Type', 'image/webp');
@ -133,7 +133,7 @@ class TextureControllerTest extends TestCase
$this->mock(Minecraft::class, function ($mock) { $this->mock(Minecraft::class, function ($mock) {
$mock->shouldReceive('render2dAvatar')->andReturn(Image::canvas(1, 1)); $mock->shouldReceive('render2dAvatar')->andReturn(Image::canvas(1, 1));
}); });
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$disk->put($texture->hash, ''); $disk->put($texture->hash, '');
$player->tid_skin = $texture->tid; $player->tid_skin = $texture->tid;
$player->save(); $player->save();
@ -170,7 +170,7 @@ class TextureControllerTest extends TestCase
->assertSuccessful() ->assertSuccessful()
->assertHeader('Content-Type', 'image/webp'); ->assertHeader('Content-Type', 'image/webp');
$user = factory(User::class)->create(); $user = User::factory()->create();
$this->get(route('avatar.user', ['uid' => $user->uid])) $this->get(route('avatar.user', ['uid' => $user->uid]))
->assertSuccessful() ->assertSuccessful()
->assertHeader('Content-Type', 'image/webp'); ->assertHeader('Content-Type', 'image/webp');
@ -178,7 +178,7 @@ class TextureControllerTest extends TestCase
$this->mock(Minecraft::class, function ($mock) { $this->mock(Minecraft::class, function ($mock) {
$mock->shouldReceive('render2dAvatar')->andReturn(Image::canvas(1, 1)); $mock->shouldReceive('render2dAvatar')->andReturn(Image::canvas(1, 1));
}); });
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$disk->put($texture->hash, ''); $disk->put($texture->hash, '');
$user->avatar = $texture->tid; $user->avatar = $texture->tid;
$user->save(); $user->save();
@ -213,7 +213,7 @@ class TextureControllerTest extends TestCase
$mock->shouldReceive('render3dAvatar')->andReturn(Image::canvas(1, 1)); $mock->shouldReceive('render3dAvatar')->andReturn(Image::canvas(1, 1));
}); });
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$disk->put($texture->hash, ''); $disk->put($texture->hash, '');
$this->get(route('avatar.hash', ['hash' => $texture->hash])) $this->get(route('avatar.hash', ['hash' => $texture->hash]))
->assertSuccessful() ->assertSuccessful()
@ -236,7 +236,7 @@ class TextureControllerTest extends TestCase
$this->assertEquals(100, $image->width()); $this->assertEquals(100, $image->width());
$this->assertEquals(100, $image->height()); $this->assertEquals(100, $image->height());
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$this->get(route('avatar.texture', ['tid' => $texture->tid])) $this->get(route('avatar.texture', ['tid' => $texture->tid]))
->assertSuccessful() ->assertSuccessful()
->assertHeader('Content-Type', 'image/webp'); ->assertHeader('Content-Type', 'image/webp');

View File

@ -2,6 +2,7 @@
namespace Tests; namespace Tests;
use App\Models\User;
use App\Services\Translations\JavaScript; use App\Services\Translations\JavaScript;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Spatie\TranslationLoader\LanguageLine; use Spatie\TranslationLoader\LanguageLine;
@ -13,7 +14,7 @@ class TranslationsControllerTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->actingAs(factory(\App\Models\User::class)->states('admin')->create()); $this->actingAs(User::factory()->admin()->create());
} }
public function testList() public function testList()

View File

@ -2,6 +2,7 @@
namespace Tests; namespace Tests;
use App\Models\User;
use App\Services\Unzip; use App\Services\Unzip;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
@ -13,7 +14,7 @@ class UpdateControllerTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->actingAs(factory(\App\Models\User::class)->states('superAdmin')->create()); $this->actingAs(User::factory()->superAdmin()->create());
} }
public function testShowUpdatePage() public function testShowUpdatePage()

View File

@ -21,7 +21,7 @@ class UserControllerTest extends TestCase
public function testUser() public function testUser()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
$this->actingAs($user, 'jwt') $this->actingAs($user, 'jwt')
->get('/api/user') ->get('/api/user')
->assertJson($user->toArray()); ->assertJson($user->toArray());
@ -31,9 +31,9 @@ class UserControllerTest extends TestCase
{ {
$filter = Fakes\Filter::fake(); $filter = Fakes\Filter::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
$uid = $user->uid; $uid = $user->uid;
factory(\App\Models\Player::class)->create(['uid' => $uid]); \App\Models\Player::factory()->create(['uid' => $uid]);
$converter = new GithubFlavoredMarkdownConverter(); $converter = new GithubFlavoredMarkdownConverter();
$announcement = $converter->convertToHtml(option_localized('announcement')); $announcement = $converter->convertToHtml(option_localized('announcement'));
@ -48,7 +48,7 @@ class UserControllerTest extends TestCase
return true; return true;
}); });
$unverified = factory(User::class)->create(['verified' => false]); $unverified = User::factory()->create(['verified' => false]);
$this->actingAs($unverified) $this->actingAs($unverified)
->get('/user') ->get('/user')
->assertDontSee(trans('user.verification.notice.title')); ->assertDontSee(trans('user.verification.notice.title'));
@ -56,8 +56,8 @@ class UserControllerTest extends TestCase
public function testScoreInfo() public function testScoreInfo()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
factory(\App\Models\Player::class)->create(['uid' => $user->uid]); \App\Models\Player::factory()->create(['uid' => $user->uid]);
$this->actingAs($user) $this->actingAs($user)
->get('/user/score-info') ->get('/user/score-info')
@ -84,7 +84,7 @@ class UserControllerTest extends TestCase
Event::fake(); Event::fake();
$filter = Fakes\Filter::fake(); $filter = Fakes\Filter::fake();
option(['sign_score' => '50,50']); option(['sign_score' => '50,50']);
$user = factory(User::class)->create(); $user = User::factory()->create();
// success // success
$this->actingAs($user) $this->actingAs($user)
@ -114,7 +114,7 @@ class UserControllerTest extends TestCase
// remaining time is greater than 0 // remaining time is greater than 0
Event::fake(); Event::fake();
$user = factory(User::class)->create(['last_sign_at' => Carbon::now()]); $user = User::factory()->create(['last_sign_at' => Carbon::now()]);
option(['sign_gap_time' => 2]); option(['sign_gap_time' => 2]);
$this->actingAs($user) $this->actingAs($user)
->postJson('/user/sign') ->postJson('/user/sign')
@ -125,14 +125,14 @@ class UserControllerTest extends TestCase
// can sign after 0 o'clock // can sign after 0 o'clock
Event::fake(); Event::fake();
option(['sign_after_zero' => true]); option(['sign_after_zero' => true]);
$user = factory(User::class)->create(['last_sign_at' => Carbon::now()]); $user = User::factory()->create(['last_sign_at' => Carbon::now()]);
$this->actingAs($user) $this->actingAs($user)
->postJson('/user/sign') ->postJson('/user/sign')
->assertJson(['code' => 1]); ->assertJson(['code' => 1]);
Event::assertNotDispatched('user.sign.before'); Event::assertNotDispatched('user.sign.before');
Event::assertNotDispatched('user.sign.after'); Event::assertNotDispatched('user.sign.after');
$user = factory(User::class)->create([ $user = User::factory()->create([
'last_sign_at' => Carbon::today(), 'last_sign_at' => Carbon::today(),
]); ]);
$this->actingAs($user) $this->actingAs($user)
@ -155,8 +155,8 @@ class UserControllerTest extends TestCase
{ {
Mail::fake(); Mail::fake();
$unverified = factory(User::class)->create(['verified' => false]); $unverified = User::factory()->create(['verified' => false]);
$verified = factory(User::class)->create(); $verified = User::factory()->create();
// Should be forbidden if account verification is disabled // Should be forbidden if account verification is disabled
option(['require_verification' => false]); option(['require_verification' => false]);
@ -222,7 +222,7 @@ class UserControllerTest extends TestCase
{ {
$filter = Fakes\Filter::fake(); $filter = Fakes\Filter::fake();
$this->actingAs(factory(User::class)->create()) $this->actingAs(User::factory()->create())
->get('/user/profile') ->get('/user/profile')
->assertViewIs('user.profile'); ->assertViewIs('user.profile');
$filter->assertApplied('grid:user.profile'); $filter->assertApplied('grid:user.profile');
@ -231,7 +231,7 @@ class UserControllerTest extends TestCase
public function testHandleProfile() public function testHandleProfile()
{ {
Event::fake(); Event::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
$user->changePassword('12345678'); $user->changePassword('12345678');
$uid = $user->uid; $uid = $user->uid;
@ -495,7 +495,7 @@ class UserControllerTest extends TestCase
$this->assertNull(User::find($user->uid)); $this->assertNull(User::find($user->uid));
// Administrator cannot be deleted // Administrator cannot be deleted
$this->actingAs(factory(User::class)->states('admin')->create()) $this->actingAs(User::factory()->admin()->create())
->postJson('/user/profile', [ ->postJson('/user/profile', [
'action' => 'delete', 'action' => 'delete',
'password' => '87654321', 'password' => '87654321',
@ -507,10 +507,10 @@ class UserControllerTest extends TestCase
public function testSetAvatar() public function testSetAvatar()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
$uid = $user->uid; $uid = $user->uid;
$steve = factory(Texture::class)->create(); $steve = Texture::factory()->create();
$cape = factory(Texture::class)->states('cape')->create(); $cape = Texture::factory()->cape()->create();
// without `tid` field // without `tid` field
$this->actingAs($user) $this->actingAs($user)
@ -539,7 +539,7 @@ class UserControllerTest extends TestCase
]); ]);
// use private texture // use private texture
$private = factory(Texture::class)->state('private')->create(); $private = Texture::factory()->private()->create();
$this->actingAs($user) $this->actingAs($user)
->postJson('/user/profile/avatar', ['tid' => $private->tid]) ->postJson('/user/profile/avatar', ['tid' => $private->tid])
->assertJson([ ->assertJson([

View File

@ -14,12 +14,12 @@ class UsersManagementControllerTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->actingAs(factory(User::class)->states('admin')->create()); $this->actingAs(User::factory()->admin()->create());
} }
public function testList() public function testList()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
$this->getJson(route('admin.users.list')) $this->getJson(route('admin.users.list'))
->assertJson(['data' => [[/* admin is here */], $user->toArray()]]); ->assertJson(['data' => [[/* admin is here */], $user->toArray()]]);
@ -28,7 +28,7 @@ class UsersManagementControllerTest extends TestCase
public function testAccessControl() public function testAccessControl()
{ {
// an administrator operating on other administrator should be forbidden // an administrator operating on other administrator should be forbidden
$otherAdmin = factory(User::class)->states('admin')->create(); $otherAdmin = User::factory()->admin()->create();
$this->putJson(route('admin.users.email', ['user' => $otherAdmin->uid])) $this->putJson(route('admin.users.email', ['user' => $otherAdmin->uid]))
->assertJson([ ->assertJson([
@ -40,7 +40,7 @@ class UsersManagementControllerTest extends TestCase
public function testEmail() public function testEmail()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
// without `email` field // without `email` field
$this->putJson(route('admin.users.email', ['user' => $user])) $this->putJson(route('admin.users.email', ['user' => $user]))
@ -53,7 +53,7 @@ class UsersManagementControllerTest extends TestCase
)->assertJsonValidationErrors(['email']); )->assertJsonValidationErrors(['email']);
// use an existed email address // use an existed email address
$other = factory(User::class)->create(); $other = User::factory()->create();
$this->putJson( $this->putJson(
route('admin.users.email', ['user' => $user]), route('admin.users.email', ['user' => $user]),
['email' => $other->email] ['email' => $other->email]
@ -89,7 +89,7 @@ class UsersManagementControllerTest extends TestCase
public function testVerification() public function testVerification()
{ {
Event::fake(); Event::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
$this->putJson( $this->putJson(
route('admin.users.verification', ['user' => $user]) route('admin.users.verification', ['user' => $user])
@ -116,7 +116,7 @@ class UsersManagementControllerTest extends TestCase
public function testNickname() public function testNickname()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
// without `nickname` field // without `nickname` field
$this->putJson( $this->putJson(
@ -152,7 +152,7 @@ class UsersManagementControllerTest extends TestCase
public function testPassword() public function testPassword()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
// without `password` field // without `password` field
$this->putJson( $this->putJson(
@ -196,7 +196,7 @@ class UsersManagementControllerTest extends TestCase
public function testScore() public function testScore()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
// without `score` field // without `score` field
$this->putJson( $this->putJson(
@ -238,7 +238,7 @@ class UsersManagementControllerTest extends TestCase
public function testPermission() public function testPermission()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
// without `permission` field // without `permission` field
$this->putJson(route('admin.users.permission', ['user' => $user])) $this->putJson(route('admin.users.permission', ['user' => $user]))
@ -300,7 +300,7 @@ class UsersManagementControllerTest extends TestCase
public function testDelete() public function testDelete()
{ {
Event::fake(); Event::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
$this->deleteJson(route('admin.users.delete', ['user' => $user])) $this->deleteJson(route('admin.users.delete', ['user' => $user]))
->assertJson([ ->assertJson([

View File

@ -10,7 +10,7 @@ class AuthenticateTest extends TestCase
{ {
$this->get('/user')->assertRedirect('auth/login'); $this->get('/user')->assertRedirect('auth/login');
$user = factory(User::class)->make(); $user = User::factory()->make();
$this->actingAs($user)->assertAuthenticated(); $this->actingAs($user)->assertAuthenticated();
} }
} }

View File

@ -8,17 +8,17 @@ class CheckRole extends TestCase
{ {
public function testHandle() public function testHandle()
{ {
$this->actingAs(factory(User::class)->create()) $this->actingAs(User::factory()->create())
->get('/admin') ->get('/admin')
->assertForbidden(); ->assertForbidden();
$this->actingAs(factory(User::class)->states('admin')->create()) $this->actingAs(User::factory()->admin()->create())
->get('/admin') ->get('/admin')
->assertSuccessful(); ->assertSuccessful();
$this->get('/admin/update')->assertForbidden(); $this->get('/admin/update')->assertForbidden();
$this->actingAs(factory(User::class)->states('superAdmin')->create()) $this->actingAs(User::factory()->superAdmin()->create())
->get('/admin/update') ->get('/admin/update')
->assertSuccessful(); ->assertSuccessful();
} }

View File

@ -11,7 +11,7 @@ class CheckUserVerifiedTest extends TestCase
public function testHandle() public function testHandle()
{ {
$unverified = factory(User::class)->create(['verified' => false]); $unverified = User::factory()->create(['verified' => false]);
option(['require_verification' => false]); option(['require_verification' => false]);
$this->actingAs($unverified) $this->actingAs($unverified)
@ -24,11 +24,11 @@ class CheckUserVerifiedTest extends TestCase
->assertStatus(403) ->assertStatus(403)
->assertSee(trans('auth.check.verified')); ->assertSee(trans('auth.check.verified'));
$this->actingAs(factory(User::class)->create()) $this->actingAs(User::factory()->create())
->get('/skinlib/upload') ->get('/skinlib/upload')
->assertSuccessful(); ->assertSuccessful();
$user = factory(User::class)->create(['verified' => false]); $user = User::factory()->create(['verified' => false]);
$this->actingAs($user)->get('/user/oauth/manage')->assertForbidden(); $this->actingAs($user)->get('/user/oauth/manage')->assertForbidden();
$this->getJson('/oauth/clients')->assertForbidden(); $this->getJson('/oauth/clients')->assertForbidden();
$user->verified = true; $user->verified = true;

View File

@ -8,10 +8,10 @@ class EnsureEmailFilledTest extends TestCase
{ {
public function testHandle() public function testHandle()
{ {
$noEmailUser = factory(User::class)->make(['email' => '']); $noEmailUser = User::factory()->make(['email' => '']);
$this->actingAs($noEmailUser)->get('/user')->assertRedirect('/auth/bind'); $this->actingAs($noEmailUser)->get('/user')->assertRedirect('/auth/bind');
$normalUser = factory(User::class)->make(); $normalUser = User::factory()->make();
$this->actingAs($normalUser)->get('/auth/bind')->assertRedirect('/user'); $this->actingAs($normalUser)->get('/auth/bind')->assertRedirect('/user');
} }
} }

View File

@ -10,7 +10,7 @@ class FireUserAuthenticatedTest extends TestCase
public function testHandle() public function testHandle()
{ {
Event::fake(); Event::fake();
$user = factory(User::class)->make(); $user = User::factory()->make();
$this->actingAs($user)->get('/user'); $this->actingAs($user)->get('/user');
Event::assertDispatched(\App\Events\UserAuthenticated::class, function ($event) use ($user) { Event::assertDispatched(\App\Events\UserAuthenticated::class, function ($event) use ($user) {
$this->assertEquals($user->uid, $event->user->uid); $this->assertEquals($user->uid, $event->user->uid);

View File

@ -12,7 +12,7 @@ class RedirectIfAuthenticatedTest extends TestCase
->assertViewIs('auth.login') ->assertViewIs('auth.login')
->assertDontSee(trans('general.user-center')); ->assertDontSee(trans('general.user-center'));
$this->actingAs(factory(User::class)->make()) $this->actingAs(User::factory()->make())
->get('/auth/login') ->get('/auth/login')
->assertRedirect('/user'); ->assertRedirect('/user');
} }

View File

@ -8,7 +8,7 @@ class RejectBannedUserTest extends TestCase
{ {
public function testHandle() public function testHandle()
{ {
$user = factory(User::class)->states('banned')->make(); $user = User::factory()->banned()->create();
$this->actingAs($user)->get('/user')->assertForbidden(); $this->actingAs($user)->get('/user')->assertForbidden();
$this->get('/user', ['accept' => 'application/json']) $this->get('/user', ['accept' => 'application/json'])
->assertForbidden() ->assertForbidden()

View File

@ -18,7 +18,7 @@ class FootComposerTest extends TestCase
option([ option([
'custom_js' => '"<div></div>"</script><h1 id=disallowed></h1><script>', 'custom_js' => '"<div></div>"</script><h1 id=disallowed></h1><script>',
]); ]);
$user = factory(User::class)->create(); $user = User::factory()->create();
$this->actingAs($user); $this->actingAs($user);
$this->get('/user')->assertSee('"<div></div>"', false); $this->get('/user')->assertSee('"<div></div>"', false);
$crawler = new Crawler($this->get('/user')->getContent()); $crawler = new Crawler($this->get('/user')->getContent());
@ -53,7 +53,7 @@ class FootComposerTest extends TestCase
$event->contents[] = '<div id=appended></div>'; $event->contents[] = '<div id=appended></div>';
}); });
$user = factory(User::class)->create(); $user = User::factory()->create();
$this->actingAs($user); $this->actingAs($user);
$this->get('/user')->assertSee('<div id=appended></div>', false); $this->get('/user')->assertSee('<div id=appended></div>', false);
} }

View File

@ -15,7 +15,7 @@ class SideMenuComposerTest extends TestCase
{ {
Event::fake(); Event::fake();
$admin = factory(User::class)->states('admin')->create(); $admin = User::factory()->admin()->create();
$this->actingAs($admin)->get('/user'); $this->actingAs($admin)->get('/user');
Event::assertDispatched(Events\ConfigureUserMenu::class); Event::assertDispatched(Events\ConfigureUserMenu::class);
Event::assertDispatched(Events\ConfigureExploreMenu::class); Event::assertDispatched(Events\ConfigureExploreMenu::class);
@ -28,7 +28,7 @@ class SideMenuComposerTest extends TestCase
{ {
$filter = Fakes\Filter::fake(); $filter = Fakes\Filter::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
$this->actingAs($user)->get('/user'); $this->actingAs($user)->get('/user');
$filter->assertHaveBeenApplied('side_menu', function ($menu, $type) { $filter->assertHaveBeenApplied('side_menu', function ($menu, $type) {
$this->assertCount(count(config('menu.user')), $menu); $this->assertCount(count(config('menu.user')), $menu);
@ -46,7 +46,7 @@ class SideMenuComposerTest extends TestCase
public function testTransform() public function testTransform()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
$this->actingAs($user); $this->actingAs($user);
$crawler = new Crawler($this->get('/user/oauth/manage')->getContent()); $crawler = new Crawler($this->get('/user/oauth/manage')->getContent());
@ -73,7 +73,7 @@ class SideMenuComposerTest extends TestCase
); );
}); });
$admin = factory(User::class)->states('admin')->create(); $admin = User::factory()->admin()->create();
$this->actingAs($admin) $this->actingAs($admin)
->get('/admin') ->get('/admin')
->assertDontSee(trans('general.plugin-configs')); ->assertDontSee(trans('general.plugin-configs'));

View File

@ -8,7 +8,7 @@ class UserMenuComposerTest extends TestCase
{ {
public function testAvatar() public function testAvatar()
{ {
$user = factory(User::class)->create(['avatar' => 5]); $user = User::factory()->create(['avatar' => 5]);
$this->actingAs($user)->get('/')->assertSee('/avatar/5?size=36'); $this->actingAs($user)->get('/')->assertSee('/avatar/5?size=36');
$this->get('/skinlib')->assertSee('/avatar/5?size=36'); $this->get('/skinlib')->assertSee('/avatar/5?size=36');
$this->get('/user')->assertSee('/avatar/5?size=36'); $this->get('/user')->assertSee('/avatar/5?size=36');

View File

@ -9,7 +9,7 @@ class UserPanelComposerTest extends TestCase
{ {
public function testRenderUser() public function testRenderUser()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
$this->actingAs($user); $this->actingAs($user);
$this->get('/user')->assertSee('/avatar/0?size=45'); $this->get('/user')->assertSee('/avatar/0?size=45');
@ -19,7 +19,7 @@ class UserPanelComposerTest extends TestCase
{ {
$filter = Fakes\Filter::fake(); $filter = Fakes\Filter::fake();
$user = factory(User::class)->create(); $user = User::factory()->create();
$this->actingAs($user); $this->actingAs($user);
Event::listen(\App\Events\RenderingBadges::class, function ($event) { Event::listen(\App\Events\RenderingBadges::class, function ($event) {

View File

@ -13,8 +13,8 @@ class CleanUpClosetTest extends TestCase
public function testPublicTexture() public function testPublicTexture()
{ {
option(['return_score' => true]); option(['return_score' => true]);
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$user = factory(User::class)->create(['score' => 0]); $user = User::factory()->create(['score' => 0]);
$user->closet()->attach($texture->tid, ['item_name' => '']); $user->closet()->attach($texture->tid, ['item_name' => '']);
event('texture.privacy.updated', [$texture]); event('texture.privacy.updated', [$texture]);
@ -26,13 +26,13 @@ class CleanUpClosetTest extends TestCase
public function testPrivateTexture() public function testPrivateTexture()
{ {
option(['return_score' => true]); option(['return_score' => true]);
$uploader = factory(User::class)->create(); $uploader = User::factory()->create();
$texture = factory(Texture::class)->create([ $texture = Texture::factory()->create([
'uploader' => $uploader->uid, 'uploader' => $uploader->uid,
'public' => false, 'public' => false,
]); ]);
$uploader->closet()->attach($texture->tid, ['item_name' => '']); $uploader->closet()->attach($texture->tid, ['item_name' => '']);
$user = factory(User::class)->create(['score' => 0]); $user = User::factory()->create(['score' => 0]);
$user->closet()->attach($texture->tid, ['item_name' => '']); $user->closet()->attach($texture->tid, ['item_name' => '']);
$replicated = $texture->replicate(); $replicated = $texture->replicate();
@ -48,8 +48,8 @@ class CleanUpClosetTest extends TestCase
public function testDeletedTexture() public function testDeletedTexture()
{ {
option(['return_score' => true]); option(['return_score' => true]);
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$user = factory(User::class)->create(['score' => 0]); $user = User::factory()->create(['score' => 0]);
$user->closet()->attach($texture->tid, ['item_name' => '']); $user->closet()->attach($texture->tid, ['item_name' => '']);
$texture->delete(); $texture->delete();

View File

@ -17,12 +17,12 @@ class NotifyFailedPluginTest extends TestCase
event(new Events\RenderingFooter($content)); event(new Events\RenderingFooter($content));
$this->assertCount(0, $content); $this->assertCount(0, $content);
$this->actingAs(factory(User::class)->make()); $this->actingAs(User::factory()->make());
event(new Events\PluginBootFailed($plugin)); event(new Events\PluginBootFailed($plugin));
event(new Events\RenderingFooter($content)); event(new Events\RenderingFooter($content));
$this->assertCount(0, $content); $this->assertCount(0, $content);
$this->actingAs(factory(User::class)->states('admin')->make()); $this->actingAs(User::factory()->admin()->make());
event(new Events\PluginBootFailed($plugin)); event(new Events\PluginBootFailed($plugin));
event(new Events\RenderingFooter($content)); event(new Events\RenderingFooter($content));
$this->assertStringContainsString('blessing.notify.toast', $content[0]); $this->assertStringContainsString('blessing.notify.toast', $content[0]);

View File

@ -12,8 +12,8 @@ class ResetPlayerForRemovedClosetItemTest extends TestCase
public function testHandle() public function testHandle()
{ {
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$player = factory(Player::class)->create(['tid_skin' => $texture->tid]); $player = Player::factory()->create(['tid_skin' => $texture->tid]);
event('closet.removed', [$texture, $player->user]); event('closet.removed', [$texture, $player->user]);
$player->refresh(); $player->refresh();

View File

@ -12,8 +12,8 @@ class ResetPlayersTest extends TestCase
public function testPublicTexture() public function testPublicTexture()
{ {
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$player = factory(Player::class)->create(['tid_skin' => $texture->tid]); $player = Player::factory()->create(['tid_skin' => $texture->tid]);
event('texture.privacy.updated', [$texture]); event('texture.privacy.updated', [$texture]);
$player->refresh(); $player->refresh();
@ -22,9 +22,9 @@ class ResetPlayersTest extends TestCase
public function testPrivateTexture() public function testPrivateTexture()
{ {
$texture = factory(Texture::class)->create(['public' => false]); $texture = Texture::factory()->private()->create();
$player = factory(Player::class)->create(['tid_skin' => $texture->tid]); $player = Player::factory()->create(['tid_skin' => $texture->tid]);
$playerOfUploader = factory(Player::class)->create([ $playerOfUploader = Player::factory()->create([
'uid' => $texture->uploader, 'uid' => $texture->uploader,
'tid_skin' => $texture->tid, 'tid_skin' => $texture->tid,
]); ]);
@ -39,9 +39,9 @@ class ResetPlayersTest extends TestCase
public function testDeletedTexture() public function testDeletedTexture()
{ {
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$player = factory(Player::class)->create(['tid_skin' => $texture->tid]); $player = Player::factory()->create(['tid_skin' => $texture->tid]);
$playerOfUploader = factory(Player::class)->create([ $playerOfUploader = Player::factory()->create([
'uid' => $texture->uploader, 'uid' => $texture->uploader,
'tid_skin' => $texture->tid, 'tid_skin' => $texture->tid,
]); ]);

View File

@ -17,7 +17,7 @@ class SendEmailVerificationTest extends TestCase
Mail::fake(); Mail::fake();
option(['require_verification' => true]); option(['require_verification' => true]);
$user = factory(User::class)->create(['verified' => false]); $user = User::factory()->create(['verified' => false]);
Event::dispatch('auth.registration.completed', [$user]); Event::dispatch('auth.registration.completed', [$user]);
Mail::assertSent(EmailVerification::class, function ($mail) use ($user) { Mail::assertSent(EmailVerification::class, function ($mail) use ($user) {
return $mail->hasTo($user->email); return $mail->hasTo($user->email);

View File

@ -11,7 +11,7 @@ class SetAppLocaleTest extends TestCase
public function testUpdateUserLocale() public function testUpdateUserLocale()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
// This is a hacky way. // This is a hacky way.
// We must call `get` first before set authentication, // We must call `get` first before set authentication,
@ -26,7 +26,7 @@ class SetAppLocaleTest extends TestCase
public function testSetAppLocale() public function testSetAppLocale()
{ {
$user = factory(User::class)->create(['locale' => 'zh_CN']); $user = User::factory()->create(['locale' => 'zh_CN']);
event(new \Illuminate\Auth\Events\Authenticated('web', $user)); event(new \Illuminate\Auth\Events\Authenticated('web', $user));
$this->assertEquals('zh_CN', app()->getLocale()); $this->assertEquals('zh_CN', app()->getLocale());

View File

@ -12,7 +12,7 @@ class UpdateScoreForDeletedTextureTest extends TestCase
public function testPublicTexture() public function testPublicTexture()
{ {
option(['return_score' => true]); option(['return_score' => true]);
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$uploader = $texture->owner->replicate(); $uploader = $texture->owner->replicate();
event('texture.deleted', [$texture]); event('texture.deleted', [$texture]);
@ -25,7 +25,7 @@ class UpdateScoreForDeletedTextureTest extends TestCase
public function testPrivateTexture() public function testPrivateTexture()
{ {
option(['return_score' => true]); option(['return_score' => true]);
$texture = factory(Texture::class)->create(['public' => false]); $texture = Texture::factory()->private()->create();
$uploader = $texture->owner->replicate(); $uploader = $texture->owner->replicate();
event('texture.deleted', [$texture]); event('texture.deleted', [$texture]);
@ -43,7 +43,7 @@ class UpdateScoreForDeletedTextureTest extends TestCase
'score_per_storage' => 0, 'score_per_storage' => 0,
]); ]);
$texture = factory(Texture::class)->create(); $texture = Texture::factory()->create();
$uploader = $texture->owner->replicate(); $uploader = $texture->owner->replicate();
event('texture.deleted', [$texture]); event('texture.deleted', [$texture]);
@ -61,7 +61,7 @@ class UpdateScoreForDeletedTextureTest extends TestCase
'private_score_per_storage' => 0, 'private_score_per_storage' => 0,
]); ]);
$texture = factory(Texture::class)->create(['public' => false]); $texture = Texture::factory()->private()->create();
$uploader = $texture->owner->replicate(); $uploader = $texture->owner->replicate();
event('texture.deleted', [$texture]); event('texture.deleted', [$texture]);

View File

@ -12,16 +12,16 @@ class PlayerTest extends TestCase
public function testGetModelAttribute() public function testGetModelAttribute()
{ {
$player = factory(Player::class)->create(); $player = Player::factory()->create();
$this->assertEquals('default', $player->model); $this->assertEquals('default', $player->model);
$alex = factory(Texture::class)->states('alex')->create(); $alex = Texture::factory()->alex()->create();
$player->tid_skin = $alex->tid; $player->tid_skin = $alex->tid;
$player->save(); $player->save();
$player->refresh(); $player->refresh();
$this->assertEquals('slim', $player->model); $this->assertEquals('slim', $player->model);
$steve = factory(Texture::class)->create(); $steve = Texture::factory()->create();
$player->tid_skin = $steve->tid; $player->tid_skin = $steve->tid;
$player->save(); $player->save();
$player->refresh(); $player->refresh();

View File

@ -12,15 +12,15 @@ class UserTest extends TestCase
public function testGetPlayerNameAttribute() public function testGetPlayerNameAttribute()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
$player = factory(Player::class)->create(['uid' => $user->uid]); $player = Player::factory()->create(['uid' => $user->uid]);
$this->assertEquals($player->name, $user->player_name); $this->assertEquals($player->name, $user->player_name);
} }
public function testSetPlayerNameAttribute() public function testSetPlayerNameAttribute()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
$player = factory(Player::class)->create(['uid' => $user->uid]); $player = Player::factory()->create(['uid' => $user->uid]);
$user->player_name = 'a'; $user->player_name = 'a';
$player->refresh(); $player->refresh();
$this->assertEquals('a', $player->name); $this->assertEquals('a', $player->name);

View File

@ -15,7 +15,7 @@ class HookTest extends TestCase
'icon' => 'fa-book', 'icon' => 'fa-book',
'new-tab' => true, 'new-tab' => true,
]); ]);
$this->actingAs(factory(User::class)->create()) $this->actingAs(User::factory()->create())
->get('/user') ->get('/user')
->assertSee('Link A') ->assertSee('Link A')
->assertSee('/to/a') ->assertSee('/to/a')
@ -28,7 +28,7 @@ class HookTest extends TestCase
'link' => '/to/b', 'link' => '/to/b',
'icon' => 'fa-book', 'icon' => 'fa-book',
]); ]);
$this->actingAs(factory(User::class)->create()) $this->actingAs(User::factory()->create())
->get('/user') ->get('/user')
->assertSee('Link B') ->assertSee('Link B')
->assertSee('/to/b'); ->assertSee('/to/b');
@ -73,14 +73,14 @@ class HookTest extends TestCase
public function testAddUserBadge() public function testAddUserBadge()
{ {
Hook::addUserBadge('hi', 'green'); Hook::addUserBadge('hi', 'green');
$this->actingAs(factory(User::class)->create()) $this->actingAs(User::factory()->create())
->get('/user') ->get('/user')
->assertSee('<span class="badge bg-green mb-1 mr-2">hi</span>', false); ->assertSee('<span class="badge bg-green mb-1 mr-2">hi</span>', false);
} }
public function testSendNotification() public function testSendNotification()
{ {
$user = factory(User::class)->create(); $user = User::factory()->create();
Hook::sendNotification([$user], 'Ibara Mayaka'); Hook::sendNotification([$user], 'Ibara Mayaka');
$user->refresh(); $user->refresh();
$this->assertCount(1, $user->unreadNotifications); $this->assertCount(1, $user->unreadNotifications);