Code Duplication    Length = 40-42 lines in 2 locations

eZ/Publish/API/Repository/Tests/ContentServiceAuthorizationTest.php 2 locations

@@ 1145-1186 (lines=42) @@
1142
     * @see \eZ\Publish\API\Repository\ContentService::copyContent()
1143
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent
1144
     */
1145
    public function testCopyContentThrowsUnauthorizedException()
1146
    {
1147
        $parentLocationId = $this->generateId('location', 52);
1148
1149
        $repository = $this->getRepository();
1150
1151
        $contentService = $repository->getContentService();
1152
        $locationService = $repository->getLocationService();
1153
1154
        $anonymousUserId = $this->generateId('user', 10);
1155
        /* BEGIN: Use Case */
1156
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
1157
        // demo installation
1158
        $contentVersion2 = $this->createMultipleLanguageContentVersion2();
1159
1160
        // Get ContentInfo instance of version 2
1161
        $contentInfo = $contentVersion2->contentInfo;
1162
1163
        // Load the user service
1164
        $userService = $repository->getUserService();
1165
1166
        // Set anonymous user
1167
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
1168
1169
        // Configure new target location
1170
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
1171
1172
        $targetLocationCreate->priority = 42;
1173
        $targetLocationCreate->hidden = true;
1174
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
1175
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
1176
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
1177
1178
        $this->expectException(UnauthorizedException::class);
1179
        $this->expectExceptionMessageRegExp('/\'read\' \'content\'/');
1180
1181
        $contentService->copyContent(
1182
            $contentInfo,
1183
            $targetLocationCreate
1184
        );
1185
        /* END: Use Case */
1186
    }
1187
1188
    /**
1189
     * Test for the copyContent() method.
@@ 1194-1233 (lines=40) @@
1191
     * @see \eZ\Publish\API\Repository\ContentService::copyContent($contentInfo, $destinationLocationCreateStruct, $versionInfo)
1192
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContentWithGivenVersion
1193
     */
1194
    public function testCopyContentThrowsUnauthorizedExceptionWithGivenVersion()
1195
    {
1196
        $parentLocationId = $this->generateId('location', 52);
1197
1198
        $repository = $this->getRepository();
1199
1200
        $contentService = $repository->getContentService();
1201
        $locationService = $repository->getLocationService();
1202
1203
        $anonymousUserId = $this->generateId('user', 10);
1204
        /* BEGIN: Use Case */
1205
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
1206
        // demo installation
1207
        $contentVersion2 = $this->createContentVersion2();
1208
1209
        // Load the user service
1210
        $userService = $repository->getUserService();
1211
1212
        // Set anonymous user
1213
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
1214
1215
        // Configure new target location
1216
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
1217
1218
        $targetLocationCreate->priority = 42;
1219
        $targetLocationCreate->hidden = true;
1220
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
1221
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
1222
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
1223
1224
        $this->expectException(UnauthorizedException::class);
1225
        $this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/');
1226
1227
        $contentService->copyContent(
1228
            $contentVersion2->contentInfo,
1229
            $targetLocationCreate,
1230
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 1)
1231
        );
1232
        /* END: Use Case */
1233
    }
1234
1235
    /**
1236
     * Test for the loadRelations() method.