|
@@ 1060-1099 (lines=40) @@
|
| 1057 |
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
| 1058 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent |
| 1059 |
|
*/ |
| 1060 |
|
public function testCopyContentThrowsUnauthorizedException() |
| 1061 |
|
{ |
| 1062 |
|
$parentLocationId = $this->generateId('location', 52); |
| 1063 |
|
|
| 1064 |
|
$repository = $this->getRepository(); |
| 1065 |
|
|
| 1066 |
|
$contentService = $repository->getContentService(); |
| 1067 |
|
$locationService = $repository->getLocationService(); |
| 1068 |
|
|
| 1069 |
|
$anonymousUserId = $this->generateId('user', 10); |
| 1070 |
|
/* BEGIN: Use Case */ |
| 1071 |
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
| 1072 |
|
// demo installation |
| 1073 |
|
$contentVersion2 = $this->createMultipleLanguageContentVersion2(); |
| 1074 |
|
|
| 1075 |
|
// Get ContentInfo instance of version 2 |
| 1076 |
|
$contentInfo = $contentVersion2->contentInfo; |
| 1077 |
|
|
| 1078 |
|
// Load the user service |
| 1079 |
|
$userService = $repository->getUserService(); |
| 1080 |
|
|
| 1081 |
|
// Set anonymous user |
| 1082 |
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
| 1083 |
|
|
| 1084 |
|
// Configure new target location |
| 1085 |
|
$targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
| 1086 |
|
|
| 1087 |
|
$targetLocationCreate->priority = 42; |
| 1088 |
|
$targetLocationCreate->hidden = true; |
| 1089 |
|
$targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789'; |
| 1090 |
|
$targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
| 1091 |
|
$targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC; |
| 1092 |
|
|
| 1093 |
|
// This call will fail with a "UnauthorizedException" |
| 1094 |
|
$contentService->copyContent( |
| 1095 |
|
$contentInfo, |
| 1096 |
|
$targetLocationCreate |
| 1097 |
|
); |
| 1098 |
|
/* END: Use Case */ |
| 1099 |
|
} |
| 1100 |
|
|
| 1101 |
|
/** |
| 1102 |
|
* Test for the copyContent() method. |
|
@@ 1108-1145 (lines=38) @@
|
| 1105 |
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
| 1106 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContentWithThirdParameter |
| 1107 |
|
*/ |
| 1108 |
|
public function testCopyContentThrowsUnauthorizedExceptionWithThirdParameter() |
| 1109 |
|
{ |
| 1110 |
|
$parentLocationId = $this->generateId('location', 52); |
| 1111 |
|
|
| 1112 |
|
$repository = $this->getRepository(); |
| 1113 |
|
|
| 1114 |
|
$contentService = $repository->getContentService(); |
| 1115 |
|
$locationService = $repository->getLocationService(); |
| 1116 |
|
|
| 1117 |
|
$anonymousUserId = $this->generateId('user', 10); |
| 1118 |
|
/* BEGIN: Use Case */ |
| 1119 |
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
| 1120 |
|
// demo installation |
| 1121 |
|
$contentVersion2 = $this->createContentVersion2(); |
| 1122 |
|
|
| 1123 |
|
// Load the user service |
| 1124 |
|
$userService = $repository->getUserService(); |
| 1125 |
|
|
| 1126 |
|
// Set anonymous user |
| 1127 |
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
| 1128 |
|
|
| 1129 |
|
// Configure new target location |
| 1130 |
|
$targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
| 1131 |
|
|
| 1132 |
|
$targetLocationCreate->priority = 42; |
| 1133 |
|
$targetLocationCreate->hidden = true; |
| 1134 |
|
$targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789'; |
| 1135 |
|
$targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
| 1136 |
|
$targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC; |
| 1137 |
|
|
| 1138 |
|
// This call will fail with a "UnauthorizedException" |
| 1139 |
|
$contentService->copyContent( |
| 1140 |
|
$contentVersion2->contentInfo, |
| 1141 |
|
$targetLocationCreate, |
| 1142 |
|
$contentService->loadVersionInfo($contentVersion2->contentInfo, 1) |
| 1143 |
|
); |
| 1144 |
|
/* END: Use Case */ |
| 1145 |
|
} |
| 1146 |
|
|
| 1147 |
|
/** |
| 1148 |
|
* Test for the loadRelations() method. |