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\Models;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
use Lorisleiva\LaravelSearchString\Concerns\SearchString;
@ -23,6 +24,7 @@ use Lorisleiva\LaravelSearchString\Concerns\SearchString;
*/
class Player extends Model
{
use HasFactory;
use SearchString;
public const CREATED_AT = null;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,6 +2,7 @@
namespace Tests;
use App\Models\User;
use Cache;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Mockery;
@ -18,7 +19,7 @@ class OptionsControllerTest extends BrowserKitTestCase
\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()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,10 +8,10 @@ class EnsureEmailFilledTest extends TestCase
{
public function testHandle()
{
$noEmailUser = factory(User::class)->make(['email' => '']);
$noEmailUser = User::factory()->make(['email' => '']);
$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');
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -11,7 +11,7 @@ class SetAppLocaleTest extends TestCase
public function testUpdateUserLocale()
{
$user = factory(User::class)->create();
$user = User::factory()->create();
// This is a hacky way.
// We must call `get` first before set authentication,
@ -26,7 +26,7 @@ class SetAppLocaleTest extends TestCase
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));
$this->assertEquals('zh_CN', app()->getLocale());

View File

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

View File

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

View File

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

View File

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