mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-12 12:10:41 -05:00
Converts Tests to Pest
This commit is contained in:
parent
1960cec21f
commit
5f192f9759
@ -34,7 +34,7 @@
|
|||||||
"laravel/sail": "^1.29",
|
"laravel/sail": "^1.29",
|
||||||
"mockery/mockery": "^1.6",
|
"mockery/mockery": "^1.6",
|
||||||
"nunomaduro/collision": "^8.1",
|
"nunomaduro/collision": "^8.1",
|
||||||
"phpunit/phpunit": "^11.2",
|
"pestphp/pest": "^2.34",
|
||||||
"spatie/laravel-ignition": "^2.8"
|
"spatie/laravel-ignition": "^2.8"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
1202
composer.lock
generated
1202
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -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));
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
<?php
|
||||||
|
|
||||||
namespace Tests\Unit;
|
test('that true is true', function () {
|
||||||
|
expect(true)->toBe(true);
|
||||||
use PHPUnit\Framework\TestCase;
|
});
|
||||||
|
|
||||||
class ExampleTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* A basic test example.
|
|
||||||
*/
|
|
||||||
public function test_that_true_is_true(): void
|
|
||||||
{
|
|
||||||
$this->assertTrue(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user