Code Duplication    Length = 38-40 lines in 2 locations

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

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