AuthTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. $this->browse(function (Browser $browser) {
  16. $browser->visit(test_admin_path('auth/login'))
  17. ->assertSee(__('admin.login'));
  18. });
  19. }
  20. public function testVisitWithoutLogin()
  21. {
  22. $this->browse(function (Browser $browser) {
  23. $browser->visit(test_admin_path('/'))
  24. ->assertPathIs(test_admin_path('auth/login'))
  25. ->assertGuest('admin');
  26. });
  27. }
  28. public function testLogin()
  29. {
  30. $this->browse(function (Browser $browser) {
  31. $credentials = ['username' => 'admin', 'password' => 'admin'];
  32. $browser->visit(test_admin_path('auth/login'))
  33. ->assertPathIs(test_admin_path('auth/login'))
  34. ->assertSee(__('admin.login'))
  35. ->type('username', $credentials['username'])
  36. ->type('password', $credentials['password'])
  37. ->press(__('admin.login'))
  38. ->waitForLocation(test_admin_path('/'), 3)
  39. ->assertPathIs(test_admin_path('/'))
  40. ->assertSee('Administrator')
  41. ->assertSee('Dashboard')
  42. ->assertSee('Description...')
  43. ->assertSee('New Users')
  44. ->assertSee('New Devices')
  45. ->assertSee('Tickets')
  46. ->assertSee(strtoupper(__('admin.documentation')))
  47. ->assertSee(strtoupper(__('admin.extensions')))
  48. ->assertSee(strtoupper(__('admin.demo')))
  49. ->assertSee('GITHUB');
  50. $browser->within('.main-menu-content', function (Browser $browser) {
  51. $browser->assertSee('Admin')
  52. ->clickLink('Admin')
  53. ->waitForText('Users', 1)
  54. ->waitForText('Roles', 1)
  55. ->waitForText('Permission', 1)
  56. ->waitForText('Operation log', 1)
  57. ->waitForText('Menu', 1);
  58. });
  59. });
  60. }
  61. public function testLogout()
  62. {
  63. $this->browse(function (Browser $browser) {
  64. $browser->visit(test_admin_path('auth/logout'))
  65. ->assertPathIs(test_admin_path('auth/login'))
  66. ->assertGuest('admin');
  67. });
  68. }
  69. }