mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-12 20:20:41 -05:00
Merge branch 'develop' into impl/mod-page-tabs
This commit is contained in:
commit
30cdc60ae0
@ -53,7 +53,7 @@ SESSION_DOMAIN=null
|
||||
BROADCAST_CONNECTION=log
|
||||
|
||||
FILESYSTEM_DISK=local
|
||||
ASSET_URL=http://localhost/storage
|
||||
ASSET_URL="${APP_URL}"
|
||||
ASSET_URL_LIVEWIRE=/vendor/livewire/livewire.js
|
||||
|
||||
CACHE_STORE=redis
|
||||
|
@ -29,7 +29,7 @@ DB_CONNECTION=sqlite
|
||||
DB_DATABASE=/Users/USER/Sites/forge/database/database.sqlite
|
||||
|
||||
FILESYSTEM_DISK=local
|
||||
ASSET_URL="${APP_URL}/storage"
|
||||
ASSET_URL="${APP_URL}"
|
||||
ASSET_URL_LIVEWIRE=/vendor/livewire/livewire.js
|
||||
|
||||
SESSION_DRIVER=file
|
||||
|
@ -536,10 +536,10 @@ class ImportHubData implements ShouldBeUnique, ShouldQueue
|
||||
'thumbnail' => $this->fetchModThumbnail($curl, $mod->fileID, $mod->iconHash, $mod->iconExtension),
|
||||
'license_id' => License::whereHubId($mod->licenseID)->value('id'),
|
||||
'source_code_link' => $optionSourceCode?->source_code_link ?? '',
|
||||
'featured' => (bool) $mod?->isFeatured,
|
||||
'featured' => (bool) $mod->isFeatured,
|
||||
'contains_ai_content' => (bool) $optionContainsAi?->contains_ai,
|
||||
'contains_ads' => (bool) $optionContainsAds?->contains_ads,
|
||||
'disabled' => (bool) $mod?->isDisabled,
|
||||
'disabled' => (bool) $mod->isDisabled,
|
||||
'created_at' => Carbon::parse($mod->time, 'UTC'),
|
||||
'updated_at' => Carbon::parse($mod->lastChangeTime, 'UTC'),
|
||||
];
|
||||
|
@ -26,7 +26,6 @@ class AdminPanelProvider extends PanelProvider
|
||||
->default()
|
||||
->id('admin')
|
||||
->path('admin')
|
||||
->login()
|
||||
->colors([
|
||||
'primary' => Color::Blue,
|
||||
])
|
||||
|
@ -34,7 +34,8 @@
|
||||
"laravel/sail": "^1.29",
|
||||
"mockery/mockery": "^1.6",
|
||||
"nunomaduro/collision": "^8.1",
|
||||
"phpunit/phpunit": "^11.2",
|
||||
"pestphp/pest": "^2.34",
|
||||
"pestphp/pest-plugin-stressless": "^2.2",
|
||||
"spatie/laravel-ignition": "^2.8"
|
||||
},
|
||||
"autoload": {
|
||||
@ -51,7 +52,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"phpstan": [
|
||||
"./vendor/bin/phpstan analyse --debug --memory-limit=2G"
|
||||
"./vendor/bin/phpstan analyse -c phpstan.neon --debug --memory-limit=2G"
|
||||
],
|
||||
"post-autoload-dump": [
|
||||
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
|
||||
|
1477
composer.lock
generated
1477
composer.lock
generated
File diff suppressed because it is too large
Load Diff
89
config/filament.php
Normal file
89
config/filament.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Broadcasting
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By uncommenting the Laravel Echo configuration, you may connect Filament
|
||||
| to any Pusher-compatible websockets server.
|
||||
|
|
||||
| This will allow your users to receive real-time notifications.
|
||||
|
|
||||
*/
|
||||
|
||||
'broadcasting' => [
|
||||
|
||||
// 'echo' => [
|
||||
// 'broadcaster' => 'pusher',
|
||||
// 'key' => env('VITE_PUSHER_APP_KEY'),
|
||||
// 'cluster' => env('VITE_PUSHER_APP_CLUSTER'),
|
||||
// 'wsHost' => env('VITE_PUSHER_HOST'),
|
||||
// 'wsPort' => env('VITE_PUSHER_PORT'),
|
||||
// 'wssPort' => env('VITE_PUSHER_PORT'),
|
||||
// 'authEndpoint' => '/broadcasting/auth',
|
||||
// 'disableStats' => true,
|
||||
// 'encrypted' => true,
|
||||
// 'forceTLS' => true,
|
||||
// ],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Filesystem Disk
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is the storage disk Filament will use to store files. You may use
|
||||
| any of the disks defined in the `config/filesystems.php`.
|
||||
|
|
||||
*/
|
||||
|
||||
'default_filesystem_disk' => env('FILAMENT_FILESYSTEM_DISK', 'public'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Assets Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is the directory where Filament's assets will be published to. It
|
||||
| is relative to the `public` directory of your Laravel application.
|
||||
|
|
||||
| After changing the path, you should run `php artisan filament:assets`.
|
||||
|
|
||||
*/
|
||||
|
||||
'assets_path' => '/vendor/filament',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is the directory that Filament will use to store cache files that
|
||||
| are used to optimize the registration of components.
|
||||
|
|
||||
| After changing the path, you should run `php artisan filament:cache-components`.
|
||||
|
|
||||
*/
|
||||
|
||||
'cache_path' => base_path('bootstrap/cache/filament'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Livewire Loading Delay
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This sets the delay before loading indicators appear.
|
||||
|
|
||||
| Setting this to 'none' makes indicators appear immediately, which can be
|
||||
| desirable for high-latency connections. Setting it to 'default' applies
|
||||
| Livewire's standard 200ms delay.
|
||||
|
|
||||
*/
|
||||
|
||||
'livewire_loading_delay' => 'default',
|
||||
|
||||
];
|
30
package-lock.json
generated
30
package-lock.json
generated
@ -1161,9 +1161,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/electron-to-chromium": {
|
||||
"version": "1.4.828",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.828.tgz",
|
||||
"integrity": "sha512-QOIJiWpQJDHAVO4P58pwb133Cwee0nbvy/MV1CwzZVGpkH1RX33N3vsaWRCpR6bF63AAq366neZrRTu7Qlsbbw==",
|
||||
"version": "1.4.829",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.829.tgz",
|
||||
"integrity": "sha512-5qp1N2POAfW0u1qGAxXEtz6P7bO1m6gpZr5hdf5ve6lxpLM7MpiM4jIPz7xcrNlClQMafbyUDDWjlIQZ1Mw0Rw==",
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
@ -1425,9 +1425,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/is-core-module": {
|
||||
"version": "2.14.0",
|
||||
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.14.0.tgz",
|
||||
"integrity": "sha512-a5dFJih5ZLYlRtDc0dZWP7RiKr6xIKzmn/oAYCDvdLThadVgyJwlaoQPmRtMSpz+rk0OGAgIu+TcM9HUF0fk1A==",
|
||||
"version": "2.15.0",
|
||||
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.15.0.tgz",
|
||||
"integrity": "sha512-Dd+Lb2/zvk9SKy1TGCt1wFJFo/MWBPMX5x7KcvLajWTGuomczdQX61PvY5yK6SVACwpoexWo81IfFyoKY2QnTA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@ -1696,9 +1696,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/node-releases": {
|
||||
"version": "2.0.14",
|
||||
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.14.tgz",
|
||||
"integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==",
|
||||
"version": "2.0.17",
|
||||
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.17.tgz",
|
||||
"integrity": "sha512-Ww6ZlOiEQfPfXM45v17oabk77Z7mg5bOt7AjDyzy7RjK9OrLrLC8dyZQoAPEOtFX9SaNf1Tdvr5gRJWdTJj7GA==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
@ -2418,9 +2418,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/tailwindcss": {
|
||||
"version": "3.4.5",
|
||||
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.5.tgz",
|
||||
"integrity": "sha512-DlTxttYcogpDfx3tf/8jfnma1nfAYi2cBUYV2YNoPPecwmO3YGiFlOX9D8tGAu+EDF38ryBzvrDKU/BLMsUwbw==",
|
||||
"version": "3.4.6",
|
||||
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.6.tgz",
|
||||
"integrity": "sha512-1uRHzPB+Vzu57ocybfZ4jh5Q3SdlH7XW23J5sQoM9LhE9eIOlzxer/3XPSsycvih3rboRsvt0QCmzSrqyOYUIA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@ -2564,9 +2564,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/vite": {
|
||||
"version": "5.3.3",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-5.3.3.tgz",
|
||||
"integrity": "sha512-NPQdeCU0Dv2z5fu+ULotpuq5yfCS1BzKUIPhNbP3YBfAMGJXbt2nS+sbTFu+qchaqWTD+H3JK++nRwr6XIcp6A==",
|
||||
"version": "5.3.4",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-5.3.4.tgz",
|
||||
"integrity": "sha512-Cw+7zL3ZG9/NZBB8C+8QbQZmR54GwqIz+WMI4b3JgdYJvX+ny9AjJXqkGQlDXSXRP9rP0B4tbciRMOVEKulVOA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
@ -1,7 +1,9 @@
|
||||
includes:
|
||||
- ./vendor/larastan/larastan/extension.neon
|
||||
|
||||
parameters:
|
||||
paths:
|
||||
- app/
|
||||
excludePaths:
|
||||
analyseAndScan:
|
||||
- tests/
|
||||
level: 4
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Jetstream\Features;
|
||||
use Laravel\Jetstream\Http\Livewire\ApiTokenManager;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ApiTokenPermissionsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_api_token_permissions_can_be_updated(): void
|
||||
{
|
||||
if (! Features::hasApiFeatures()) {
|
||||
$this->markTestSkipped('API support is not enabled.');
|
||||
}
|
||||
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
$token = $user->tokens()->create([
|
||||
'name' => 'Test Token',
|
||||
'token' => Str::random(40),
|
||||
'abilities' => ['create', 'read'],
|
||||
]);
|
||||
|
||||
Livewire::test(ApiTokenManager::class)
|
||||
->set(['managingPermissionsFor' => $token])
|
||||
->set(['updateApiTokenForm' => [
|
||||
'permissions' => [
|
||||
'delete',
|
||||
'missing-permission',
|
||||
],
|
||||
]])
|
||||
->call('updateApiToken');
|
||||
|
||||
$this->assertTrue($user->fresh()->tokens->first()->can('delete'));
|
||||
$this->assertFalse($user->fresh()->tokens->first()->can('read'));
|
||||
$this->assertFalse($user->fresh()->tokens->first()->can('missing-permission'));
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AuthenticationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_login_screen_can_be_rendered(): void
|
||||
{
|
||||
$response = $this->get('/login');
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
public function test_users_can_authenticate_using_the_login_screen(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->post('/login', [
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('dashboard', absolute: false));
|
||||
}
|
||||
|
||||
public function test_users_can_not_authenticate_with_invalid_password(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->post('/login', [
|
||||
'email' => $user->email,
|
||||
'password' => 'wrong-password',
|
||||
]);
|
||||
|
||||
$this->assertGuest();
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Jetstream\Http\Livewire\LogoutOtherBrowserSessionsForm;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BrowserSessionsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_other_browser_sessions_can_be_logged_out(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->create());
|
||||
|
||||
Livewire::test(LogoutOtherBrowserSessionsForm::class)
|
||||
->set('password', 'password')
|
||||
->call('logoutOtherBrowserSessions')
|
||||
->assertSuccessful();
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Jetstream\Features;
|
||||
use Laravel\Jetstream\Http\Livewire\ApiTokenManager;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateApiTokenTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_api_tokens_can_be_created(): void
|
||||
{
|
||||
if (! Features::hasApiFeatures()) {
|
||||
$this->markTestSkipped('API support is not enabled.');
|
||||
}
|
||||
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
Livewire::test(ApiTokenManager::class)
|
||||
->set(['createApiTokenForm' => [
|
||||
'name' => 'Test Token',
|
||||
'permissions' => [
|
||||
'read',
|
||||
'update',
|
||||
],
|
||||
]])
|
||||
->call('createApiToken');
|
||||
|
||||
$this->assertCount(1, $user->fresh()->tokens);
|
||||
$this->assertEquals('Test Token', $user->fresh()->tokens->first()->name);
|
||||
$this->assertTrue($user->fresh()->tokens->first()->can('read'));
|
||||
$this->assertFalse($user->fresh()->tokens->first()->can('delete'));
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Jetstream\Features;
|
||||
use Laravel\Jetstream\Http\Livewire\DeleteUserForm;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteAccountTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_user_accounts_can_be_deleted(): void
|
||||
{
|
||||
if (! Features::hasAccountDeletionFeatures()) {
|
||||
$this->markTestSkipped('Account deletion is not enabled.');
|
||||
}
|
||||
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
$component = Livewire::test(DeleteUserForm::class)
|
||||
->set('password', 'password')
|
||||
->call('deleteUser');
|
||||
|
||||
$this->assertNull($user->fresh());
|
||||
}
|
||||
|
||||
public function test_correct_password_must_be_provided_before_account_can_be_deleted(): void
|
||||
{
|
||||
if (! Features::hasAccountDeletionFeatures()) {
|
||||
$this->markTestSkipped('Account deletion is not enabled.');
|
||||
}
|
||||
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
Livewire::test(DeleteUserForm::class)
|
||||
->set('password', 'wrong-password')
|
||||
->call('deleteUser')
|
||||
->assertHasErrors(['password']);
|
||||
|
||||
$this->assertNotNull($user->fresh());
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Jetstream\Features;
|
||||
use Laravel\Jetstream\Http\Livewire\ApiTokenManager;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteApiTokenTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_api_tokens_can_be_deleted(): void
|
||||
{
|
||||
if (! Features::hasApiFeatures()) {
|
||||
$this->markTestSkipped('API support is not enabled.');
|
||||
}
|
||||
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
$token = $user->tokens()->create([
|
||||
'name' => 'Test Token',
|
||||
'token' => Str::random(40),
|
||||
'abilities' => ['create', 'read'],
|
||||
]);
|
||||
|
||||
Livewire::test(ApiTokenManager::class)
|
||||
->set(['apiTokenIdBeingDeleted' => $token->id])
|
||||
->call('deleteApiToken');
|
||||
|
||||
$this->assertCount(0, $user->fresh()->tokens);
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\Verified;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Laravel\Fortify\Features;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EmailVerificationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_email_verification_screen_can_be_rendered(): void
|
||||
{
|
||||
if (! Features::enabled(Features::emailVerification())) {
|
||||
$this->markTestSkipped('Email verification not enabled.');
|
||||
}
|
||||
|
||||
$user = User::factory()->unverified()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get('/email/verify');
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
public function test_email_can_be_verified(): void
|
||||
{
|
||||
if (! Features::enabled(Features::emailVerification())) {
|
||||
$this->markTestSkipped('Email verification not enabled.');
|
||||
}
|
||||
|
||||
Event::fake();
|
||||
|
||||
$user = User::factory()->unverified()->create();
|
||||
|
||||
$verificationUrl = URL::temporarySignedRoute(
|
||||
'verification.verify',
|
||||
now()->addMinutes(60),
|
||||
['id' => $user->id, 'hash' => sha1($user->email)]
|
||||
);
|
||||
|
||||
$response = $this->actingAs($user)->get($verificationUrl);
|
||||
|
||||
Event::assertDispatched(Verified::class);
|
||||
|
||||
$this->assertTrue($user->fresh()->hasVerifiedEmail());
|
||||
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
|
||||
}
|
||||
|
||||
public function test_email_can_not_verified_with_invalid_hash(): void
|
||||
{
|
||||
if (! Features::enabled(Features::emailVerification())) {
|
||||
$this->markTestSkipped('Email verification not enabled.');
|
||||
}
|
||||
|
||||
$user = User::factory()->unverified()->create();
|
||||
|
||||
$verificationUrl = URL::temporarySignedRoute(
|
||||
'verification.verify',
|
||||
now()->addMinutes(60),
|
||||
['id' => $user->id, 'hash' => sha1('wrong-email')]
|
||||
);
|
||||
|
||||
$this->actingAs($user)->get($verificationUrl);
|
||||
|
||||
$this->assertFalse($user->fresh()->hasVerifiedEmail());
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
// use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ExampleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic test example.
|
||||
*/
|
||||
public function test_the_application_returns_a_successful_response(): void
|
||||
{
|
||||
$response = $this->get('/');
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PasswordConfirmationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_confirm_password_screen_can_be_rendered(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get('/user/confirm-password');
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
public function test_password_can_be_confirmed(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post('/user/confirm-password', [
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
$response->assertSessionHasNoErrors();
|
||||
}
|
||||
|
||||
public function test_password_is_not_confirmed_with_invalid_password(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post('/user/confirm-password', [
|
||||
'password' => 'wrong-password',
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors();
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Notifications\ResetPassword;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Laravel\Fortify\Features;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PasswordResetTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_reset_password_link_screen_can_be_rendered(): void
|
||||
{
|
||||
if (! Features::enabled(Features::resetPasswords())) {
|
||||
$this->markTestSkipped('Password updates are not enabled.');
|
||||
}
|
||||
|
||||
$response = $this->get('/forgot-password');
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
public function test_reset_password_link_can_be_requested(): void
|
||||
{
|
||||
if (! Features::enabled(Features::resetPasswords())) {
|
||||
$this->markTestSkipped('Password updates are not enabled.');
|
||||
}
|
||||
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->post('/forgot-password', [
|
||||
'email' => $user->email,
|
||||
]);
|
||||
|
||||
Notification::assertSentTo($user, ResetPassword::class);
|
||||
}
|
||||
|
||||
public function test_reset_password_screen_can_be_rendered(): void
|
||||
{
|
||||
if (! Features::enabled(Features::resetPasswords())) {
|
||||
$this->markTestSkipped('Password updates are not enabled.');
|
||||
}
|
||||
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->post('/forgot-password', [
|
||||
'email' => $user->email,
|
||||
]);
|
||||
|
||||
Notification::assertSentTo($user, ResetPassword::class, function (object $notification) {
|
||||
$response = $this->get('/reset-password/'.$notification->token);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public function test_password_can_be_reset_with_valid_token(): void
|
||||
{
|
||||
if (! Features::enabled(Features::resetPasswords())) {
|
||||
$this->markTestSkipped('Password updates are not enabled.');
|
||||
}
|
||||
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->post('/forgot-password', [
|
||||
'email' => $user->email,
|
||||
]);
|
||||
|
||||
Notification::assertSentTo($user, ResetPassword::class, function (object $notification) use ($user) {
|
||||
$response = $this->post('/reset-password', [
|
||||
'token' => $notification->token,
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
]);
|
||||
|
||||
$response->assertSessionHasNoErrors();
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Jetstream\Http\Livewire\UpdateProfileInformationForm;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProfileInformationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_current_profile_information_is_available(): void
|
||||
{
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
$component = Livewire::test(UpdateProfileInformationForm::class);
|
||||
|
||||
$this->assertEquals($user->name, $component->state['name']);
|
||||
$this->assertEquals($user->email, $component->state['email']);
|
||||
}
|
||||
|
||||
public function test_profile_information_can_be_updated(): void
|
||||
{
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
Livewire::test(UpdateProfileInformationForm::class)
|
||||
->set('state', ['name' => 'Test Name', 'email' => 'test@example.com'])
|
||||
->call('updateProfileInformation');
|
||||
|
||||
$this->assertEquals('Test Name', $user->fresh()->name);
|
||||
$this->assertEquals('test@example.com', $user->fresh()->email);
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Fortify\Features;
|
||||
use Laravel\Jetstream\Jetstream;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RegistrationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_registration_screen_can_be_rendered(): void
|
||||
{
|
||||
if (! Features::enabled(Features::registration())) {
|
||||
$this->markTestSkipped('Registration support is not enabled.');
|
||||
}
|
||||
|
||||
$response = $this->get('/register');
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
public function test_registration_screen_cannot_be_rendered_if_support_is_disabled(): void
|
||||
{
|
||||
if (Features::enabled(Features::registration())) {
|
||||
$this->markTestSkipped('Registration support is enabled.');
|
||||
}
|
||||
|
||||
$response = $this->get('/register');
|
||||
|
||||
$response->assertStatus(404);
|
||||
}
|
||||
|
||||
public function test_new_users_can_register(): void
|
||||
{
|
||||
if (! Features::enabled(Features::registration())) {
|
||||
$this->markTestSkipped('Registration support is not enabled.');
|
||||
}
|
||||
|
||||
$response = $this->post('/register', [
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('dashboard', absolute: false));
|
||||
}
|
||||
}
|
9
tests/Feature/StressTest.php
Normal file
9
tests/Feature/StressTest.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
use function Pest\Stressless\stress;
|
||||
|
||||
it('homepage has a fast response time', function () {
|
||||
$result = stress('/');
|
||||
|
||||
expect($result->requests()->duration()->med())->toBeLessThan(100);
|
||||
});
|
@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Fortify\Features;
|
||||
use Laravel\Jetstream\Http\Livewire\TwoFactorAuthenticationForm;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TwoFactorAuthenticationSettingsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_two_factor_authentication_can_be_enabled(): void
|
||||
{
|
||||
if (! Features::canManageTwoFactorAuthentication()) {
|
||||
$this->markTestSkipped('Two factor authentication is not enabled.');
|
||||
}
|
||||
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
$this->withSession(['auth.password_confirmed_at' => time()]);
|
||||
|
||||
Livewire::test(TwoFactorAuthenticationForm::class)
|
||||
->call('enableTwoFactorAuthentication');
|
||||
|
||||
$user = $user->fresh();
|
||||
|
||||
$this->assertNotNull($user->two_factor_secret);
|
||||
$this->assertCount(8, $user->recoveryCodes());
|
||||
}
|
||||
|
||||
public function test_recovery_codes_can_be_regenerated(): void
|
||||
{
|
||||
if (! Features::canManageTwoFactorAuthentication()) {
|
||||
$this->markTestSkipped('Two factor authentication is not enabled.');
|
||||
}
|
||||
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
$this->withSession(['auth.password_confirmed_at' => time()]);
|
||||
|
||||
$component = Livewire::test(TwoFactorAuthenticationForm::class)
|
||||
->call('enableTwoFactorAuthentication')
|
||||
->call('regenerateRecoveryCodes');
|
||||
|
||||
$user = $user->fresh();
|
||||
|
||||
$component->call('regenerateRecoveryCodes');
|
||||
|
||||
$this->assertCount(8, $user->recoveryCodes());
|
||||
$this->assertCount(8, array_diff($user->recoveryCodes(), $user->fresh()->recoveryCodes()));
|
||||
}
|
||||
|
||||
public function test_two_factor_authentication_can_be_disabled(): void
|
||||
{
|
||||
if (! Features::canManageTwoFactorAuthentication()) {
|
||||
$this->markTestSkipped('Two factor authentication is not enabled.');
|
||||
}
|
||||
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
$this->withSession(['auth.password_confirmed_at' => time()]);
|
||||
|
||||
$component = Livewire::test(TwoFactorAuthenticationForm::class)
|
||||
->call('enableTwoFactorAuthentication');
|
||||
|
||||
$this->assertNotNull($user->fresh()->two_factor_secret);
|
||||
|
||||
$component->call('disableTwoFactorAuthentication');
|
||||
|
||||
$this->assertNull($user->fresh()->two_factor_secret);
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Laravel\Jetstream\Http\Livewire\UpdatePasswordForm;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpdatePasswordTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_password_can_be_updated(): void
|
||||
{
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
Livewire::test(UpdatePasswordForm::class)
|
||||
->set('state', [
|
||||
'current_password' => 'password',
|
||||
'password' => 'new-password',
|
||||
'password_confirmation' => 'new-password',
|
||||
])
|
||||
->call('updatePassword');
|
||||
|
||||
$this->assertTrue(Hash::check('new-password', $user->fresh()->password));
|
||||
}
|
||||
|
||||
public function test_current_password_must_be_correct(): void
|
||||
{
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
Livewire::test(UpdatePasswordForm::class)
|
||||
->set('state', [
|
||||
'current_password' => 'wrong-password',
|
||||
'password' => 'new-password',
|
||||
'password_confirmation' => 'new-password',
|
||||
])
|
||||
->call('updatePassword')
|
||||
->assertHasErrors(['current_password']);
|
||||
|
||||
$this->assertTrue(Hash::check('password', $user->fresh()->password));
|
||||
}
|
||||
|
||||
public function test_new_passwords_must_match(): void
|
||||
{
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
Livewire::test(UpdatePasswordForm::class)
|
||||
->set('state', [
|
||||
'current_password' => 'password',
|
||||
'password' => 'new-password',
|
||||
'password_confirmation' => 'wrong-password',
|
||||
])
|
||||
->call('updatePassword')
|
||||
->assertHasErrors(['password']);
|
||||
|
||||
$this->assertTrue(Hash::check('password', $user->fresh()->password));
|
||||
}
|
||||
}
|
38
tests/Feature/User/ApiTokenPermissionsTest.php
Executable file
38
tests/Feature/User/ApiTokenPermissionsTest.php
Executable file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Jetstream\Features;
|
||||
use Laravel\Jetstream\Http\Livewire\ApiTokenManager;
|
||||
use Livewire\Livewire;
|
||||
|
||||
test('api token permissions can be updated', function () {
|
||||
if (Features::hasTeamFeatures()) {
|
||||
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
|
||||
} else {
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
}
|
||||
|
||||
$token = $user->tokens()->create([
|
||||
'name' => 'Test Token',
|
||||
'token' => Str::random(40),
|
||||
'abilities' => ['create', 'read'],
|
||||
]);
|
||||
|
||||
Livewire::test(ApiTokenManager::class)
|
||||
->set(['managingPermissionsFor' => $token])
|
||||
->set(['updateApiTokenForm' => [
|
||||
'permissions' => [
|
||||
'delete',
|
||||
'missing-permission',
|
||||
],
|
||||
]])
|
||||
->call('updateApiToken');
|
||||
|
||||
expect($user->fresh()->tokens->first())
|
||||
->can('delete')->toBeTrue()
|
||||
->can('read')->toBeFalse()
|
||||
->can('missing-permission')->toBeFalse();
|
||||
})->skip(function () {
|
||||
return ! Features::hasApiFeatures();
|
||||
}, 'API support is not enabled.');
|
32
tests/Feature/User/AuthenticationTest.php
Executable file
32
tests/Feature/User/AuthenticationTest.php
Executable file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
test('login screen can be rendered', function () {
|
||||
$response = $this->get('/login');
|
||||
|
||||
$response->assertStatus(200);
|
||||
});
|
||||
|
||||
test('users can authenticate using the login screen', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->post('/login', [
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('dashboard', absolute: false));
|
||||
});
|
||||
|
||||
test('users cannot authenticate with invalid password', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->post('/login', [
|
||||
'email' => $user->email,
|
||||
'password' => 'wrong-password',
|
||||
]);
|
||||
|
||||
$this->assertGuest();
|
||||
});
|
14
tests/Feature/User/BrowserSessionsTest.php
Executable file
14
tests/Feature/User/BrowserSessionsTest.php
Executable file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Laravel\Jetstream\Http\Livewire\LogoutOtherBrowserSessionsForm;
|
||||
use Livewire\Livewire;
|
||||
|
||||
test('other browser sessions can be logged out', function () {
|
||||
$this->actingAs(User::factory()->create());
|
||||
|
||||
Livewire::test(LogoutOtherBrowserSessionsForm::class)
|
||||
->set('password', 'password')
|
||||
->call('logoutOtherBrowserSessions')
|
||||
->assertSuccessful();
|
||||
});
|
32
tests/Feature/User/CreateApiTokenTest.php
Executable file
32
tests/Feature/User/CreateApiTokenTest.php
Executable file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Laravel\Jetstream\Features;
|
||||
use Laravel\Jetstream\Http\Livewire\ApiTokenManager;
|
||||
use Livewire\Livewire;
|
||||
|
||||
test('api tokens can be created', function () {
|
||||
if (Features::hasTeamFeatures()) {
|
||||
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
|
||||
} else {
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
}
|
||||
|
||||
Livewire::test(ApiTokenManager::class)
|
||||
->set(['createApiTokenForm' => [
|
||||
'name' => 'Test Token',
|
||||
'permissions' => [
|
||||
'read',
|
||||
'update',
|
||||
],
|
||||
]])
|
||||
->call('createApiToken');
|
||||
|
||||
expect($user->fresh()->tokens)->toHaveCount(1);
|
||||
expect($user->fresh()->tokens->first())
|
||||
->name->toEqual('Test Token')
|
||||
->can('read')->toBeTrue()
|
||||
->can('delete')->toBeFalse();
|
||||
})->skip(function () {
|
||||
return ! Features::hasApiFeatures();
|
||||
}, 'API support is not enabled.');
|
31
tests/Feature/User/DeleteAccountTest.php
Executable file
31
tests/Feature/User/DeleteAccountTest.php
Executable file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Laravel\Jetstream\Features;
|
||||
use Laravel\Jetstream\Http\Livewire\DeleteUserForm;
|
||||
use Livewire\Livewire;
|
||||
|
||||
test('user accounts can be deleted', function () {
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
Livewire::test(DeleteUserForm::class)
|
||||
->set('password', 'password')
|
||||
->call('deleteUser');
|
||||
|
||||
expect($user->fresh())->toBeNull();
|
||||
})->skip(function () {
|
||||
return ! Features::hasAccountDeletionFeatures();
|
||||
}, 'Account deletion is not enabled.');
|
||||
|
||||
test('correct password must be provided before account can be deleted', function () {
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
Livewire::test(DeleteUserForm::class)
|
||||
->set('password', 'wrong-password')
|
||||
->call('deleteUser')
|
||||
->assertHasErrors(['password']);
|
||||
|
||||
expect($user->fresh())->not->toBeNull();
|
||||
})->skip(function () {
|
||||
return ! Features::hasAccountDeletionFeatures();
|
||||
}, 'Account deletion is not enabled.');
|
29
tests/Feature/User/DeleteApiTokenTest.php
Executable file
29
tests/Feature/User/DeleteApiTokenTest.php
Executable file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Jetstream\Features;
|
||||
use Laravel\Jetstream\Http\Livewire\ApiTokenManager;
|
||||
use Livewire\Livewire;
|
||||
|
||||
test('api tokens can be deleted', function () {
|
||||
if (Features::hasTeamFeatures()) {
|
||||
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
|
||||
} else {
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
}
|
||||
|
||||
$token = $user->tokens()->create([
|
||||
'name' => 'Test Token',
|
||||
'token' => Str::random(40),
|
||||
'abilities' => ['create', 'read'],
|
||||
]);
|
||||
|
||||
Livewire::test(ApiTokenManager::class)
|
||||
->set(['apiTokenIdBeingDeleted' => $token->id])
|
||||
->call('deleteApiToken');
|
||||
|
||||
expect($user->fresh()->tokens)->toHaveCount(0);
|
||||
})->skip(function () {
|
||||
return ! Features::hasApiFeatures();
|
||||
}, 'API support is not enabled.');
|
60
tests/Feature/User/EmailVerificationTest.php
Executable file
60
tests/Feature/User/EmailVerificationTest.php
Executable file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\Verified;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Laravel\Fortify\Features;
|
||||
|
||||
test('email verification screen can be rendered', function () {
|
||||
$user = User::factory()->create([
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->get('/email/verify');
|
||||
|
||||
$response->assertStatus(200);
|
||||
})->skip(function () {
|
||||
return ! Features::enabled(Features::emailVerification());
|
||||
}, 'Email verification not enabled.');
|
||||
|
||||
test('email can be verified', function () {
|
||||
Event::fake();
|
||||
|
||||
$user = User::factory()->create([
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
|
||||
$verificationUrl = URL::temporarySignedRoute(
|
||||
'verification.verify',
|
||||
now()->addMinutes(60),
|
||||
['id' => $user->id, 'hash' => sha1($user->email)]
|
||||
);
|
||||
|
||||
$response = $this->actingAs($user)->get($verificationUrl);
|
||||
|
||||
Event::assertDispatched(Verified::class);
|
||||
|
||||
expect($user->fresh()->hasVerifiedEmail())->toBeTrue();
|
||||
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
|
||||
})->skip(function () {
|
||||
return ! Features::enabled(Features::emailVerification());
|
||||
}, 'Email verification not enabled.');
|
||||
|
||||
test('email can not verified with invalid hash', function () {
|
||||
$user = User::factory()->create([
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
|
||||
$verificationUrl = URL::temporarySignedRoute(
|
||||
'verification.verify',
|
||||
now()->addMinutes(60),
|
||||
['id' => $user->id, 'hash' => sha1('wrong-email')]
|
||||
);
|
||||
|
||||
$this->actingAs($user)->get($verificationUrl);
|
||||
|
||||
expect($user->fresh()->hasVerifiedEmail())->toBeFalse();
|
||||
})->skip(function () {
|
||||
return ! Features::enabled(Features::emailVerification());
|
||||
}, 'Email verification not enabled.');
|
35
tests/Feature/User/PasswordConfirmationTest.php
Executable file
35
tests/Feature/User/PasswordConfirmationTest.php
Executable file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Laravel\Jetstream\Features;
|
||||
|
||||
test('confirm password screen can be rendered', function () {
|
||||
$user = Features::hasTeamFeatures()
|
||||
? User::factory()->withPersonalTeam()->create()
|
||||
: User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get('/user/confirm-password');
|
||||
|
||||
$response->assertStatus(200);
|
||||
});
|
||||
|
||||
test('password can be confirmed', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post('/user/confirm-password', [
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
$response->assertSessionHasNoErrors();
|
||||
});
|
||||
|
||||
test('password is not confirmed with invalid password', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post('/user/confirm-password', [
|
||||
'password' => 'wrong-password',
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors();
|
||||
});
|
73
tests/Feature/User/PasswordResetTest.php
Executable file
73
tests/Feature/User/PasswordResetTest.php
Executable file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\ResetPassword;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Laravel\Fortify\Features;
|
||||
|
||||
test('reset password link screen can be rendered', function () {
|
||||
$response = $this->get('/forgot-password');
|
||||
|
||||
$response->assertStatus(200);
|
||||
})->skip(function () {
|
||||
return ! Features::enabled(Features::resetPasswords());
|
||||
}, 'Password updates are not enabled.');
|
||||
|
||||
test('reset password link can be requested', function () {
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->post('/forgot-password', [
|
||||
'email' => $user->email,
|
||||
]);
|
||||
|
||||
Notification::assertSentTo($user, ResetPassword::class);
|
||||
})->skip(function () {
|
||||
return ! Features::enabled(Features::resetPasswords());
|
||||
}, 'Password updates are not enabled.');
|
||||
|
||||
test('reset password screen can be rendered', function () {
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->post('/forgot-password', [
|
||||
'email' => $user->email,
|
||||
]);
|
||||
|
||||
Notification::assertSentTo($user, ResetPassword::class, function (object $notification) {
|
||||
$response = $this->get('/reset-password/'.$notification->token);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
return true;
|
||||
});
|
||||
})->skip(function () {
|
||||
return ! Features::enabled(Features::resetPasswords());
|
||||
}, 'Password updates are not enabled.');
|
||||
|
||||
test('password can be reset with valid token', function () {
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->post('/forgot-password', [
|
||||
'email' => $user->email,
|
||||
]);
|
||||
|
||||
Notification::assertSentTo($user, ResetPassword::class, function (object $notification) use ($user) {
|
||||
$response = $this->post('/reset-password', [
|
||||
'token' => $notification->token,
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
]);
|
||||
|
||||
$response->assertSessionHasNoErrors();
|
||||
|
||||
return true;
|
||||
});
|
||||
})->skip(function () {
|
||||
return ! Features::enabled(Features::resetPasswords());
|
||||
}, 'Password updates are not enabled.');
|
26
tests/Feature/User/ProfileInformationTest.php
Executable file
26
tests/Feature/User/ProfileInformationTest.php
Executable file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Laravel\Jetstream\Http\Livewire\UpdateProfileInformationForm;
|
||||
use Livewire\Livewire;
|
||||
|
||||
test('current profile information is available', function () {
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
$component = Livewire::test(UpdateProfileInformationForm::class);
|
||||
|
||||
expect($component->state['name'])->toEqual($user->name);
|
||||
expect($component->state['email'])->toEqual($user->email);
|
||||
});
|
||||
|
||||
test('profile information can be updated', function () {
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
Livewire::test(UpdateProfileInformationForm::class)
|
||||
->set('state', ['name' => 'Test Name', 'email' => 'test@example.com'])
|
||||
->call('updateProfileInformation');
|
||||
|
||||
expect($user->fresh())
|
||||
->name->toEqual('Test Name')
|
||||
->email->toEqual('test@example.com');
|
||||
});
|
35
tests/Feature/User/RegistrationTest.php
Executable file
35
tests/Feature/User/RegistrationTest.php
Executable file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Laravel\Fortify\Features;
|
||||
use Laravel\Jetstream\Jetstream;
|
||||
|
||||
test('registration screen can be rendered', function () {
|
||||
$response = $this->get('/register');
|
||||
|
||||
$response->assertStatus(200);
|
||||
})->skip(function () {
|
||||
return ! Features::enabled(Features::registration());
|
||||
}, 'Registration support is not enabled.');
|
||||
|
||||
test('registration screen cannot be rendered if support is disabled', function () {
|
||||
$response = $this->get('/register');
|
||||
|
||||
$response->assertStatus(404);
|
||||
})->skip(function () {
|
||||
return Features::enabled(Features::registration());
|
||||
}, 'Registration support is enabled.');
|
||||
|
||||
test('new users can register', function () {
|
||||
$response = $this->post('/register', [
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('dashboard', absolute: false));
|
||||
})->skip(function () {
|
||||
return ! Features::enabled(Features::registration());
|
||||
}, 'Registration support is not enabled.');
|
58
tests/Feature/User/TwoFactorAuthenticationSettingsTest.php
Executable file
58
tests/Feature/User/TwoFactorAuthenticationSettingsTest.php
Executable file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Laravel\Fortify\Features;
|
||||
use Laravel\Jetstream\Http\Livewire\TwoFactorAuthenticationForm;
|
||||
use Livewire\Livewire;
|
||||
|
||||
test('two factor authentication can be enabled', function () {
|
||||
$this->actingAs($user = User::factory()->create()->fresh());
|
||||
|
||||
$this->withSession(['auth.password_confirmed_at' => time()]);
|
||||
|
||||
Livewire::test(TwoFactorAuthenticationForm::class)
|
||||
->call('enableTwoFactorAuthentication');
|
||||
|
||||
$user = $user->fresh();
|
||||
|
||||
expect($user->two_factor_secret)->not->toBeNull();
|
||||
expect($user->recoveryCodes())->toHaveCount(8);
|
||||
})->skip(function () {
|
||||
return ! Features::canManageTwoFactorAuthentication();
|
||||
}, 'Two factor authentication is not enabled.');
|
||||
|
||||
test('recovery codes can be regenerated', function () {
|
||||
$this->actingAs($user = User::factory()->create()->fresh());
|
||||
|
||||
$this->withSession(['auth.password_confirmed_at' => time()]);
|
||||
|
||||
$component = Livewire::test(TwoFactorAuthenticationForm::class)
|
||||
->call('enableTwoFactorAuthentication')
|
||||
->call('regenerateRecoveryCodes');
|
||||
|
||||
$user = $user->fresh();
|
||||
|
||||
$component->call('regenerateRecoveryCodes');
|
||||
|
||||
expect($user->recoveryCodes())->toHaveCount(8);
|
||||
expect(array_diff($user->recoveryCodes(), $user->fresh()->recoveryCodes()))->toHaveCount(8);
|
||||
})->skip(function () {
|
||||
return ! Features::canManageTwoFactorAuthentication();
|
||||
}, 'Two factor authentication is not enabled.');
|
||||
|
||||
test('two factor authentication can be disabled', function () {
|
||||
$this->actingAs($user = User::factory()->create()->fresh());
|
||||
|
||||
$this->withSession(['auth.password_confirmed_at' => time()]);
|
||||
|
||||
$component = Livewire::test(TwoFactorAuthenticationForm::class)
|
||||
->call('enableTwoFactorAuthentication');
|
||||
|
||||
$this->assertNotNull($user->fresh()->two_factor_secret);
|
||||
|
||||
$component->call('disableTwoFactorAuthentication');
|
||||
|
||||
expect($user->fresh()->two_factor_secret)->toBeNull();
|
||||
})->skip(function () {
|
||||
return ! Features::canManageTwoFactorAuthentication();
|
||||
}, 'Two factor authentication is not enabled.');
|
50
tests/Feature/User/UpdatePasswordTest.php
Executable file
50
tests/Feature/User/UpdatePasswordTest.php
Executable file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Laravel\Jetstream\Http\Livewire\UpdatePasswordForm;
|
||||
use Livewire\Livewire;
|
||||
|
||||
test('password can be updated', function () {
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
Livewire::test(UpdatePasswordForm::class)
|
||||
->set('state', [
|
||||
'current_password' => 'password',
|
||||
'password' => 'new-password',
|
||||
'password_confirmation' => 'new-password',
|
||||
])
|
||||
->call('updatePassword');
|
||||
|
||||
expect(Hash::check('new-password', $user->fresh()->password))->toBeTrue();
|
||||
});
|
||||
|
||||
test('current password must be correct', function () {
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
Livewire::test(UpdatePasswordForm::class)
|
||||
->set('state', [
|
||||
'current_password' => 'wrong-password',
|
||||
'password' => 'new-password',
|
||||
'password_confirmation' => 'new-password',
|
||||
])
|
||||
->call('updatePassword')
|
||||
->assertHasErrors(['current_password']);
|
||||
|
||||
expect(Hash::check('password', $user->fresh()->password))->toBeTrue();
|
||||
});
|
||||
|
||||
test('new passwords must match', function () {
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
Livewire::test(UpdatePasswordForm::class)
|
||||
->set('state', [
|
||||
'current_password' => 'password',
|
||||
'password' => 'new-password',
|
||||
'password_confirmation' => 'wrong-password',
|
||||
])
|
||||
->call('updatePassword')
|
||||
->assertHasErrors(['password']);
|
||||
|
||||
expect(Hash::check('password', $user->fresh()->password))->toBeTrue();
|
||||
});
|
48
tests/Pest.php
Executable file
48
tests/Pest.php
Executable file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Test Case
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The closure you provide to your test functions is always bound to a specific PHPUnit test
|
||||
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
|
||||
| need to change it using the "uses()" function to bind a different classes or traits.
|
||||
|
|
||||
*/
|
||||
|
||||
uses(TestCase::class, RefreshDatabase::class)->in('Feature');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Expectations
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When you're writing tests, you often need to check that values meet certain conditions. The
|
||||
| "expect()" function gives you access to a set of "expectations" methods that you can use
|
||||
| to assert different things. Of course, you may extend the Expectation API at any time.
|
||||
|
|
||||
*/
|
||||
|
||||
expect()->extend('toBeOne', function () {
|
||||
return $this->toBe(1);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Functions
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
|
||||
| project that you don't want to repeat in every file. Here you can also expose helpers as
|
||||
| global functions to help you to reduce the number of lines of code in your test files.
|
||||
|
|
||||
*/
|
||||
|
||||
function something()
|
||||
{
|
||||
// ..
|
||||
}
|
@ -1,16 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ExampleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic test example.
|
||||
*/
|
||||
public function test_that_true_is_true(): void
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
test('that true is true', function () {
|
||||
expect(true)->toBe(true);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user