AuthTest.php 2.3 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('Login')
  33. ->type('username', $credentials['username'])
  34. ->type('password', $credentials['password'])
  35. ->press('Login')
  36. ->assertPathIs(test_admin_path('/'))
  37. ->assertSee('Administrator')
  38. ->assertSee('Dashboard')
  39. ->assertSee('Description...')
  40. ->assertSee('Environment')
  41. ->assertSee('PHP version')
  42. ->assertSee('Laravel version')
  43. ->assertSee('Extensions')
  44. ->assertSee('Dependencies')
  45. ->assertSee('php')
  46. ->assertSee('laravel/framework');
  47. //->assertAuthenticated('admin');
  48. $browser->within('.main-sidebar', function (Browser $browser) {
  49. $browser->assertSee('Admin')
  50. ->clickLink('Admin')
  51. ->waitForText('Users', 1)
  52. ->waitForText('Roles', 1)
  53. ->waitForText('Permission', 1)
  54. ->waitForText('Operation log', 1)
  55. ->waitForText('Menu', 1);
  56. });
  57. });
  58. }
  59. public function testLogout()
  60. {
  61. $this->browse(function (Browser $browser) {
  62. $browser->visit(test_admin_path('auth/logout'))
  63. ->assertPathIs(test_admin_path('auth/login'))
  64. ->assertGuest('admin');
  65. });
  66. }
  67. }