Code Duplication    Length = 18-21 lines in 3 locations

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

@@ 1556-1573 (lines=18) @@
1553
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1554
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1555
     */
1556
    public function testUpdateContentThrowsInvalidArgumentExceptionWhenFieldTypeDoesNotAccept()
1557
    {
1558
        /* BEGIN: Use Case */
1559
        $draft = $this->createContentDraftVersion1();
1560
1561
        // Now create an update struct and modify some fields
1562
        $contentUpdateStruct = $this->contentService->newContentUpdateStruct();
1563
        // The name field does not accept a stdClass object as its input
1564
        $contentUpdateStruct->setField('name', new \stdClass(), 'eng-US');
1565
1566
        $this->expectException(APIInvalidArgumentException::class);
1567
        // is not accepted
1568
        $this->contentService->updateContent(
1569
            $draft->getVersionInfo(),
1570
            $contentUpdateStruct
1571
        );
1572
        /* END: Use Case */
1573
    }
1574
1575
    /**
1576
     * Test for the updateContent() method.
@@ 1581-1601 (lines=21) @@
1578
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1579
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1580
     */
1581
    public function testUpdateContentWhenMandatoryFieldIsEmpty()
1582
    {
1583
        /* BEGIN: Use Case */
1584
        $draft = $this->createContentDraftVersion1();
1585
1586
        // Now create an update struct and set a mandatory field to null
1587
        $contentUpdateStruct = $this->contentService->newContentUpdateStruct();
1588
        $contentUpdateStruct->setField('name', null);
1589
1590
        // Don't set this, then the above call without languageCode will fail
1591
        $contentUpdateStruct->initialLanguageCode = 'eng-US';
1592
1593
        $this->expectException(ContentFieldValidationException::class);
1594
1595
        // This call will fail with a "ContentFieldValidationException", because the mandatory "name" field is empty.
1596
        $this->contentService->updateContent(
1597
            $draft->getVersionInfo(),
1598
            $contentUpdateStruct
1599
        );
1600
        /* END: Use Case */
1601
    }
1602
1603
    /**
1604
     * Test for the updateContent() method.
@@ 3987-4005 (lines=19) @@
3984
     * @see \eZ\Publish\API\Repository\ContentService::deleteRelation()
3985
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
3986
     */
3987
    public function testDeleteRelationThrowsInvalidArgumentException()
3988
    {
3989
        /* BEGIN: Use Case */
3990
        // RemoteId of the "Media" page of an eZ Publish demo installation
3991
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3992
3993
        $draft = $this->createContentDraftVersion1();
3994
3995
        // Load the destination object
3996
        $media = $this->contentService->loadContentInfoByRemoteId($mediaRemoteId);
3997
3998
        // This call will fail with a "InvalidArgumentException", because no relation exists between $draft and $media.
3999
        $this->expectException(APIInvalidArgumentException::class);
4000
        $this->contentService->deleteRelation(
4001
            $draft->getVersionInfo(),
4002
            $media
4003
        );
4004
        /* END: Use Case */
4005
    }
4006
4007
    /**
4008
     * Test for the createContent() method.