-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathProcessPermissionsTest.php
More file actions
69 lines (55 loc) · 2.1 KB
/
Copy pathProcessPermissionsTest.php
File metadata and controls
69 lines (55 loc) · 2.1 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
66
67
68
69
<?php
namespace Tests\Feature\Api;
use Database\Seeders\PermissionSeeder;
use Illuminate\Support\Facades\Hash;
use ProcessMaker\Models\Group;
use ProcessMaker\Models\GroupMember;
use ProcessMaker\Models\Permission;
use ProcessMaker\Models\PermissionAssignment;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessPermission;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Models\User;
use Tests\Feature\Shared\RequestHelper;
use Tests\TestCase;
class ProcessPermissionsTest extends TestCase
{
use RequestHelper;
protected $resource = 'requests';
public $withPermissions = true;
protected function withUserSetup()
{
$this->user->is_administrator = false;
$this->user->save();
(new PermissionSeeder)->run($this->user);
}
public function testUpdateProcessPermissionRequestCancelTypeUser()
{
// Create a process
$process = Process::factory()->create();
// Create a "normal" user
$normalUser = User::factory()->create([
'password' => Hash::make('password'),
]);
// We haven't assigned cancel permissions to this process, so let's
// assert that our "normal" user cannot cancel it
$this->assertFalse($normalUser->can('cancel', $process));
// Ensure our primary user can edit processes
$this->user->giveDirectPermission('edit-processes');
$this->user->refresh();
$this->flushSession();
// Add the "normal" user to the list of users that have permission to
// cancel the process
$route = route('api.processes.update', [$process->id]);
$response = $this->apiCall('PUT', $route, [
'name' => 'Update Process',
'description' => 'Update Test',
'cancel_request' => ['users' => [$normalUser->id], 'groups' => []],
]);
// Assert that the API returned a valid response
$response->assertStatus(200, $response);
// Assert that our "normal user" can now cancel the process
$process->refresh();
$this->assertTrue($normalUser->can('cancel', $process));
}
}