This commit is contained in:
Saeed Vaziry
2023-07-02 12:47:50 +02:00
commit 5c72f12490
825 changed files with 41659 additions and 0 deletions

View File

@ -0,0 +1,40 @@
<?php
namespace Tests\Feature\Http\Auth;
use App\Providers\RouteServiceProvider;
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
{
$response = $this->post('/login', [
'email' => $this->user->email,
'password' => 'password',
]);
$this->assertAuthenticated();
$response->assertRedirect(RouteServiceProvider::HOME);
}
public function test_users_can_not_authenticate_with_invalid_password(): void
{
$this->post('/login', [
'email' => $this->user->email,
'password' => 'wrong-password',
]);
$this->assertGuest();
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace Tests\Feature\Http\Auth;
use Illuminate\Foundation\Testing\RefreshDatabase;
use JsonException;
use Tests\TestCase;
class PasswordConfirmationTest extends TestCase
{
use RefreshDatabase;
public function test_confirm_password_screen_can_be_rendered(): void
{
$this->actingAs($this->user);
$response = $this->get('/confirm-password');
$response->assertStatus(200);
}
/**
* @throws JsonException
*/
public function test_password_can_be_confirmed(): void
{
$this->actingAs($this->user);
$response = $this->post('/confirm-password', [
'password' => 'password',
]);
$response->assertRedirect();
$response->assertSessionHasNoErrors();
}
public function test_password_is_not_confirmed_with_invalid_password(): void
{
$this->actingAs($this->user);
$response = $this->post('/confirm-password', [
'password' => 'wrong-password',
]);
$response->assertSessionHasErrors();
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace Tests\Feature\Http\Auth;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
class PasswordResetTest extends TestCase
{
use RefreshDatabase;
public function test_reset_password_link_screen_can_be_rendered(): void
{
$response = $this->get('/forgot-password');
$response->assertStatus(200);
}
public function test_reset_password_link_can_be_requested(): void
{
Notification::fake();
$this->post('/forgot-password', ['email' => $this->user->email]);
Notification::assertSentTo($this->user, ResetPassword::class);
}
public function test_reset_password_screen_can_be_rendered(): void
{
Notification::fake();
$this->post('/forgot-password', ['email' => $this->user->email]);
Notification::assertSentTo($this->user, ResetPassword::class, function ($notification) {
$response = $this->get('/reset-password/'.$notification->token);
$response->assertStatus(200);
return true;
});
}
public function test_password_can_be_reset_with_valid_token(): void
{
Notification::fake();
$this->post('/forgot-password', ['email' => $this->user->email]);
Notification::assertSentTo($this->user, ResetPassword::class, function ($notification) {
$response = $this->post('/reset-password', [
'token' => $notification->token,
'email' => $this->user->email,
'password' => 'password',
'password_confirmation' => 'password',
]);
$response->assertSessionHasNoErrors();
return true;
});
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace Tests\Feature\Http\Auth;
use App\Http\Livewire\Profile\UpdatePassword;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Livewire\Livewire;
use Tests\TestCase;
class PasswordUpdateTest extends TestCase
{
use RefreshDatabase;
public function test_password_can_be_updated(): void
{
$this->actingAs($this->user);
Livewire::test(UpdatePassword::class)
->set('current_password', 'password')
->set('password', 'new-password')
->set('password_confirmation', 'new-password')
->call('update')
->assertSuccessful();
$this->assertTrue(Hash::check('new-password', $this->user->refresh()->password));
}
public function test_correct_password_must_be_provided_to_update_password(): void
{
$this->actingAs($this->user);
Livewire::test(UpdatePassword::class)
->set('current_password', 'wrong-password')
->set('password', 'new-password')
->set('password_confirmation', 'new-password')
->call('update')
->assertHasErrors();
}
}