UsersTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Dcat\Admin\Tests\Feature;
  3. use Dcat\Admin\Tests\TestCase;
  4. /**
  5. * @group user
  6. */
  7. class UsersTest extends TestCase
  8. {
  9. public function testUsersIndexPage()
  10. {
  11. $this->visit('admin/auth/users')
  12. ->see('Administrator');
  13. }
  14. public function testCreateUser()
  15. {
  16. $user = [
  17. 'username' => 'Test',
  18. 'name' => 'Name',
  19. 'password' => '123456',
  20. 'password_confirmation' => '123456',
  21. ];
  22. // create user
  23. $this->visit('admin/auth/users/create')
  24. ->see('Create')
  25. ->submitForm('Submit', $user)
  26. ->seePageIs('admin/auth/users')
  27. ->seeInDatabase(config('admin.database.users_table'), ['username' => $user['username'], 'name' => $user['name']]);
  28. // assign role to user
  29. $this->visit('admin/auth/users/2/edit')
  30. ->see('Edit')
  31. ->submitForm('Submit', ['roles' => [1]])
  32. ->seePageIs('admin/auth/users')
  33. ->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 2, 'role_id' => 1]);
  34. $this->visit('admin/auth/logout')
  35. ->dontSeeIsAuthenticated('admin')
  36. ->seePageIs('admin/auth/login')
  37. ->submitForm('Login', ['username' => $user['username'], 'password' => $user['password']])
  38. ->see('dashboard')
  39. ->seeIsAuthenticated('admin')
  40. ->seePageIs('admin');
  41. $this->assertTrue($this->app['auth']->guard('admin')->getUser()->isAdministrator());
  42. $this->see('<span>Users</span>')
  43. ->see('<span>Roles</span>')
  44. ->see('<span>Permission</span>')
  45. ->see('<span>Operation log</span>')
  46. ->see('<span>Menu</span>');
  47. }
  48. public function testUpdateUser()
  49. {
  50. $this->visit('admin/auth/users/'.$this->user->id.'/edit')
  51. ->see('Edit')
  52. ->submitForm('Submit', ['name' => 'test', 'roles' => [1]])
  53. ->seePageIs('admin/auth/users')
  54. ->seeInDatabase(config('admin.database.users_table'), ['name' => 'test']);
  55. }
  56. public function testResetPassword()
  57. {
  58. $password = 'odjwyufkglte';
  59. $data = [
  60. 'password' => $password,
  61. 'password_confirmation' => $password,
  62. 'roles' => [1],
  63. ];
  64. $this->visit('admin/auth/users/'.$this->user->id.'/edit')
  65. ->see('Edit')
  66. ->submitForm('Submit', $data)
  67. ->seePageIs('admin/auth/users')
  68. ->visit('admin/auth/logout')
  69. ->dontSeeIsAuthenticated('admin')
  70. ->seePageIs('admin/auth/login')
  71. ->submitForm('Login', ['username' => $this->user->username, 'password' => $password])
  72. ->see('dashboard')
  73. ->seeIsAuthenticated('admin')
  74. ->seePageIs('admin');
  75. }
  76. }