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

@@ 834-849 (lines=16) @@
831
     *
832
     * @return \eZ\Publish\API\Repository\Values\Content\Content
833
     */
834
    protected function createNewContentInPlaceTrashedOne(Repository $repository, $parentLocationId)
835
    {
836
        $contentService = $repository->getContentService();
837
        $locationService = $repository->getLocationService();
838
        $contentTypeService = $repository->getContentTypeService();
839
840
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
841
        $newContent = $contentService->newContentCreateStruct($contentType, 'eng-US');
842
        $newContent->setField('name', 'Media');
843
844
        $location = $locationService->newLocationCreateStruct($parentLocationId);
845
846
        $draftContent = $contentService->createContent($newContent, [$location]);
847
848
        return $contentService->publishVersion($draftContent->versionInfo);
849
    }
850
851
    /**
852
     * @param URLAliasService $urlAliasService

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

@@ 723-743 (lines=21) @@
720
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations
721
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
722
     */
723
    public function testLoadLocationsThrowsBadStateException()
724
    {
725
        $repository = $this->getRepository();
726
727
        /* BEGIN: Use Case */
728
        $contentTypeService = $repository->getContentTypeService();
729
        $contentService = $repository->getContentService();
730
        $locationService = $repository->getLocationService();
731
732
        // Create new content, which is not published
733
        $folderType = $contentTypeService->loadContentTypeByIdentifier('folder');
734
        $contentCreate = $contentService->newContentCreateStruct($folderType, 'eng-US');
735
        $contentCreate->setField('name', 'New Folder');
736
        $content = $contentService->createContent($contentCreate);
737
738
        // Throws Exception, since $content has no published version, yet
739
        $locationService->loadLocations(
740
            $content->contentInfo
741
        );
742
        /* END: Use Case */
743
    }
744
745
    /**
746
     * Test for the loadLocations() method.
@@ 2416-2437 (lines=22) @@
2413
     *
2414
     * @return \eZ\Publish\API\Repository\Values\Content\Content published Content
2415
     */
2416
    private function publishContentWithParentLocation($contentName, $parentLocationId)
2417
    {
2418
        $repository = $this->getRepository(false);
2419
        $locationService = $repository->getLocationService();
2420
2421
        $contentService = $repository->getContentService();
2422
        $contentTypeService = $repository->getContentTypeService();
2423
2424
        $contentCreateStruct = $contentService->newContentCreateStruct(
2425
            $contentTypeService->loadContentTypeByIdentifier('folder'),
2426
            'eng-US'
2427
        );
2428
        $contentCreateStruct->setField('name', $contentName);
2429
        $contentDraft = $contentService->createContent(
2430
            $contentCreateStruct,
2431
            [
2432
                $locationService->newLocationCreateStruct($parentLocationId),
2433
            ]
2434
        );
2435
2436
        return $contentService->publishVersion($contentDraft->versionInfo);
2437
    }
2438
}
2439