Code Duplication    Length = 22-24 lines in 2 locations

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

@@ 1573-1594 (lines=22) @@
1570
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1571
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1572
     */
1573
    public function testUpdateContentThrowsInvalidArgumentExceptionWhenFieldTypeDoesNotAccept()
1574
    {
1575
        $repository = $this->getRepository();
1576
1577
        $contentService = $repository->getContentService();
1578
1579
        /* BEGIN: Use Case */
1580
        $draft = $this->createContentDraftVersion1();
1581
1582
        // Now create an update struct and modify some fields
1583
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
1584
        // The name field does not accept a stdClass object as its input
1585
        $contentUpdateStruct->setField('name', new \stdClass(), 'eng-US');
1586
1587
        // Throws an InvalidArgumentException, since the value for field "name"
1588
        // is not accepted
1589
        $contentService->updateContent(
1590
            $draft->getVersionInfo(),
1591
            $contentUpdateStruct
1592
        );
1593
        /* END: Use Case */
1594
    }
1595
1596
    /**
1597
     * Test for the updateContent() method.
@@ 1603-1626 (lines=24) @@
1600
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
1601
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1602
     */
1603
    public function testUpdateContentWhenMandatoryFieldIsEmpty()
1604
    {
1605
        $repository = $this->getRepository();
1606
1607
        $contentService = $repository->getContentService();
1608
1609
        /* BEGIN: Use Case */
1610
        $draft = $this->createContentDraftVersion1();
1611
1612
        // Now create an update struct and set a mandatory field to null
1613
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
1614
        $contentUpdateStruct->setField('name', null);
1615
1616
        // Don't set this, then the above call without languageCode will fail
1617
        $contentUpdateStruct->initialLanguageCode = 'eng-US';
1618
1619
        // This call will fail with a "ContentFieldValidationException", because the
1620
        // mandatory "name" field is empty.
1621
        $contentService->updateContent(
1622
            $draft->getVersionInfo(),
1623
            $contentUpdateStruct
1624
        );
1625
        /* END: Use Case */
1626
    }
1627
1628
    /**
1629
     * Test for the updateContent() method.