AuthTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. // ->waitForText(__('admin.login_successful'), 2)
  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. }