AuthTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Tests\Browser;
  3. use Laravel\Dusk\Browser;
  4. use Tests\TestCase;
  5. /**
  6. * @group auth
  7. */
  8. class AuthTest extends TestCase
  9. {
  10. protected $login = false;
  11. public function testLoginPage()
  12. {
  13. $this->browse(function (Browser $browser) {
  14. $browser->visit(test_admin_path('auth/login'))
  15. ->assertSee(__('admin.login'));
  16. });
  17. }
  18. public function testVisitWithoutLogin()
  19. {
  20. $this->browse(function (Browser $browser) {
  21. $browser->visit(test_admin_path('/'))
  22. ->assertPathIs(test_admin_path('auth/login'))
  23. ->assertGuest('admin');
  24. });
  25. }
  26. public function testLogin()
  27. {
  28. $this->browse(function (Browser $browser) {
  29. $credentials = ['username' => 'admin', 'password' => 'admin'];
  30. $browser->visit(test_admin_path('auth/login'))
  31. ->assertPathIs(test_admin_path('auth/login'))
  32. ->assertSee(__('admin.login'))
  33. ->type('username', $credentials['username'])
  34. ->type('password', $credentials['password'])
  35. ->press(__('admin.login'))
  36. // ->waitForText(__('admin.login_successful'), 2)
  37. ->waitForLocation(test_admin_path('/'), 3)
  38. ->assertPathIs(test_admin_path('/'))
  39. ->assertSee('Administrator')
  40. ->assertSee('Dashboard')
  41. ->assertSee('Description...')
  42. ->assertSee('New Users')
  43. ->assertSee('New Devices')
  44. ->assertSee('Tickets')
  45. ->assertSee(__('admin.documentation'))
  46. ->assertSee(__('admin.extensions'))
  47. ->assertSee(__('admin.demo'))
  48. ->assertSee('GITHUB');
  49. $browser->within('.main-menu-content', function (Browser $browser) {
  50. $browser->assertSee('Admin')
  51. ->clickLink('Admin')
  52. ->waitForText('Users', 1)
  53. ->waitForText('Roles', 1)
  54. ->waitForText('Permission', 1)
  55. ->waitForText('Operation log', 1)
  56. ->waitForText('Menu', 1);
  57. });
  58. });
  59. }
  60. public function testLogout()
  61. {
  62. $this->browse(function (Browser $browser) {
  63. $browser->visit(test_admin_path('auth/logout'))
  64. ->assertPathIs(test_admin_path('auth/login'))
  65. ->assertGuest('admin');
  66. });
  67. }
  68. }