AuthTest.php 2.5 KB

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