|
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 JobsTest\Acl; |
|
12
|
|
|
|
|
13
|
|
|
use Auth\Entity\User; |
|
14
|
|
|
use Jobs\Acl\CreateAssertion; |
|
15
|
|
|
use Zend\Permissions\Acl\Acl; |
|
16
|
|
|
use Zend\Permissions\Acl\Resource\ResourceInterface; |
|
17
|
|
|
use Zend\Permissions\Acl\Role\GenericRole; |
|
18
|
|
|
use Zend\Permissions\Acl\Role\RoleInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Test of Jobs\Acl\CreateAssertion |
|
22
|
|
|
* |
|
23
|
|
|
* @covers \Jobs\Acl\CreateAssertion |
|
24
|
|
|
* @author Mathias Gelhausen <[email protected]> |
|
25
|
|
|
* @group Jobs |
|
26
|
|
|
* @group Jobs.Acl |
|
27
|
|
|
*/ |
|
28
|
|
|
class CreateAssertionTest extends \PHPUnit_Framework_TestCase |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @coversNothing |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testExtendsBaseClass() |
|
35
|
|
|
{ |
|
36
|
|
|
$target = new CreateAssertion(); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertInstanceOf('\Acl\Assertion\AbstractEventManagerAwareAssertion', $target); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @coversNothing |
|
43
|
|
|
*/ |
|
44
|
|
|
public function testProvidesDefaultEventManagerIdentifiers() |
|
45
|
|
|
{ |
|
46
|
|
|
$target = new CreateAssertion(); |
|
47
|
|
|
$expected = array( |
|
48
|
|
|
'Jobs/Acl/Assertions', |
|
49
|
|
|
'Jobs/Acl/Assertion/Create', |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertAttributeEquals($expected, 'identifiers', $target); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testPreAssertConditions() |
|
56
|
|
|
{ |
|
57
|
|
|
$target = new CreateAssertionMock(); |
|
58
|
|
|
|
|
59
|
|
|
$acl = new Acl(); |
|
60
|
|
|
$role = new GenericRole('test'); |
|
61
|
|
|
|
|
62
|
|
|
// non user is always false? |
|
63
|
|
|
$this->assertFalse($target->assert($acl, $role, null, 'test')); |
|
64
|
|
|
$this->assertFalse($target->assert($acl, $role, null, 'new')); |
|
65
|
|
|
|
|
66
|
|
|
// user and wrong privilege is false? |
|
67
|
|
|
$role = new User(); |
|
68
|
|
|
$this->assertFalse($target->assert($acl, $role, null, 'test')); |
|
69
|
|
|
|
|
70
|
|
|
// user and right privilege is null (meaning triggering event will be done)? |
|
71
|
|
|
$this->assertNull($target->assert($acl, $role, null, 'new')); |
|
72
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
class CreateAssertionMock extends CreateAssertion |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
|
|
public function assert(Acl $acl, |
|
79
|
|
|
RoleInterface $role = null, |
|
80
|
|
|
ResourceInterface $resource = null, |
|
81
|
|
|
$privilege = null |
|
82
|
|
|
) { |
|
83
|
|
|
return parent::preAssert($acl, $role, $resource, $privilege); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
} |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.