Code Duplication    Length = 25-28 lines in 3 locations

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

@@ 787-811 (lines=25) @@
784
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
785
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUserGroup
786
     */
787
    public function testUpdateUserGroupThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
788
    {
789
        $repository = $this->getRepository();
790
        $userService = $repository->getUserService();
791
792
        /* BEGIN: Use Case */
793
        $userGroup = $this->createUserGroupVersion1();
794
795
        // Load the content service
796
        $contentService = $repository->getContentService();
797
798
        // Create a content update struct and update the group name
799
        $contentUpdate = $contentService->newContentUpdateStruct();
800
        // An object of stdClass is not accepted as a value by the field "name"
801
        $contentUpdate->setField('name', new \stdClass(), 'eng-US');
802
803
        // Create a group update struct and set content update struct
804
        $groupUpdate = $userService->newUserGroupUpdateStruct();
805
        $groupUpdate->contentUpdateStruct = $contentUpdate;
806
807
        // This call will fail with an InvalidArgumentException, because the
808
        // field "name" does not accept the given value
809
        $userService->updateUserGroup($userGroup, $groupUpdate);
810
        /* END: Use Case */
811
    }
812
813
    /**
814
     * Test for the newUserCreateStruct() method.
@@ 1717-1744 (lines=28) @@
1714
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
1715
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1716
     */
1717
    public function testUpdateUserWhenMissingField()
1718
    {
1719
        $repository = $this->getRepository();
1720
1721
        $userService = $repository->getUserService();
1722
1723
        /* BEGIN: Use Case */
1724
        $user = $this->createUserVersion1();
1725
1726
        // Get the ContentService implementation
1727
        $contentService = $repository->getContentService();
1728
1729
        // Create a content update struct and change the remote id.
1730
        $contentUpdate = $contentService->newContentUpdateStruct();
1731
        $contentUpdate->setField('first_name', null, 'eng-US');
1732
1733
        // Create a new update struct instance
1734
        $userUpdate = $userService->newUserUpdateStruct();
1735
1736
        // Set the content update struct.
1737
        $userUpdate->contentUpdateStruct = $contentUpdate;
1738
1739
        // This call will fail with a "ContentFieldValidationException" because the
1740
        // mandatory field "first_name" is set to an empty value.
1741
        $userService->updateUser($user, $userUpdate);
1742
1743
        /* END: Use Case */
1744
    }
1745
1746
    /**
1747
     * Test for the updateUser() method.
@@ 1753-1780 (lines=28) @@
1750
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1751
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1752
     */
1753
    public function testUpdateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
1754
    {
1755
        $repository = $this->getRepository();
1756
1757
        $userService = $repository->getUserService();
1758
1759
        /* BEGIN: Use Case */
1760
        $user = $this->createUserVersion1();
1761
1762
        // Get the ContentService implementation
1763
        $contentService = $repository->getContentService();
1764
1765
        $contentUpdate = $contentService->newContentUpdateStruct();
1766
        // An object of stdClass is not valid for the field first_name
1767
        $contentUpdate->setField('first_name', new \stdClass(), 'eng-US');
1768
1769
        // Create a new update struct instance
1770
        $userUpdate = $userService->newUserUpdateStruct();
1771
1772
        // Set the content update struct.
1773
        $userUpdate->contentUpdateStruct = $contentUpdate;
1774
1775
        // This call will fail with a "InvalidArgumentException" because the
1776
        // the field "first_name" does not accept the given value.
1777
        $userService->updateUser($user, $userUpdate);
1778
1779
        /* END: Use Case */
1780
    }
1781
1782
    /**
1783
     * Test for the loadUserGroupsOfUser() method.