Code Duplication    Length = 18-21 lines in 3 locations

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

@@ 1553-1570 (lines=18) @@
1550
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1551
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1552
     */
1553
    public function testUpdateContentThrowsInvalidArgumentExceptionWhenFieldTypeDoesNotAccept()
1554
    {
1555
        /* BEGIN: Use Case */
1556
        $draft = $this->createContentDraftVersion1();
1557
1558
        // Now create an update struct and modify some fields
1559
        $contentUpdateStruct = $this->contentService->newContentUpdateStruct();
1560
        // The name field does not accept a stdClass object as its input
1561
        $contentUpdateStruct->setField('name', new \stdClass(), 'eng-US');
1562
1563
        $this->expectException(APIInvalidArgumentException::class);
1564
        // is not accepted
1565
        $this->contentService->updateContent(
1566
            $draft->getVersionInfo(),
1567
            $contentUpdateStruct
1568
        );
1569
        /* END: Use Case */
1570
    }
1571
1572
    /**
1573
     * Test for the updateContent() method.
@@ 1578-1598 (lines=21) @@
1575
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1576
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1577
     */
1578
    public function testUpdateContentWhenMandatoryFieldIsEmpty()
1579
    {
1580
        /* BEGIN: Use Case */
1581
        $draft = $this->createContentDraftVersion1();
1582
1583
        // Now create an update struct and set a mandatory field to null
1584
        $contentUpdateStruct = $this->contentService->newContentUpdateStruct();
1585
        $contentUpdateStruct->setField('name', null);
1586
1587
        // Don't set this, then the above call without languageCode will fail
1588
        $contentUpdateStruct->initialLanguageCode = 'eng-US';
1589
1590
        $this->expectException(ContentFieldValidationException::class);
1591
1592
        // This call will fail with a "ContentFieldValidationException", because the mandatory "name" field is empty.
1593
        $this->contentService->updateContent(
1594
            $draft->getVersionInfo(),
1595
            $contentUpdateStruct
1596
        );
1597
        /* END: Use Case */
1598
    }
1599
1600
    /**
1601
     * Test for the updateContent() method.
@@ 3853-3871 (lines=19) @@
3850
     * @see \eZ\Publish\API\Repository\ContentService::deleteRelation()
3851
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
3852
     */
3853
    public function testDeleteRelationThrowsInvalidArgumentException()
3854
    {
3855
        /* BEGIN: Use Case */
3856
        // RemoteId of the "Media" page of an eZ Publish demo installation
3857
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3858
3859
        $draft = $this->createContentDraftVersion1();
3860
3861
        // Load the destination object
3862
        $media = $this->contentService->loadContentInfoByRemoteId($mediaRemoteId);
3863
3864
        // This call will fail with a "InvalidArgumentException", because no relation exists between $draft and $media.
3865
        $this->expectException(APIInvalidArgumentException::class);
3866
        $this->contentService->deleteRelation(
3867
            $draft->getVersionInfo(),
3868
            $media
3869
        );
3870
        /* END: Use Case */
3871
    }
3872
3873
    /**
3874
     * Test for the createContent() method.