Completed
Push — master ( 014612...36ad26 )
by Mahmoud
03:39
created

SyncPermissionsOnRoleTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 40
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B testSyncDuplicatedPermissionsToRole_() 0 28 1
1
<?php
2
3
namespace App\Containers\Authorization\UI\API\Tests\Functional;
4
5
use App\Containers\Authorization\Models\Permission;
6
use App\Containers\Authorization\Models\Role;
7
use App\Containers\Authorization\Tests\TestCase;
8
9
/**
10
 * Class SyncPermissionsOnRoleTest.
11
 *
12
 * @author  Mahmoud Zalt <[email protected]>
13
 */
14
class SyncPermissionsOnRoleTest extends TestCase
15
{
16
17
    protected $endpoint = '/permissions/sync';
18
19
    protected $access = [
20
        'roles'       => 'admin',
21
        'permissions' => '',
22
    ];
23
24
    public function testSyncDuplicatedPermissionsToRole_()
25
    {
26
        $this->getTestingAdmin();
27
28
        $permissionA = factory(Permission::class)->create(['display_name' => 'AAA']);
29
        $permissionB = factory(Permission::class)->create(['display_name' => 'BBB']);
30
31
        $roleA = factory(Role::class)->create();
32
        $roleA->givePermissionTo($permissionA);
33
34
        $data = [
35
            'role_id'         => $roleA->getHashedKey(),
36
            'permissions_ids' => [$permissionA->getHashedKey(), $permissionB->getHashedKey()]
37
        ];
38
39
        // send the HTTP request
40
        $response = $this->apiCall($this->endpoint, 'post', $data, true);
41
42
        // assert response status is correct
43
        $this->assertEquals('200', $response->getStatusCode());
44
45
        $this->seeInDatabase('role_has_permissions', [
46
            'permission_id' => $permissionA->id,
47
            'permission_id' => $permissionB->id,
48
            'role_id'       => $roleA->id
49
        ]);
50
51
    }
52
53
}
54