LoginControllerTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace Tests\Feature;
  3. use Tests\TestCase;
  4. class LoginControllerTest extends TestCase
  5. {
  6. /** @test */
  7. public function it_loads_the_login_page()
  8. {
  9. $response = $this->get(route('login.show'));
  10. $this->assertSame(200, $response->getStatusCode());
  11. }
  12. /** @test */
  13. public function it_redirect_to_login_with_no_data()
  14. {
  15. $response = $this->post(route('login.show'));
  16. $this->assertSame(302, $response->getStatusCode());
  17. $this->assertSame(route('login.show'), $response->getHeaderLine('Location'));
  18. }
  19. /** @test */
  20. public function it_login_with_correct_data()
  21. {
  22. $this->createAdminUser();
  23. $response = $this->get(route('login.show'));
  24. $form = $this->getCrawler($response)
  25. ->selectButton('Login')
  26. ->form([
  27. 'username' => 'admin@example.com',
  28. 'password' => 'admin',
  29. ], 'POST');
  30. $response = $this->submitForm($form);
  31. $this->assertSame(302, $response->getStatusCode());
  32. $this->assertSame(route('home'), $response->getHeaderLine('Location'));
  33. $response = $this->get(route('home'));
  34. $this->assertSame(200, $response->getStatusCode());
  35. }
  36. /** @test */
  37. public function it_hide_register_by_default()
  38. {
  39. $response = $this->get(route('login.show'));
  40. $this->assertSame(200, $response->getStatusCode());
  41. $this->assertStringNotContainsString('Register', $this->getCrawler($response)->text());
  42. }
  43. /** @test */
  44. public function it_show_register_when_enabled()
  45. {
  46. $this->updateSetting('register_enabled', 'on');
  47. $response = $this->get(route('login.show'));
  48. $this->assertSame(200, $response->getStatusCode());
  49. $this->assertStringContainsString('Register', $this->getCrawler($response)->text());
  50. }
  51. /** @test */
  52. public function it_redirect_to_home_if_logged_in()
  53. {
  54. $this->createAdminUser();
  55. $response = $this->get(route('login.show'));
  56. $form = $this->getCrawler($response)
  57. ->selectButton('Login')
  58. ->form([
  59. 'username' => 'admin@example.com',
  60. 'password' => 'admin',
  61. ], 'POST');
  62. $this->submitForm($form);
  63. $response = $this->get(route('login'));
  64. $this->assertSame(302, $response->getStatusCode());
  65. }
  66. /** @test */
  67. public function it_set_the_remember_token()
  68. {
  69. $this->createAdminUser();
  70. $response = $this->get(route('login.show'));
  71. $form = $this->getCrawler($response)
  72. ->selectButton('Login')
  73. ->form([
  74. 'username' => 'admin@example.com',
  75. 'password' => 'admin',
  76. 'remember' => 'on',
  77. ], 'POST');
  78. $response = $this->submitForm($form);
  79. dd($response->getHeaders());
  80. }
  81. }