AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

AuthenticationTest.php 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace Tests\Feature\Auth;
  3. use App\Models\User;
  4. use Illuminate\Foundation\Testing\RefreshDatabase;
  5. use Illuminate\Support\Facades\RateLimiter;
  6. use Laravel\Fortify\Features;
  7. use Tests\TestCase;
  8. class AuthenticationTest extends TestCase
  9. {
  10. use RefreshDatabase;
  11. public function test_login_screen_can_be_rendered()
  12. {
  13. $response = $this->get(route('login'));
  14. $response->assertOk();
  15. }
  16. public function test_users_can_authenticate_using_the_login_screen()
  17. {
  18. $user = User::factory()->create();
  19. $response = $this->post(route('login.store'), [
  20. 'email' => $user->email,
  21. 'password' => 'password',
  22. ]);
  23. $this->assertAuthenticated();
  24. $response->assertRedirect(route('dashboard', absolute: false));
  25. }
  26. public function test_users_with_two_factor_enabled_are_redirected_to_two_factor_challenge()
  27. {
  28. $this->skipUnlessFortifyHas(Features::twoFactorAuthentication());
  29. Features::twoFactorAuthentication([
  30. 'confirm' => true,
  31. 'confirmPassword' => true,
  32. ]);
  33. $user = User::factory()->withTwoFactor()->create();
  34. $response = $this->post(route('login'), [
  35. 'email' => $user->email,
  36. 'password' => 'password',
  37. ]);
  38. $response->assertRedirect(route('two-factor.login'));
  39. $response->assertSessionHas('login.id', $user->id);
  40. $this->assertGuest();
  41. }
  42. public function test_users_can_not_authenticate_with_invalid_password()
  43. {
  44. $user = User::factory()->create();
  45. $this->post(route('login.store'), [
  46. 'email' => $user->email,
  47. 'password' => 'wrong-password',
  48. ]);
  49. $this->assertGuest();
  50. }
  51. public function test_users_can_logout()
  52. {
  53. $user = User::factory()->create();
  54. $response = $this->actingAs($user)->post(route('logout'));
  55. $response->assertRedirect(route('home'));
  56. $this->assertGuest();
  57. }
  58. public function test_users_are_rate_limited()
  59. {
  60. $user = User::factory()->create();
  61. RateLimiter::increment(md5('login'.implode('|', [$user->email, '127.0.0.1'])), amount: 5);
  62. $response = $this->post(route('login.store'), [
  63. 'email' => $user->email,
  64. 'password' => 'wrong-password',
  65. ]);
  66. $response->assertTooManyRequests();
  67. }
  68. }