Code Duplication    Length = 25-28 lines in 3 locations

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

@@ 699-723 (lines=25) @@
696
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
697
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUserGroup
698
     */
699
    public function testUpdateUserGroupThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
700
    {
701
        $repository = $this->getRepository();
702
        $userService = $repository->getUserService();
703
704
        /* BEGIN: Use Case */
705
        $userGroup = $this->createUserGroupVersion1();
706
707
        // Load the content service
708
        $contentService = $repository->getContentService();
709
710
        // Create a content update struct and update the group name
711
        $contentUpdate = $contentService->newContentUpdateStruct();
712
        // An object of stdClass is not accepted as a value by the field "name"
713
        $contentUpdate->setField('name', new \stdClass(), 'eng-US');
714
715
        // Create a group update struct and set content update struct
716
        $groupUpdate = $userService->newUserGroupUpdateStruct();
717
        $groupUpdate->contentUpdateStruct = $contentUpdate;
718
719
        // This call will fail with an InvalidArgumentException, because the
720
        // field "name" does not accept the given value
721
        $userService->updateUserGroup($userGroup, $groupUpdate);
722
        /* END: Use Case */
723
    }
724
725
    /**
726
     * Test for the newUserCreateStruct() method.
@@ 1714-1741 (lines=28) @@
1711
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
1712
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1713
     */
1714
    public function testUpdateUserWhenMissingField()
1715
    {
1716
        $repository = $this->getRepository();
1717
1718
        $userService = $repository->getUserService();
1719
1720
        /* BEGIN: Use Case */
1721
        $user = $this->createUserVersion1();
1722
1723
        // Get the ContentService implementation
1724
        $contentService = $repository->getContentService();
1725
1726
        // Create a content update struct and change the remote id.
1727
        $contentUpdate = $contentService->newContentUpdateStruct();
1728
        $contentUpdate->setField('first_name', null, 'eng-US');
1729
1730
        // Create a new update struct instance
1731
        $userUpdate = $userService->newUserUpdateStruct();
1732
1733
        // Set the content update struct.
1734
        $userUpdate->contentUpdateStruct = $contentUpdate;
1735
1736
        // This call will fail with a "ContentFieldValidationException" because the
1737
        // mandatory field "first_name" is set to an empty value.
1738
        $userService->updateUser($user, $userUpdate);
1739
1740
        /* END: Use Case */
1741
    }
1742
1743
    /**
1744
     * Test for the updateUser() method.
@@ 1750-1777 (lines=28) @@
1747
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1748
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1749
     */
1750
    public function testUpdateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
1751
    {
1752
        $repository = $this->getRepository();
1753
1754
        $userService = $repository->getUserService();
1755
1756
        /* BEGIN: Use Case */
1757
        $user = $this->createUserVersion1();
1758
1759
        // Get the ContentService implementation
1760
        $contentService = $repository->getContentService();
1761
1762
        $contentUpdate = $contentService->newContentUpdateStruct();
1763
        // An object of stdClass is not valid for the field first_name
1764
        $contentUpdate->setField('first_name', new \stdClass(), 'eng-US');
1765
1766
        // Create a new update struct instance
1767
        $userUpdate = $userService->newUserUpdateStruct();
1768
1769
        // Set the content update struct.
1770
        $userUpdate->contentUpdateStruct = $contentUpdate;
1771
1772
        // This call will fail with a "InvalidArgumentException" because the
1773
        // the field "first_name" does not accept the given value.
1774
        $userService->updateUser($user, $userUpdate);
1775
1776
        /* END: Use Case */
1777
    }
1778
1779
    /**
1780
     * Test for the loadUserGroupsOfUser() method.