|
@@ 1102-1141 (lines=40) @@
|
| 1099 |
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
| 1100 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent |
| 1101 |
|
*/ |
| 1102 |
|
public function testCopyContentThrowsUnauthorizedException() |
| 1103 |
|
{ |
| 1104 |
|
$parentLocationId = $this->generateId('location', 52); |
| 1105 |
|
|
| 1106 |
|
$repository = $this->getRepository(); |
| 1107 |
|
|
| 1108 |
|
$contentService = $repository->getContentService(); |
| 1109 |
|
$locationService = $repository->getLocationService(); |
| 1110 |
|
|
| 1111 |
|
$anonymousUserId = $this->generateId('user', 10); |
| 1112 |
|
/* BEGIN: Use Case */ |
| 1113 |
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
| 1114 |
|
// demo installation |
| 1115 |
|
$contentVersion2 = $this->createMultipleLanguageContentVersion2(); |
| 1116 |
|
|
| 1117 |
|
// Get ContentInfo instance of version 2 |
| 1118 |
|
$contentInfo = $contentVersion2->contentInfo; |
| 1119 |
|
|
| 1120 |
|
// Load the user service |
| 1121 |
|
$userService = $repository->getUserService(); |
| 1122 |
|
|
| 1123 |
|
// Set anonymous user |
| 1124 |
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
| 1125 |
|
|
| 1126 |
|
// Configure new target location |
| 1127 |
|
$targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
| 1128 |
|
|
| 1129 |
|
$targetLocationCreate->priority = 42; |
| 1130 |
|
$targetLocationCreate->hidden = true; |
| 1131 |
|
$targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789'; |
| 1132 |
|
$targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
| 1133 |
|
$targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC; |
| 1134 |
|
|
| 1135 |
|
// This call will fail with a "UnauthorizedException" |
| 1136 |
|
$contentService->copyContent( |
| 1137 |
|
$contentInfo, |
| 1138 |
|
$targetLocationCreate |
| 1139 |
|
); |
| 1140 |
|
/* END: Use Case */ |
| 1141 |
|
} |
| 1142 |
|
|
| 1143 |
|
/** |
| 1144 |
|
* Test for the copyContent() method. |
|
@@ 1150-1187 (lines=38) @@
|
| 1147 |
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
| 1148 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContentWithThirdParameter |
| 1149 |
|
*/ |
| 1150 |
|
public function testCopyContentThrowsUnauthorizedExceptionWithThirdParameter() |
| 1151 |
|
{ |
| 1152 |
|
$parentLocationId = $this->generateId('location', 52); |
| 1153 |
|
|
| 1154 |
|
$repository = $this->getRepository(); |
| 1155 |
|
|
| 1156 |
|
$contentService = $repository->getContentService(); |
| 1157 |
|
$locationService = $repository->getLocationService(); |
| 1158 |
|
|
| 1159 |
|
$anonymousUserId = $this->generateId('user', 10); |
| 1160 |
|
/* BEGIN: Use Case */ |
| 1161 |
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
| 1162 |
|
// demo installation |
| 1163 |
|
$contentVersion2 = $this->createContentVersion2(); |
| 1164 |
|
|
| 1165 |
|
// Load the user service |
| 1166 |
|
$userService = $repository->getUserService(); |
| 1167 |
|
|
| 1168 |
|
// Set anonymous user |
| 1169 |
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
| 1170 |
|
|
| 1171 |
|
// Configure new target location |
| 1172 |
|
$targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
| 1173 |
|
|
| 1174 |
|
$targetLocationCreate->priority = 42; |
| 1175 |
|
$targetLocationCreate->hidden = true; |
| 1176 |
|
$targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789'; |
| 1177 |
|
$targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
| 1178 |
|
$targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC; |
| 1179 |
|
|
| 1180 |
|
// This call will fail with a "UnauthorizedException" |
| 1181 |
|
$contentService->copyContent( |
| 1182 |
|
$contentVersion2->contentInfo, |
| 1183 |
|
$targetLocationCreate, |
| 1184 |
|
$contentService->loadVersionInfo($contentVersion2->contentInfo, 1) |
| 1185 |
|
); |
| 1186 |
|
/* END: Use Case */ |
| 1187 |
|
} |
| 1188 |
|
|
| 1189 |
|
/** |
| 1190 |
|
* Test for the loadRelations() method. |