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

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