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