summaryrefslogtreecommitdiff
path: root/tests/Unit/Models/Auth/PermissionTest.php
blob: bb5f7605a73f24b0be598f117d878256a6985fbe (plain)
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
<?php

namespace Engelsystem\Test\Unit\Models\Auth;

use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Engelsystem\Models\Auth\Permission;

class PermissionTest extends AuthModelTest
{
    use ArraySubsetAsserts;

    /** @var array */
    protected $data = [
        'name'        => 'foo.bar',
        'description' => 'Allows bar in foo',
    ];

    /**
     * @covers \Engelsystem\Models\Auth\Permission::roles
     */
    public function testPermissions()
    {
        $role = $this->getRole();
        $role2 = $this->getRole([], ['name' => 'Example Role']);

        $permission = new Permission($this->data);
        $permission->save();
        $permission->roles()->attach($role);
        $permission->roles()->attach($role2);

        $this->assertCount(2, $permission->roles);
        $this->assertEquals('Test Role', $permission->roles()->get()->first()->name);
    }

    /**
     * @covers \Engelsystem\Models\Auth\Permission::users
     */
    public function testUsers()
    {
        $role = $this->getRole();
        $team = $this->getTeam($role);
        $this->getUser($team);

        $permission = new Permission($this->data);
        $permission->save();
        $permission->roles()->attach($role);

        $this->assertEquals('Test User', $permission->users()->get()->first()->name);
    }
}