AuthTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace Tests\Browser\Cases;
  3. use Dcat\Admin\Admin;
  4. use Laravel\Dusk\Browser;
  5. use Tests\TestCase;
  6. /**
  7. * 鉴权登陆功能测试.
  8. *
  9. * @group auth
  10. */
  11. class AuthTest extends TestCase
  12. {
  13. protected $login = false;
  14. public function testLoginPage()
  15. {
  16. $this->browse(function (Browser $browser) {
  17. $browser->visit(admin_base_path('auth/login'))
  18. ->assertSeeText(__('admin.login'));
  19. });
  20. }
  21. public function testVisitWithoutLogin()
  22. {
  23. $this->browse(function (Browser $browser) {
  24. $browser->visit(admin_base_path('/'))
  25. ->assertPathIs(admin_base_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(admin_base_path('auth/login'))
  34. ->assertPathIs(admin_base_path('auth/login'))
  35. ->assertSeeText(__('admin.login'))
  36. ->type('username', $credentials['username'])
  37. ->type('password', $credentials['password'])
  38. ->press(__('admin.login'))
  39. ->waitForLocation(admin_base_path('/'), 3)
  40. ->assertPathIs(admin_base_path('/'))
  41. ->assertSeeText('Administrator')
  42. ->assertSeeText('Dashboard')
  43. ->assertSeeText('Description...')
  44. ->assertSeeText('New Users')
  45. ->assertSeeText('New Devices')
  46. ->assertSeeText('Tickets')
  47. ->assertSeeText((__('admin.documentation')))
  48. ->assertSeeText((__('admin.extensions')))
  49. ->assertSeeText((__('admin.demo')))
  50. ->assertSeeText('GITHUB');
  51. $browser->within('.main-menu-content', function (Browser $browser) {
  52. $browser->assertSeeText('Admin')
  53. ->clickLink($this->translateMenuTitle('Admin'));
  54. // ->waitForText($this->translateMenuTitle('Users'), 1)
  55. // ->waitForText($this->translateMenuTitle('Roles'), 1)
  56. // ->waitForText($this->translateMenuTitle('Permission'), 1)
  57. // ->waitForText($this->translateMenuTitle('Operation log'), 1)
  58. // ->waitForText($this->translateMenuTitle('Menu'), 1);
  59. });
  60. });
  61. }
  62. /**
  63. * 翻译菜单标题.
  64. *
  65. * @param $title
  66. * @return string
  67. */
  68. protected function translateMenuTitle($title)
  69. {
  70. return Admin::menu()->translate($title);
  71. }
  72. public function testLogout()
  73. {
  74. $this->browse(function (Browser $browser) {
  75. $browser->visit(admin_base_path('auth/logout'))
  76. ->assertPathIs(admin_base_path('auth/login'))
  77. ->assertGuest('admin');
  78. });
  79. }
  80. }