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