1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the UserGroupTest class. |
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\UserGroup; |
13
|
|
|
use PHPUnit_Framework_TestCase; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Test internal integrity of @see \eZ\Publish\Core\Repository\Values\User\UserGroup. |
17
|
|
|
*/ |
18
|
|
|
class UserGroupTest extends PHPUnit_Framework_TestCase |
19
|
|
|
{ |
20
|
|
|
use ValueObjectTestTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @covers \eZ\Publish\Core\Repository\Values\User\UserGroup::__construct |
24
|
|
|
*/ |
25
|
|
|
public function testNewClass() |
26
|
|
|
{ |
27
|
|
|
$group = new UserGroup(); |
28
|
|
|
self::assertEquals(null, $group->parentId); |
|
|
|
|
29
|
|
|
self::assertEquals(null, $group->subGroupCount); |
|
|
|
|
30
|
|
|
|
31
|
|
|
$this->assertPropertiesCorrect( |
32
|
|
|
[ |
33
|
|
|
'parentId' => null, |
34
|
|
|
'subGroupCount' => null, |
35
|
|
|
], |
36
|
|
|
$group |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Test retrieving missing property. |
42
|
|
|
* |
43
|
|
|
* @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__get |
44
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException |
45
|
|
|
*/ |
46
|
|
|
public function testMissingProperty() |
47
|
|
|
{ |
48
|
|
|
$userGroup = new UserGroup(); |
49
|
|
|
$value = $userGroup->notDefined; |
|
|
|
|
50
|
|
|
self::fail('Succeeded getting non existing property'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @covers \eZ\Publish\Core\Repository\Values\User\UserGroup::getProperties |
55
|
|
|
*/ |
56
|
|
View Code Duplication |
public function testObjectProperties() |
57
|
|
|
{ |
58
|
|
|
$object = new UserGroup(); |
59
|
|
|
$properties = $object->attributes(); |
|
|
|
|
60
|
|
|
self::assertNotContains('internalFields', $properties, 'Internal property found '); |
61
|
|
|
self::assertContains('id', $properties, 'Property not found '); |
62
|
|
|
self::assertContains('fields', $properties, 'Property not found '); |
63
|
|
|
self::assertContains('versionInfo', $properties, 'Property not found '); |
64
|
|
|
self::assertContains('contentInfo', $properties, 'Property not found '); |
65
|
|
|
|
66
|
|
|
// check for duplicates and double check existence of property |
67
|
|
|
$propertiesHash = []; |
68
|
|
|
foreach ($properties as $property) { |
69
|
|
|
if (isset($propertiesHash[$property])) { |
70
|
|
|
self::fail("Property '{$property}' exists several times in properties list"); |
71
|
|
|
} elseif (!isset($object->$property)) { |
72
|
|
|
self::fail("Property '{$property}' does not exist on object, even though it was hinted to be there"); |
73
|
|
|
} |
74
|
|
|
$propertiesHash[$property] = 1; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Test setting read only property. |
80
|
|
|
* |
81
|
|
|
* @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__set |
82
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
83
|
|
|
*/ |
84
|
|
|
public function testReadOnlyProperty() |
85
|
|
|
{ |
86
|
|
|
$userGroup = new UserGroup(); |
87
|
|
|
$userGroup->parentId = 42; |
|
|
|
|
88
|
|
|
self::fail('Succeeded setting read only property'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Test if property exists. |
93
|
|
|
* |
94
|
|
|
* @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__isset |
95
|
|
|
*/ |
96
|
|
|
public function testIsPropertySet() |
97
|
|
|
{ |
98
|
|
|
$userGroup = new UserGroup(); |
99
|
|
|
$value = isset($userGroup->notDefined); |
100
|
|
|
self::assertEquals(false, $value); |
101
|
|
|
|
102
|
|
|
$value = isset($userGroup->parentId); |
|
|
|
|
103
|
|
|
self::assertEquals(true, $value); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Test unsetting a property. |
108
|
|
|
* |
109
|
|
|
* @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__unset |
110
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
111
|
|
|
*/ |
112
|
|
|
public function testUnsetProperty() |
113
|
|
|
{ |
114
|
|
|
$userGroup = new UserGroup(['parentId' => 1]); |
115
|
|
|
unset($userGroup->parentId); |
116
|
|
|
self::fail('Unsetting read-only property succeeded'); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
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.