Completed
Push — develop ( e2b887...c09155 )
by
unknown
12:13
created

testImplementsAssertionInterface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2015 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace ApplicationsTest\Acl;
12
13
use Applications\Acl\ApplicationAccessAssertion;
14
use Applications\Entity\Application;
15
use Auth\Entity\User;
16
use Core\Entity\PermissionsInterface;
17
use Zend\Permissions\Acl\Acl;
18
use Zend\Permissions\Acl\Resource\GenericResource;
19
use Zend\Permissions\Acl\Resource\ResourceInterface;
20
use Zend\Permissions\Acl\Role\GenericRole;
21
use Zend\Permissions\Acl\Role\RoleInterface;
22
23
/**
24
 * Tests the ApplicationAccessAssertion
25
 *
26
 * @covers \Applications\Acl\ApplicationAccessAssertion
27
 * @author Mathias Gelhausen <[email protected]>
28
 * @group Applications
29
 * @group Applications.Acl
30
 */
31
class ApplicationAccessAssertionTest extends \PHPUnit_Framework_TestCase
32
{
33
34
    /**
35
     * Fixup of the Class under Test
36
     *
37
     * @var ApplicationAccessAssertion
38
     */
39
    private $target;
40
41
    /**
42
     * Fixup for the ACL needed as first Argument to assert().
43
     *
44
     * @var Acl
45
     */
46
    private $acl;
47
48
    public function setUp()
49
    {
50
        $this->target = new ApplicationAccessAssertion();
51
        $this->acl    = new Acl();
52
    }
53
    /**
54
     * @testdox Implements \Zend\Permsissions\Acl\Assertion\AssertionInterface
55
     */
56
    public function testImplementsAssertionInterface()
57
    {
58
        $this->assertInstanceOf('\Zend\Permissions\Acl\Assertion\AssertionInterface', $this->target);
59
    }
60
61
    public function provideAssertTestData()
62
    {
63
        $role = new GenericRole('Test');
64
        $resource = new GenericResource('Test');
65
        $user = new User();
66
        $user->setId('testuser');
67
        $user2 = new User();
68
        $user2->setId('testuser2');
69
        $app  = new Application();
70
        $app2 = new Application();
71
        $app2->getPermissions()->grant($user, PermissionsInterface::PERMISSION_VIEW)
72
                               ->grant($user2, PermissionsInterface::PERMISSION_CHANGE);
73
74
        return array(
75
            'nouser-noapp'     => array($role, $resource, null, false),
76
            'user-noapp'       => array($user, $resource, null, false),
77
            'user-app-no-perm' => array($role, $app, null, false),
78
            'read-not-granted' => array($user, $app, 'read', false),
79
            'change-not-granted' => array($user, $app, 'write', false),
80
            'read-granted' => array($user2, $app2, 'read', true),
81
            'change-granted' => array($user2, $app2, 'write', true),
82
            'change-not-granted2' => array($user, $app2, 'change', false),
83
        );
84
    }
85
86
    /**
87
     * @dataProvider provideAssertTestData
88
     *
89
     * @testdox assert() checks role and resource and resources' permissions if needed
90
     *
91
     * @param RoleInterface $role
92
     * @param ResourceInterface $resource
93
     * @param null|string $privilege
94
     * @param bool $expected
95
     */
96
    public function testAssert($role, $resource, $privilege, $expected)
97
    {
98
        if ($expected) {
99
            $this->assertTrue($this->target->assert($this->acl, $role, $resource, $privilege));
100
        } else {
101
            $this->assertFalse($this->target->assert($this->acl, $role, $resource, $privilege));
102
        }
103
    }
104
105
}