Code Duplication    Length = 16-22 lines in 4 locations

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

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

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

@@ 850-865 (lines=16) @@
847
     *
848
     * @return \eZ\Publish\API\Repository\Values\Content\Content
849
     */
850
    protected function createNewContentInPlaceTrashedOne(Repository $repository, $parentLocationId)
851
    {
852
        $contentService = $repository->getContentService();
853
        $locationService = $repository->getLocationService();
854
        $contentTypeService = $repository->getContentTypeService();
855
856
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
857
        $newContent = $contentService->newContentCreateStruct($contentType, 'eng-US');
858
        $newContent->setField('name', 'Media');
859
860
        $location = $locationService->newLocationCreateStruct($parentLocationId);
861
862
        $draftContent = $contentService->createContent($newContent, [$location]);
863
864
        return $contentService->publishVersion($draftContent->versionInfo);
865
    }
866
867
    /**
868
     * @param URLAliasService $urlAliasService

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

@@ 804-824 (lines=21) @@
801
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations
802
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
803
     */
804
    public function testLoadLocationsThrowsBadStateException()
805
    {
806
        $repository = $this->getRepository();
807
808
        /* BEGIN: Use Case */
809
        $contentTypeService = $repository->getContentTypeService();
810
        $contentService = $repository->getContentService();
811
        $locationService = $repository->getLocationService();
812
813
        // Create new content, which is not published
814
        $folderType = $contentTypeService->loadContentTypeByIdentifier('folder');
815
        $contentCreate = $contentService->newContentCreateStruct($folderType, 'eng-US');
816
        $contentCreate->setField('name', 'New Folder');
817
        $content = $contentService->createContent($contentCreate);
818
819
        // Throws Exception, since $content has no published version, yet
820
        $locationService->loadLocations(
821
            $content->contentInfo
822
        );
823
        /* END: Use Case */
824
    }
825
826
    /**
827
     * Test for the loadLocations() method.
@@ 2565-2586 (lines=22) @@
2562
     *
2563
     * @return \eZ\Publish\API\Repository\Values\Content\Content published Content
2564
     */
2565
    private function publishContentWithParentLocation($contentName, $parentLocationId)
2566
    {
2567
        $repository = $this->getRepository(false);
2568
        $locationService = $repository->getLocationService();
2569
2570
        $contentService = $repository->getContentService();
2571
        $contentTypeService = $repository->getContentTypeService();
2572
2573
        $contentCreateStruct = $contentService->newContentCreateStruct(
2574
            $contentTypeService->loadContentTypeByIdentifier('folder'),
2575
            'eng-US'
2576
        );
2577
        $contentCreateStruct->setField('name', $contentName);
2578
        $contentDraft = $contentService->createContent(
2579
            $contentCreateStruct,
2580
            [
2581
                $locationService->newLocationCreateStruct($parentLocationId),
2582
            ]
2583
        );
2584
2585
        return $contentService->publishVersion($contentDraft->versionInfo);
2586
    }
2587
}
2588