Advertisement
Guest User

Untitled

a guest
Mar 5th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. <?php
  2.  
  3. use {{namespace}}User;
  4. use Illuminate\Foundation\Testing\DatabaseMigrations;
  5. use Illuminate\Foundation\Testing\DatabaseTransactions;
  6.  
  7. class AuthTest extends TestCase
  8. {
  9. use DatabaseMigrations;
  10.  
  11. protected $name = 'Your name';
  12. protected $email = 'a@valid.email';
  13. protected $password = 'secret';
  14.  
  15. public function test_registration()
  16. {
  17. $this->visit('register')
  18. ->type($this->name, 'name')
  19. ->type($this->email, 'email')
  20. ->type($this->password, 'password')
  21. ->type($this->password, 'password_confirmation')
  22. ->press('Register')
  23. ->seeCredentials([
  24. 'name' => $this->name,
  25. 'email' => $this->email,
  26. 'password' => $this->password,
  27. ])
  28. ->see('Welcome')
  29. ->seePageIs('/')
  30. ->seeIsAuthenticated();
  31. }
  32.  
  33. public function test_login()
  34. {
  35. $this->createUser();
  36.  
  37. $this->visit('login')
  38. ->type($this->email, 'email')
  39. ->type($this->password, 'password')
  40. ->press('Login')
  41. ->see('Welcome')
  42. ->seePageIs('/')
  43. ->seeIsAuthenticated();
  44. }
  45.  
  46. public function test_logout()
  47. {
  48. $user = $this->createUser();
  49.  
  50. $this->actingAs($user)
  51. ->visit('logout')
  52. ->seePageIs('/')
  53. ->dontSeeIsAuthenticated();
  54. }
  55.  
  56. protected function createUser()
  57. {
  58. return factory(User::class)->create([
  59. 'email' => $this->email,
  60. 'password' => bcrypt($this->password)
  61. ]);
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement