FrontAccountsFeatureTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace Tests\Feature\Front\Accounts;
  3. use App\Shop\Customers\Customer;
  4. use Illuminate\Auth\Events\Lockout;
  5. use Tests\TestCase;
  6. class FrontAccountsFeatureTest extends TestCase
  7. {
  8. /** @test */
  9. public function it_can_show_the_reset_password_page()
  10. {
  11. $this->get(route('password.reset', $this->faker->uuid))
  12. ->assertStatus(200);
  13. }
  14. /** @test */
  15. public function it_throws_validation_error_during_registration()
  16. {
  17. $this->post(route('register'), [])
  18. ->assertStatus(302)
  19. ->assertSessionHasErrors();
  20. }
  21. /** @test */
  22. public function it_can_register_the_customer()
  23. {
  24. $data = [
  25. 'name' => $this->faker->name,
  26. 'email' => $this->faker->email,
  27. 'password' => 'secret',
  28. 'password_confirmation' => 'secret'
  29. ];
  30. $this->post(route('register'), $data)
  31. ->assertStatus(302)
  32. ->assertRedirect(route('accounts'));
  33. }
  34. /** @test */
  35. public function it_can_show_the_registration_page()
  36. {
  37. $this->get(route('register'))
  38. ->assertStatus(200)
  39. ->assertSee('Name')
  40. ->assertSee('E-Mail Address')
  41. ->assertSee('Password')
  42. ->assertSee('Confirm Password');
  43. }
  44. /** @test */
  45. public function it_shows_the_password_reset_page()
  46. {
  47. $this->get(route('password.request'))
  48. ->assertStatus(200)
  49. ->assertSee('E-Mail Address')
  50. ->assertSee('Send Password Reset Link')
  51. ->assertSee('Reset Password');
  52. }
  53. /** @test */
  54. public function it_shows_the_login_form()
  55. {
  56. $this->get(route('login'))
  57. ->assertStatus(200)
  58. ->assertSee('Email')
  59. ->assertSee('Password')
  60. ->assertSee('Login now')
  61. ->assertSee('I forgot my password')
  62. ->assertSee('No account? Register here.');
  63. }
  64. /** @test */
  65. public function it_shows_the_account_page_after_successful_login()
  66. {
  67. $this
  68. ->post(route('login'), ['email' => $this->customer->email, 'password' => 'secret'])
  69. ->assertStatus(302)
  70. ->assertRedirect(route('accounts', ['tab' => 'profile']));
  71. }
  72. /** @test */
  73. public function it_throws_the_too_many_login_attempts_event()
  74. {
  75. $this->expectsEvents(Lockout::class);
  76. $customer = factory(Customer::class)->create();
  77. for ($i=0; $i <= 5; $i++) {
  78. $data = [
  79. 'email' => $customer->email,
  80. 'password' => 'unknown'
  81. ];
  82. $this->post(route('login'), $data);
  83. }
  84. }
  85. /** @test */
  86. public function it_can_show_the_user_account()
  87. {
  88. $this
  89. ->actingAs($this->customer, 'web')
  90. ->get(route('accounts'))
  91. ->assertStatus(200);
  92. }
  93. /** @test */
  94. public function it_can_go_to_my_accounts_page_on_successful_login()
  95. {
  96. $customer = factory(Customer::class)->create();
  97. $data = [
  98. 'email' => $customer->email,
  99. 'password' => 'secret'
  100. ];
  101. $this->post(route('login'), $data)
  102. ->assertStatus(302)
  103. ->assertRedirect(route('accounts', ['tab' => 'profile']));
  104. }
  105. /** @test */
  106. public function it_errors_when_the_customer_is_logging_in_without_the_email_or_password()
  107. {
  108. $this
  109. ->post('login', [])
  110. ->assertSessionHasErrors([
  111. 'email' => 'The email field is required.',
  112. 'password' => 'The password field is required.'
  113. ]);
  114. }
  115. }