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.
@@ 1705-1732 (lines=28) @@
1702
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
1703
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1704
     */
1705
    public function testUpdateUserWhenMissingField()
1706
    {
1707
        $repository = $this->getRepository();
1708
1709
        $userService = $repository->getUserService();
1710
1711
        /* BEGIN: Use Case */
1712
        $user = $this->createUserVersion1();
1713
1714
        // Get the ContentService implementation
1715
        $contentService = $repository->getContentService();
1716
1717
        // Create a content update struct and change the remote id.
1718
        $contentUpdate = $contentService->newContentUpdateStruct();
1719
        $contentUpdate->setField('first_name', null, 'eng-US');
1720
1721
        // Create a new update struct instance
1722
        $userUpdate = $userService->newUserUpdateStruct();
1723
1724
        // Set the content update struct.
1725
        $userUpdate->contentUpdateStruct = $contentUpdate;
1726
1727
        // This call will fail with a "ContentFieldValidationException" because the
1728
        // mandatory field "first_name" is set to an empty value.
1729
        $userService->updateUser($user, $userUpdate);
1730
1731
        /* END: Use Case */
1732
    }
1733
1734
    /**
1735
     * Test for the updateUser() method.
@@ 1741-1768 (lines=28) @@
1738
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1739
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1740
     */
1741
    public function testUpdateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
1742
    {
1743
        $repository = $this->getRepository();
1744
1745
        $userService = $repository->getUserService();
1746
1747
        /* BEGIN: Use Case */
1748
        $user = $this->createUserVersion1();
1749
1750
        // Get the ContentService implementation
1751
        $contentService = $repository->getContentService();
1752
1753
        $contentUpdate = $contentService->newContentUpdateStruct();
1754
        // An object of stdClass is not valid for the field first_name
1755
        $contentUpdate->setField('first_name', new \stdClass(), 'eng-US');
1756
1757
        // Create a new update struct instance
1758
        $userUpdate = $userService->newUserUpdateStruct();
1759
1760
        // Set the content update struct.
1761
        $userUpdate->contentUpdateStruct = $contentUpdate;
1762
1763
        // This call will fail with a "InvalidArgumentException" because the
1764
        // the field "first_name" does not accept the given value.
1765
        $userService->updateUser($user, $userUpdate);
1766
1767
        /* END: Use Case */
1768
    }
1769
1770
    /**
1771
     * Test for the loadUserGroupsOfUser() method.