1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing a test 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
|
|
|
* @version //autogentag// |
10
|
|
|
*/ |
11
|
|
|
namespace eZ\Publish\Core\REST\Server\Tests\Output\ValueObjectVisitor; |
12
|
|
|
|
13
|
|
|
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest; |
14
|
|
|
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor; |
15
|
|
|
use eZ\Publish\Core\Repository\Values\User; |
16
|
|
|
use eZ\Publish\Core\REST\Server\Values; |
17
|
|
|
|
18
|
|
View Code Duplication |
class RestUserGroupRoleAssignmentTest extends ValueObjectVisitorBaseTest |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Test the RestUserGroupRoleAssignment visitor. |
22
|
|
|
* |
23
|
|
|
* @return string |
24
|
|
|
*/ |
25
|
|
|
public function testVisit() |
26
|
|
|
{ |
27
|
|
|
$visitor = $this->getVisitor(); |
28
|
|
|
$generator = $this->getGenerator(); |
29
|
|
|
|
30
|
|
|
$generator->startDocument(null); |
31
|
|
|
|
32
|
|
|
$userGroupRoleAssignment = new Values\RestUserGroupRoleAssignment( |
33
|
|
|
new User\UserGroupRoleAssignment( |
34
|
|
|
array( |
35
|
|
|
'role' => new User\Role( |
36
|
|
|
array( |
37
|
|
|
'id' => 42, |
38
|
|
|
'identifier' => 'some-role', |
39
|
|
|
) |
40
|
|
|
), |
41
|
|
|
) |
42
|
|
|
), |
43
|
|
|
'/1/5/14' |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
$this->addRouteExpectation( |
47
|
|
|
'ezpublish_rest_loadRoleAssignmentForUserGroup', |
48
|
|
|
array( |
49
|
|
|
'groupPath' => '1/5/14', |
50
|
|
|
'roleId' => $userGroupRoleAssignment->roleAssignment->role->id, |
51
|
|
|
), |
52
|
|
|
"/user/groups/1/5/14/roles/{$userGroupRoleAssignment->roleAssignment->role->id}" |
53
|
|
|
); |
54
|
|
|
$this->addRouteExpectation( |
55
|
|
|
'ezpublish_rest_loadRole', |
56
|
|
|
array('roleId' => $userGroupRoleAssignment->roleAssignment->role->id), |
57
|
|
|
"/user/roles/{$userGroupRoleAssignment->roleAssignment->role->id}" |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$visitor->visit( |
61
|
|
|
$this->getVisitorMock(), |
|
|
|
|
62
|
|
|
$generator, |
63
|
|
|
$userGroupRoleAssignment |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$result = $generator->endDocument(null); |
67
|
|
|
|
68
|
|
|
$this->assertNotNull($result); |
69
|
|
|
|
70
|
|
|
return $result; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Test if result contains RoleAssignment element. |
75
|
|
|
* |
76
|
|
|
* @param string $result |
77
|
|
|
* |
78
|
|
|
* @depends testVisit |
79
|
|
|
*/ |
80
|
|
|
public function testResultContainsRoleAssignmentElement($result) |
81
|
|
|
{ |
82
|
|
|
$this->assertXMLTag( |
83
|
|
|
array( |
84
|
|
|
'tag' => 'RoleAssignment', |
85
|
|
|
'children' => array( |
86
|
|
|
'count' => 1, |
87
|
|
|
), |
88
|
|
|
), |
89
|
|
|
$result, |
90
|
|
|
'Invalid <RoleAssignment> element.', |
91
|
|
|
false |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Test if result contains RoleAssignment element attributes. |
97
|
|
|
* |
98
|
|
|
* @param string $result |
99
|
|
|
* |
100
|
|
|
* @depends testVisit |
101
|
|
|
*/ |
102
|
|
|
public function testResultContainsRoleAssignmentAttributes($result) |
103
|
|
|
{ |
104
|
|
|
$this->assertXMLTag( |
105
|
|
|
array( |
106
|
|
|
'tag' => 'RoleAssignment', |
107
|
|
|
'attributes' => array( |
108
|
|
|
'media-type' => 'application/vnd.ez.api.RoleAssignment+xml', |
109
|
|
|
'href' => '/user/groups/1/5/14/roles/42', |
110
|
|
|
), |
111
|
|
|
), |
112
|
|
|
$result, |
113
|
|
|
'Invalid <RoleAssignment> attributes.', |
114
|
|
|
false |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Test if result contains Role element. |
120
|
|
|
* |
121
|
|
|
* @param string $result |
122
|
|
|
* |
123
|
|
|
* @depends testVisit |
124
|
|
|
*/ |
125
|
|
|
public function testResultContainsRoleElement($result) |
126
|
|
|
{ |
127
|
|
|
$this->assertXMLTag( |
128
|
|
|
array( |
129
|
|
|
'tag' => 'Role', |
130
|
|
|
), |
131
|
|
|
$result, |
132
|
|
|
'Invalid <Role> element.', |
133
|
|
|
false |
134
|
|
|
); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Test if result contains Role element attributes. |
139
|
|
|
* |
140
|
|
|
* @param string $result |
141
|
|
|
* |
142
|
|
|
* @depends testVisit |
143
|
|
|
*/ |
144
|
|
|
public function testResultContainsRoleAttributes($result) |
145
|
|
|
{ |
146
|
|
|
$this->assertXMLTag( |
147
|
|
|
array( |
148
|
|
|
'tag' => 'Role', |
149
|
|
|
'attributes' => array( |
150
|
|
|
'media-type' => 'application/vnd.ez.api.Role+xml', |
151
|
|
|
'href' => '/user/roles/42', |
152
|
|
|
), |
153
|
|
|
), |
154
|
|
|
$result, |
155
|
|
|
'Invalid <Role> attributes.', |
156
|
|
|
false |
157
|
|
|
); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Get the RestUserGroupRoleAssignment visitor. |
162
|
|
|
* |
163
|
|
|
* @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestUserGroupRoleAssignment |
164
|
|
|
*/ |
165
|
|
|
protected function internalGetVisitor() |
166
|
|
|
{ |
167
|
|
|
return new ValueObjectVisitor\RestUserGroupRoleAssignment(); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|
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.