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

@@ 870-890 (lines=21) @@
867
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations
868
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
869
     */
870
    public function testLoadLocationsThrowsBadStateException()
871
    {
872
        $repository = $this->getRepository();
873
874
        /* BEGIN: Use Case */
875
        $contentTypeService = $repository->getContentTypeService();
876
        $contentService = $repository->getContentService();
877
        $locationService = $repository->getLocationService();
878
879
        // Create new content, which is not published
880
        $folderType = $contentTypeService->loadContentTypeByIdentifier('folder');
881
        $contentCreate = $contentService->newContentCreateStruct($folderType, 'eng-US');
882
        $contentCreate->setField('name', 'New Folder');
883
        $content = $contentService->createContent($contentCreate);
884
885
        // Throws Exception, since $content has no published version, yet
886
        $locationService->loadLocations(
887
            $content->contentInfo
888
        );
889
        /* END: Use Case */
890
    }
891
892
    /**
893
     * Test for the loadLocations() method.
@@ 3016-3037 (lines=22) @@
3013
     *
3014
     * @return \eZ\Publish\API\Repository\Values\Content\Content published Content
3015
     */
3016
    private function publishContentWithParentLocation($contentName, $parentLocationId)
3017
    {
3018
        $repository = $this->getRepository(false);
3019
        $locationService = $repository->getLocationService();
3020
3021
        $contentService = $repository->getContentService();
3022
        $contentTypeService = $repository->getContentTypeService();
3023
3024
        $contentCreateStruct = $contentService->newContentCreateStruct(
3025
            $contentTypeService->loadContentTypeByIdentifier('folder'),
3026
            'eng-US'
3027
        );
3028
        $contentCreateStruct->setField('name', $contentName);
3029
        $contentDraft = $contentService->createContent(
3030
            $contentCreateStruct,
3031
            [
3032
                $locationService->newLocationCreateStruct($parentLocationId),
3033
            ]
3034
        );
3035
3036
        return $contentService->publishVersion($contentDraft->versionInfo);
3037
    }
3038
3039
    /**
3040
     * @param string $name