Guest User

Untitled

a guest
Dec 10th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Tests\Feature\Auth;
  4.  
  5. use App\User;
  6. use Illuminate\Support\Facades\Notification;
  7. use Illuminate\Support\Facades\Password;
  8. use Illuminate\Support\Facades\Hash;
  9. use Tests\TenantTestCase;
  10.  
  11. class ResetPasswordTest extends TenantTestCase
  12. {
  13.  
  14. protected $url;
  15.  
  16. protected function duringSetup()
  17. {
  18. $this->setUpHostnames(true);
  19. $this->setUpWebsites(true, true);
  20. $this->activateTenant();
  21.  
  22.  
  23. $this->url = $this->tenantUrl . '/password';
  24. }
  25.  
  26. protected function getValidToken($user)
  27. {
  28. return Password::broker()->createToken($user);
  29. }
  30.  
  31. /** @test */
  32. public function browseEmailPage()
  33. {
  34. // Visit password reset email page
  35. $this->get($this->url.'/reset')
  36. ->assertViewIs('auth.passwords.email')
  37. ->assertSee('Reset Password - ' . env('APP_NAME'));
  38.  
  39. }
  40.  
  41. /** @test */
  42. public function browseResetPageWithInvalidToken()
  43. {
  44.  
  45. // Visit reset page without valid token
  46. $this->get($this->url.'reset/invalidtoken')
  47. ->assertStatus(404);
  48.  
  49. }
  50.  
  51. /** @test */
  52. public function sendResetEmail()
  53. {
  54. Notification::fake();
  55.  
  56. // Visit Page first for correct redirect
  57. $this->get($this->url.'/reset');
  58.  
  59. // Send invalid request
  60. $this->post($this->url.'/email', [])
  61. ->assertRedirect($this->url.'/reset')
  62. ->assertSessionHasErrors();
  63.  
  64. $user = factory(User::class)->create();
  65.  
  66. // Send valid response
  67. $this->post($this->url.'/email', [
  68. 'email' => $user->email,
  69. ])
  70. ->assertRedirect($this->url.'/reset')
  71. ->assertSessionHasNoErrors();
  72.  
  73. //Make sure email was sent
  74. Notification::assertSentTo($user, \Illuminate\Auth\Notifications\ResetPassword::class);
  75.  
  76. // Send invalid email
  77. $this->post($this->url.'/email', [
  78. 'email' => 'test@email.com',
  79. ])
  80. ->assertRedirect($this->url.'/reset')
  81. ->assertSessionHasErrors();
  82. }
  83.  
  84. /** @test */
  85. public function resetPassword()
  86. {
  87.  
  88. $user = factory(User::class)->create();
  89.  
  90. $token = $this->getValidToken($user);
  91.  
  92. $this->get($this->url.'/reset/'.$token)
  93. ->assertOk()
  94. ->assertViewIs('auth.passwords.reset')
  95. ->assertSee('Reset Password - ' . env('APP_NAME'));
  96.  
  97. $this->post($this->url.'/reset', [
  98. 'token' => $token,
  99. 'email' => $user->email,
  100. 'password' => 'new-awesome-password',
  101. 'password_confirmation' => 'new-awesome-password',
  102. ])
  103. ->assertRedirect($this->tenantUrl . '/home');
  104.  
  105. $this->assertTrue(Hash::check('new-awesome-password', $user->fresh()->password));
  106. $this->assertAuthenticatedAs($user);
  107. }
  108.  
  109. }
Add Comment
Please, Sign In to add comment