summaryrefslogtreecommitdiffstats
path: root/tests/Psecio/Gatekeeper/UserPermissionCollectionTest.php
blob: 35c3a20d544c8929fa860e432b6b04d3de59f84a (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
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php

namespace Psecio\Gatekeeper;

class UserPermissionCollectionTest extends \Psecio\Gatekeeper\Base
{
    /**
     * Test the location of permissions of a member by ID
     */
    public function testFindPermissionsByUserId()
    {
        $userId = 1;
        $return = array(
            array('name' => 'perm1', 'description' => 'Permission #1'),
            array('name' => 'perm2', 'description' => 'Permission #2')
        );

        $ds = $this->buildMock($return, 'fetch');
        $permissions = new UserPermissionCollection($ds);

        $permissions->findByUserId($userId);
        $this->assertCount(2, $permissions);
    }

    /**
     * Test the creation of a user permission relation by permission ID
     */
    public function testCreateUserPermissionById()
    {
        $return = array(
            array('id' => 1, 'name' => 'perm5')
        );

        $ds = $this->buildMock($return, 'fetch');
        $permissions = new UserPermissionCollection($ds);
        $model = new UserPermissionModel($ds);

        $data = array(1, 2, 3);
        $permissions->create($model, $data);
    }

    /**
     * Test the creation of a user permission relation by permission model instance
     */
    public function testCreateUserPermissionByModel()
    {
        $return = array(
            array('id' => 1, 'name' => 'perm5'),
            array('id' => 2, 'name' => 'perm6')
        );

        $ds = $this->buildMock($return, 'fetch');
        $permissions = new UserPermissionCollection($ds);
        $model = new UserPermissionModel($ds);

        $data = array(
            new PermissionModel($ds, array('id' => 1)),
            new PermissionModel($ds, array('id' => 2)),
            new PermissionModel($ds, array('id' => 3))
        );
        $permissions->create($model, $data);
    }
}