summaryrefslogtreecommitdiffstats
path: root/tests/Psecio/Gatekeeper/PolicyCollectionTest.php
blob: afa9e7a1af90e3bc551d299f95c5d4d269020634 (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
<?php

namespace Psecio\Gatekeeper;

class PolicyCollectionTest extends \Psecio\Gatekeeper\Base
{
    /**
     * Test the location of policies in the system
     */
    public function testFindPoliciesList()
    {
        $return = array(
            array('name' => 'policy1', 'expression' => 'test expression'),
            array('name' => 'policy2', 'expression' => '"group1" in user.groups.getName()')
        );

        $ds = $this->buildMock($return, 'fetch');
        $policies = new PolicyCollection($ds);

        $policies->getList();
        $this->assertCount(2, $policies);

        $policies = $policies->toArray();
        $this->assertTrue($policies[0] instanceof PolicyModel);
    }

    /**
     * Test the location of policies in the system
     */
    public function testFindPoliciesListLimit()
    {
        $return = array(
            array('name' => 'policy1', 'expression' => 'test expression')
        );

        $ds = $this->buildMock($return, 'fetch');
        $policies = new PolicyCollection($ds);

        $policies->getList(1);
        $this->assertCount(1, $policies);

        $policies = $policies->toArray();
        $this->assertTrue($policies[0] instanceof PolicyModel);
    }
}