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

@@ 867-887 (lines=21) @@
864
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations
865
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
866
     */
867
    public function testLoadLocationsThrowsBadStateException()
868
    {
869
        $repository = $this->getRepository();
870
871
        /* BEGIN: Use Case */
872
        $contentTypeService = $repository->getContentTypeService();
873
        $contentService = $repository->getContentService();
874
        $locationService = $repository->getLocationService();
875
876
        // Create new content, which is not published
877
        $folderType = $contentTypeService->loadContentTypeByIdentifier('folder');
878
        $contentCreate = $contentService->newContentCreateStruct($folderType, 'eng-US');
879
        $contentCreate->setField('name', 'New Folder');
880
        $content = $contentService->createContent($contentCreate);
881
882
        // Throws Exception, since $content has no published version, yet
883
        $locationService->loadLocations(
884
            $content->contentInfo
885
        );
886
        /* END: Use Case */
887
    }
888
889
    /**
890
     * Test for the loadLocations() method.
@@ 2974-2995 (lines=22) @@
2971
     *
2972
     * @return \eZ\Publish\API\Repository\Values\Content\Content published Content
2973
     */
2974
    private function publishContentWithParentLocation($contentName, $parentLocationId)
2975
    {
2976
        $repository = $this->getRepository(false);
2977
        $locationService = $repository->getLocationService();
2978
2979
        $contentService = $repository->getContentService();
2980
        $contentTypeService = $repository->getContentTypeService();
2981
2982
        $contentCreateStruct = $contentService->newContentCreateStruct(
2983
            $contentTypeService->loadContentTypeByIdentifier('folder'),
2984
            'eng-US'
2985
        );
2986
        $contentCreateStruct->setField('name', $contentName);
2987
        $contentDraft = $contentService->createContent(
2988
            $contentCreateStruct,
2989
            [
2990
                $locationService->newLocationCreateStruct($parentLocationId),
2991
            ]
2992
        );
2993
2994
        return $contentService->publishVersion($contentDraft->versionInfo);
2995
    }
2996
}
2997