1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the eZ Publish Kernel package. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\Core\Repository\Tests\Values\User; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Tests\Values\ValueObjectTestTrait; |
12
|
|
|
use eZ\Publish\Core\Repository\Values\User\Policy; |
13
|
|
|
use PHPUnit_Framework_TestCase; |
14
|
|
|
|
15
|
|
|
class PolicyTest extends PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
use ValueObjectTestTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Test a new class and default values on properties. |
21
|
|
|
* |
22
|
|
|
* @covers \eZ\Publish\API\Repository\Values\User\Policy::__construct |
23
|
|
|
*/ |
24
|
|
|
public function testNewClass() |
25
|
|
|
{ |
26
|
|
|
$this->assertPropertiesCorrect( |
27
|
|
|
[ |
28
|
|
|
'id' => null, |
29
|
|
|
'roleId' => null, |
30
|
|
|
'module' => null, |
31
|
|
|
'function' => null, |
32
|
|
|
'limitations' => [], |
33
|
|
|
], |
34
|
|
|
new Policy() |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Test retrieving missing property. |
40
|
|
|
* |
41
|
|
|
* @covers \eZ\Publish\API\Repository\Values\User\Policy::__get |
42
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException |
43
|
|
|
*/ |
44
|
|
|
public function testMissingProperty() |
45
|
|
|
{ |
46
|
|
|
$policy = new Policy(); |
47
|
|
|
$value = $policy->notDefined; |
|
|
|
|
48
|
|
|
self::fail('Succeeded getting non existing property'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Test setting read only property. |
53
|
|
|
* |
54
|
|
|
* @covers \eZ\Publish\API\Repository\Values\User\Policy::__set |
55
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
56
|
|
|
*/ |
57
|
|
|
public function testReadOnlyProperty() |
58
|
|
|
{ |
59
|
|
|
$policy = new Policy(); |
60
|
|
|
$policy->id = 42; |
|
|
|
|
61
|
|
|
self::fail('Succeeded setting read only property'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Test if property exists. |
66
|
|
|
* |
67
|
|
|
* @covers \eZ\Publish\API\Repository\Values\User\Policy::__isset |
68
|
|
|
*/ |
69
|
|
|
public function testIsPropertySet() |
70
|
|
|
{ |
71
|
|
|
$policy = new Policy(); |
72
|
|
|
$value = isset($policy->notDefined); |
73
|
|
|
self::assertEquals(false, $value); |
74
|
|
|
|
75
|
|
|
$value = isset($policy->id); |
|
|
|
|
76
|
|
|
self::assertEquals(true, $value); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Test unsetting a property. |
81
|
|
|
* |
82
|
|
|
* @covers \eZ\Publish\API\Repository\Values\User\Policy::__unset |
83
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
84
|
|
|
*/ |
85
|
|
|
public function testUnsetProperty() |
86
|
|
|
{ |
87
|
|
|
$policy = new Policy(['id' => 1]); |
88
|
|
|
unset($policy->id); |
89
|
|
|
self::fail('Unsetting read-only property succeeded'); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.