Code Duplication    Length = 13-23 lines in 3 locations

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

@@ 2956-2977 (lines=22) @@
2953
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
2954
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation
2955
     */
2956
    public function testAddRelationThrowsBadStateException()
2957
    {
2958
        $repository = $this->getRepository();
2959
2960
        $contentService = $repository->getContentService();
2961
2962
        /* BEGIN: Use Case */
2963
        // RemoteId of the "Media" page of an eZ Publish demo installation
2964
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
2965
2966
        $content = $this->createContentVersion1();
2967
2968
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
2969
2970
        // This call will fail with a "BadStateException", because content is
2971
        // published and not a draft.
2972
        $contentService->addRelation(
2973
            $content->getVersionInfo(),
2974
            $media
2975
        );
2976
        /* END: Use Case */
2977
    }
2978
2979
    /**
2980
     * Test for the loadRelations() method.
@@ 3520-3542 (lines=23) @@
3517
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
3518
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
3519
     */
3520
    public function testDeleteRelationThrowsInvalidArgumentException()
3521
    {
3522
        $repository = $this->getRepository();
3523
3524
        $contentService = $repository->getContentService();
3525
3526
        /* BEGIN: Use Case */
3527
        // RemoteId of the "Media" page of an eZ Publish demo installation
3528
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3529
3530
        $draft = $this->createContentDraftVersion1();
3531
3532
        // Load the destination object
3533
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3534
3535
        // This call will fail with a "InvalidArgumentException", because no
3536
        // relation exists between $draft and $media.
3537
        $contentService->deleteRelation(
3538
            $draft->getVersionInfo(),
3539
            $media
3540
        );
3541
        /* END: Use Case */
3542
    }
3543
3544
    /**
3545
     * Test for the createContent() method.

eZ/Publish/Core/Repository/Tests/Service/Integration/ContentBase.php 1 location

@@ 2422-2434 (lines=13) @@
2419
     * @covers \eZ\Publish\Core\Repository\ContentService::addRelation
2420
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
2421
     */
2422
    public function testAddRelationThrowsBadStateException()
2423
    {
2424
        $contentService = $this->repository->getContentService();
2425
        list($contentDraft, $contentType) = $this->createTestContent();
2426
        $publishedContent = $contentService->publishVersion($contentDraft->versionInfo);
2427
2428
        $mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262');
2429
2430
        $contentService->addRelation(
2431
            $publishedContent->getVersionInfo(),
2432
            $mediaContentInfo
2433
        );
2434
    }
2435
2436
    /**
2437
     * Test for the deleteRelation() method.