Code Duplication    Length = 22-24 lines in 2 locations

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

@@ 1669-1690 (lines=22) @@
1666
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1667
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1668
     */
1669
    public function testUpdateContentThrowsInvalidArgumentExceptionWhenFieldTypeDoesNotAccept()
1670
    {
1671
        $repository = $this->getRepository();
1672
1673
        $contentService = $repository->getContentService();
1674
1675
        /* BEGIN: Use Case */
1676
        $draft = $this->createContentDraftVersion1();
1677
1678
        // Now create an update struct and modify some fields
1679
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
1680
        // The name field does not accept a stdClass object as its input
1681
        $contentUpdateStruct->setField('name', new \stdClass(), 'eng-US');
1682
1683
        // Throws an InvalidArgumentException, since the value for field "name"
1684
        // is not accepted
1685
        $contentService->updateContent(
1686
            $draft->getVersionInfo(),
1687
            $contentUpdateStruct
1688
        );
1689
        /* END: Use Case */
1690
    }
1691
1692
    /**
1693
     * Test for the updateContent() method.
@@ 1699-1722 (lines=24) @@
1696
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
1697
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1698
     */
1699
    public function testUpdateContentWhenMandatoryFieldIsEmpty()
1700
    {
1701
        $repository = $this->getRepository();
1702
1703
        $contentService = $repository->getContentService();
1704
1705
        /* BEGIN: Use Case */
1706
        $draft = $this->createContentDraftVersion1();
1707
1708
        // Now create an update struct and set a mandatory field to null
1709
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
1710
        $contentUpdateStruct->setField('name', null);
1711
1712
        // Don't set this, then the above call without languageCode will fail
1713
        $contentUpdateStruct->initialLanguageCode = 'eng-US';
1714
1715
        // This call will fail with a "ContentFieldValidationException", because the
1716
        // mandatory "name" field is empty.
1717
        $contentService->updateContent(
1718
            $draft->getVersionInfo(),
1719
            $contentUpdateStruct
1720
        );
1721
        /* END: Use Case */
1722
    }
1723
1724
    /**
1725
     * Test for the updateContent() method.