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

testSyncDuplicatedPermissionsToRole_()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 28
rs 8.8571
cc 1
eloc 15
nc 1
nop 0
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