Code Duplication    Length = 38-40 lines in 2 locations

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

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