Code Duplication    Length = 16-22 lines in 4 locations

eZ/Bundle/EzPublishCoreBundle/Features/Context/QueryControllerContext.php 1 location

@@ 97-118 (lines=22) @@
94
    /**
95
     * @return Content
96
     */
97
    private function createFolder()
98
    {
99
        $repository = $this->getRepository();
100
        $contentService = $repository->getContentService();
101
        $contentTypeService = $repository->getContentTypeService();
102
        $locationService = $repository->getLocationService();
103
104
        $struct = $contentService->newContentCreateStruct(
105
            $contentTypeService->loadContentTypeByIdentifier('folder'),
106
            'eng-GB'
107
        );
108
109
        $struct->setField('name', uniqid('Query Controller BDD ', true));
110
111
        $contentDraft = $contentService->createContent(
112
            $struct,
113
            [$locationService->newLocationCreateStruct(2)]
114
        );
115
        $contentService->publishVersion($contentDraft->versionInfo);
116
117
        return $contentService->loadContent($contentDraft->id);
118
    }
119
120
    /**
121
     * @Given /^a LocationChildren QueryType defined in "([^"]*)":$/

eZ/Publish/API/Repository/Tests/TrashServiceTest.php 1 location

@@ 956-971 (lines=16) @@
953
     *
954
     * @return \eZ\Publish\API\Repository\Values\Content\Content
955
     */
956
    protected function createNewContentInPlaceTrashedOne(Repository $repository, $parentLocationId)
957
    {
958
        $contentService = $repository->getContentService();
959
        $locationService = $repository->getLocationService();
960
        $contentTypeService = $repository->getContentTypeService();
961
962
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
963
        $newContent = $contentService->newContentCreateStruct($contentType, 'eng-US');
964
        $newContent->setField('name', 'Media');
965
966
        $location = $locationService->newLocationCreateStruct($parentLocationId);
967
968
        $draftContent = $contentService->createContent($newContent, [$location]);
969
970
        return $contentService->publishVersion($draftContent->versionInfo);
971
    }
972
973
    /**
974
     * @param URLAliasService $urlAliasService

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

@@ 907-927 (lines=21) @@
904
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations
905
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
906
     */
907
    public function testLoadLocationsThrowsBadStateException()
908
    {
909
        $repository = $this->getRepository();
910
911
        /* BEGIN: Use Case */
912
        $contentTypeService = $repository->getContentTypeService();
913
        $contentService = $repository->getContentService();
914
        $locationService = $repository->getLocationService();
915
916
        // Create new content, which is not published
917
        $folderType = $contentTypeService->loadContentTypeByIdentifier('folder');
918
        $contentCreate = $contentService->newContentCreateStruct($folderType, 'eng-US');
919
        $contentCreate->setField('name', 'New Folder');
920
        $content = $contentService->createContent($contentCreate);
921
922
        // Throws Exception, since $content has no published version, yet
923
        $locationService->loadLocations(
924
            $content->contentInfo
925
        );
926
        /* END: Use Case */
927
    }
928
929
    /**
930
     * Test for the loadLocations() method.
@@ 3082-3103 (lines=22) @@
3079
     *
3080
     * @return \eZ\Publish\API\Repository\Values\Content\Content published Content
3081
     */
3082
    private function publishContentWithParentLocation($contentName, $parentLocationId)
3083
    {
3084
        $repository = $this->getRepository(false);
3085
        $locationService = $repository->getLocationService();
3086
3087
        $contentService = $repository->getContentService();
3088
        $contentTypeService = $repository->getContentTypeService();
3089
3090
        $contentCreateStruct = $contentService->newContentCreateStruct(
3091
            $contentTypeService->loadContentTypeByIdentifier('folder'),
3092
            'eng-US'
3093
        );
3094
        $contentCreateStruct->setField('name', $contentName);
3095
        $contentDraft = $contentService->createContent(
3096
            $contentCreateStruct,
3097
            [
3098
                $locationService->newLocationCreateStruct($parentLocationId),
3099
            ]
3100
        );
3101
3102
        return $contentService->publishVersion($contentDraft->versionInfo);
3103
    }
3104
3105
    /**
3106
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException