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

@@ 737-757 (lines=21) @@
734
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations
735
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
736
     */
737
    public function testLoadLocationsThrowsBadStateException()
738
    {
739
        $repository = $this->getRepository();
740
741
        /* BEGIN: Use Case */
742
        $contentTypeService = $repository->getContentTypeService();
743
        $contentService = $repository->getContentService();
744
        $locationService = $repository->getLocationService();
745
746
        // Create new content, which is not published
747
        $folderType = $contentTypeService->loadContentTypeByIdentifier('folder');
748
        $contentCreate = $contentService->newContentCreateStruct($folderType, 'eng-US');
749
        $contentCreate->setField('name', 'New Folder');
750
        $content = $contentService->createContent($contentCreate);
751
752
        // Throws Exception, since $content has no published version, yet
753
        $locationService->loadLocations(
754
            $content->contentInfo
755
        );
756
        /* END: Use Case */
757
    }
758
759
    /**
760
     * Test for the loadLocations() method.
@@ 2498-2519 (lines=22) @@
2495
     *
2496
     * @return \eZ\Publish\API\Repository\Values\Content\Content published Content
2497
     */
2498
    private function publishContentWithParentLocation($contentName, $parentLocationId)
2499
    {
2500
        $repository = $this->getRepository(false);
2501
        $locationService = $repository->getLocationService();
2502
2503
        $contentService = $repository->getContentService();
2504
        $contentTypeService = $repository->getContentTypeService();
2505
2506
        $contentCreateStruct = $contentService->newContentCreateStruct(
2507
            $contentTypeService->loadContentTypeByIdentifier('folder'),
2508
            'eng-US'
2509
        );
2510
        $contentCreateStruct->setField('name', $contentName);
2511
        $contentDraft = $contentService->createContent(
2512
            $contentCreateStruct,
2513
            [
2514
                $locationService->newLocationCreateStruct($parentLocationId),
2515
            ]
2516
        );
2517
2518
        return $contentService->publishVersion($contentDraft->versionInfo);
2519
    }
2520
}
2521