forked from BookStackApp/BookStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserSearchTest.php
More file actions
65 lines (52 loc) · 2.09 KB
/
UserSearchTest.php
File metadata and controls
65 lines (52 loc) · 2.09 KB
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
<?php
namespace Tests\User;
use BookStack\Users\Models\User;
use Tests\TestCase;
class UserSearchTest extends TestCase
{
public function test_select_search_matches_by_name()
{
$viewer = $this->users->viewer();
$admin = $this->users->admin();
$resp = $this->actingAs($admin)->get('/search/users/select?search=' . urlencode($viewer->name));
$resp->assertOk();
$resp->assertSee($viewer->name);
$resp->assertDontSee($admin->name);
}
public function test_select_search_shows_first_by_name_without_search()
{
/** @var User $firstUser */
$firstUser = User::query()->orderBy('name', 'desc')->first();
$resp = $this->asAdmin()->get('/search/users/select');
$resp->assertOk();
$resp->assertSee($firstUser->name);
}
public function test_select_search_does_not_match_by_email()
{
$viewer = $this->users->viewer();
$editor = $this->users->editor();
$resp = $this->actingAs($editor)->get('/search/users/select?search=' . urlencode($viewer->email));
$resp->assertDontSee($viewer->name);
}
public function test_select_requires_right_permission()
{
$permissions = ['users-manage', 'restrictions-manage-own', 'restrictions-manage-all'];
$user = $this->users->viewer();
foreach ($permissions as $permission) {
$resp = $this->actingAs($user)->get('/search/users/select?search=a');
$this->assertPermissionError($resp);
$this->permissions->grantUserRolePermissions($user, [$permission]);
$resp = $this->actingAs($user)->get('/search/users/select?search=a');
$resp->assertOk();
$user->roles()->delete();
$user->clearPermissionCache();
}
}
public function test_select_requires_logged_in_user()
{
$this->setSettings(['app-public' => true]);
$this->permissions->grantUserRolePermissions($this->users->guest(), ['users-manage']);
$resp = $this->get('/search/users/select?search=a');
$this->assertPermissionError($resp);
}
}