forked from z-song/laravel-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsersTest.php
95 lines (79 loc) · 2.96 KB
/
UsersTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
use Encore\Admin\Auth\Database\Administrator;
class UsersTest extends TestCase
{
protected $user;
public function setUp()
{
parent::setUp();
$this->user = Administrator::first();
$this->be($this->user, 'admin');
}
public function testUsersIndexPage()
{
$this->visit('admin/auth/users')
->see('Administrator');
}
public function testCreateUser()
{
$user = [
'username' => 'Test',
'name' => 'Name',
'password' => '123456',
'password_confirmation' => '123456',
];
// create user
$this->visit('admin/auth/users/create')
->see('Create')
->submitForm('Submit', $user)
->seePageIs('admin/auth/users')
->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']);
// assign role to user
$this->visit('admin/auth/users/2/edit')
->see('Edit')
->submitForm('Submit', ['roles' => [1]])
->seePageIs('admin/auth/users')
->seeInDatabase(config('admin.database.role_users_table'), ['user_id' => 2, 'role_id' => 1]);
$this->visit('admin/auth/logout')
->dontSeeIsAuthenticated('admin')
->seePageIs('admin/auth/login')
->submitForm('Login', ['username' => $user['username'], 'password' => $user['password']])
->see('dashboard')
->seeIsAuthenticated('admin')
->seePageIs('admin');
$this->assertTrue($this->app['auth']->guard('admin')->getUser()->isAdministrator());
$this->see('<span>Users</span>')
->see('<span>Roles</span>')
->see('<span>Permission</span>')
->see('<span>Operation log</span>')
->see('<span>Menu</span>');
}
public function testUpdateUser()
{
$this->visit('admin/auth/users/'.$this->user->id.'/edit')
->see('Create')
->submitForm('Submit', ['name' => 'test', 'roles' => [1]])
->seePageIs('admin/auth/users')
->seeInDatabase(config('admin.database.users_table'), ['name' => 'test']);
}
public function testResetPassword()
{
$password = 'odjwyufkglte';
$data = [
'password' => $password,
'password_confirmation' => $password,
'roles' => [1],
];
$this->visit('admin/auth/users/'.$this->user->id.'/edit')
->see('Create')
->submitForm('Submit', $data)
->seePageIs('admin/auth/users')
->visit('admin/auth/logout')
->dontSeeIsAuthenticated('admin')
->seePageIs('admin/auth/login')
->submitForm('Login', ['username' => $this->user->username, 'password' => $password])
->see('dashboard')
->seeIsAuthenticated('admin')
->seePageIs('admin');
}
}