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\Role; |
13
|
|
|
use PHPUnit_Framework_TestCase; |
14
|
|
|
|
15
|
|
View Code Duplication |
class RoleTest 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\Role::__construct |
23
|
|
|
*/ |
24
|
|
|
public function testNewClass() |
25
|
|
|
{ |
26
|
|
|
$this->assertPropertiesCorrect( |
27
|
|
|
[ |
28
|
|
|
'id' => null, |
29
|
|
|
'identifier' => null, |
30
|
|
|
'policies' => [], |
31
|
|
|
], |
32
|
|
|
new Role() |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Test retrieving missing property. |
38
|
|
|
* |
39
|
|
|
* @covers \eZ\Publish\API\Repository\Values\User\Role::__get |
40
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException |
41
|
|
|
*/ |
42
|
|
|
public function testMissingProperty() |
43
|
|
|
{ |
44
|
|
|
$role = new Role(); |
45
|
|
|
$value = $role->notDefined; |
|
|
|
|
46
|
|
|
self::fail('Succeeded getting non existing property'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Test setting read only property. |
51
|
|
|
* |
52
|
|
|
* @covers \eZ\Publish\API\Repository\Values\User\Role::__set |
53
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
54
|
|
|
*/ |
55
|
|
|
public function testReadOnlyProperty() |
56
|
|
|
{ |
57
|
|
|
$role = new Role(); |
58
|
|
|
$role->id = 42; |
|
|
|
|
59
|
|
|
self::fail('Succeeded setting read only property'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Test if property exists. |
64
|
|
|
* |
65
|
|
|
* @covers \eZ\Publish\API\Repository\Values\User\Role::__isset |
66
|
|
|
*/ |
67
|
|
|
public function testIsPropertySet() |
68
|
|
|
{ |
69
|
|
|
$role = new Role(); |
70
|
|
|
$value = isset($role->notDefined); |
71
|
|
|
self::assertEquals(false, $value); |
72
|
|
|
|
73
|
|
|
$value = isset($role->id); |
|
|
|
|
74
|
|
|
self::assertEquals(true, $value); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Test unsetting a property. |
79
|
|
|
* |
80
|
|
|
* @covers \eZ\Publish\API\Repository\Values\User\Role::__unset |
81
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
82
|
|
|
*/ |
83
|
|
|
public function testUnsetProperty() |
84
|
|
|
{ |
85
|
|
|
$role = new Role(['id' => 1]); |
86
|
|
|
unset($role->id); |
87
|
|
|
self::fail('Unsetting read-only property succeeded'); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.