Code Duplication    Length = 18-21 lines in 3 locations

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

@@ 1554-1571 (lines=18) @@
1551
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1552
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1553
     */
1554
    public function testUpdateContentThrowsInvalidArgumentExceptionWhenFieldTypeDoesNotAccept()
1555
    {
1556
        /* BEGIN: Use Case */
1557
        $draft = $this->createContentDraftVersion1();
1558
1559
        // Now create an update struct and modify some fields
1560
        $contentUpdateStruct = $this->contentService->newContentUpdateStruct();
1561
        // The name field does not accept a stdClass object as its input
1562
        $contentUpdateStruct->setField('name', new \stdClass(), 'eng-US');
1563
1564
        $this->expectException(APIInvalidArgumentException::class);
1565
        // is not accepted
1566
        $this->contentService->updateContent(
1567
            $draft->getVersionInfo(),
1568
            $contentUpdateStruct
1569
        );
1570
        /* END: Use Case */
1571
    }
1572
1573
    /**
1574
     * Test for the updateContent() method.
@@ 1579-1599 (lines=21) @@
1576
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1577
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1578
     */
1579
    public function testUpdateContentWhenMandatoryFieldIsEmpty()
1580
    {
1581
        /* BEGIN: Use Case */
1582
        $draft = $this->createContentDraftVersion1();
1583
1584
        // Now create an update struct and set a mandatory field to null
1585
        $contentUpdateStruct = $this->contentService->newContentUpdateStruct();
1586
        $contentUpdateStruct->setField('name', null);
1587
1588
        // Don't set this, then the above call without languageCode will fail
1589
        $contentUpdateStruct->initialLanguageCode = 'eng-US';
1590
1591
        $this->expectException(ContentFieldValidationException::class);
1592
1593
        // This call will fail with a "ContentFieldValidationException", because the mandatory "name" field is empty.
1594
        $this->contentService->updateContent(
1595
            $draft->getVersionInfo(),
1596
            $contentUpdateStruct
1597
        );
1598
        /* END: Use Case */
1599
    }
1600
1601
    /**
1602
     * Test for the updateContent() method.
@@ 3953-3971 (lines=19) @@
3950
     * @see \eZ\Publish\API\Repository\ContentService::deleteRelation()
3951
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
3952
     */
3953
    public function testDeleteRelationThrowsInvalidArgumentException()
3954
    {
3955
        /* BEGIN: Use Case */
3956
        // RemoteId of the "Media" page of an eZ Publish demo installation
3957
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3958
3959
        $draft = $this->createContentDraftVersion1();
3960
3961
        // Load the destination object
3962
        $media = $this->contentService->loadContentInfoByRemoteId($mediaRemoteId);
3963
3964
        // This call will fail with a "InvalidArgumentException", because no relation exists between $draft and $media.
3965
        $this->expectException(APIInvalidArgumentException::class);
3966
        $this->contentService->deleteRelation(
3967
            $draft->getVersionInfo(),
3968
            $media
3969
        );
3970
        /* END: Use Case */
3971
    }
3972
3973
    /**
3974
     * Test for the createContent() method.