Code Duplication    Length = 25-28 lines in 3 locations

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

@@ 702-726 (lines=25) @@
699
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
700
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUserGroup
701
     */
702
    public function testUpdateUserGroupThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
703
    {
704
        $repository = $this->getRepository();
705
        $userService = $repository->getUserService();
706
707
        /* BEGIN: Use Case */
708
        $userGroup = $this->createUserGroupVersion1();
709
710
        // Load the content service
711
        $contentService = $repository->getContentService();
712
713
        // Create a content update struct and update the group name
714
        $contentUpdate = $contentService->newContentUpdateStruct();
715
        // An object of stdClass is not accepted as a value by the field "name"
716
        $contentUpdate->setField('name', new \stdClass(), 'eng-US');
717
718
        // Create a group update struct and set content update struct
719
        $groupUpdate = $userService->newUserGroupUpdateStruct();
720
        $groupUpdate->contentUpdateStruct = $contentUpdate;
721
722
        // This call will fail with an InvalidArgumentException, because the
723
        // field "name" does not accept the given value
724
        $userService->updateUserGroup($userGroup, $groupUpdate);
725
        /* END: Use Case */
726
    }
727
728
    /**
729
     * Test for the newUserCreateStruct() method.
@@ 1786-1813 (lines=28) @@
1783
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
1784
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1785
     */
1786
    public function testUpdateUserWhenMissingField()
1787
    {
1788
        $repository = $this->getRepository();
1789
1790
        $userService = $repository->getUserService();
1791
1792
        /* BEGIN: Use Case */
1793
        $user = $this->createUserVersion1();
1794
1795
        // Get the ContentService implementation
1796
        $contentService = $repository->getContentService();
1797
1798
        // Create a content update struct and change the remote id.
1799
        $contentUpdate = $contentService->newContentUpdateStruct();
1800
        $contentUpdate->setField('first_name', null, 'eng-US');
1801
1802
        // Create a new update struct instance
1803
        $userUpdate = $userService->newUserUpdateStruct();
1804
1805
        // Set the content update struct.
1806
        $userUpdate->contentUpdateStruct = $contentUpdate;
1807
1808
        // This call will fail with a "ContentFieldValidationException" because the
1809
        // mandatory field "first_name" is set to an empty value.
1810
        $userService->updateUser($user, $userUpdate);
1811
1812
        /* END: Use Case */
1813
    }
1814
1815
    /**
1816
     * Test for the updateUser() method.
@@ 1822-1849 (lines=28) @@
1819
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1820
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1821
     */
1822
    public function testUpdateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
1823
    {
1824
        $repository = $this->getRepository();
1825
1826
        $userService = $repository->getUserService();
1827
1828
        /* BEGIN: Use Case */
1829
        $user = $this->createUserVersion1();
1830
1831
        // Get the ContentService implementation
1832
        $contentService = $repository->getContentService();
1833
1834
        $contentUpdate = $contentService->newContentUpdateStruct();
1835
        // An object of stdClass is not valid for the field first_name
1836
        $contentUpdate->setField('first_name', new \stdClass(), 'eng-US');
1837
1838
        // Create a new update struct instance
1839
        $userUpdate = $userService->newUserUpdateStruct();
1840
1841
        // Set the content update struct.
1842
        $userUpdate->contentUpdateStruct = $contentUpdate;
1843
1844
        // This call will fail with a "InvalidArgumentException" because the
1845
        // the field "first_name" does not accept the given value.
1846
        $userService->updateUser($user, $userUpdate);
1847
1848
        /* END: Use Case */
1849
    }
1850
1851
    /**
1852
     * Test updating a user throwing UserPasswordValidationException when password doesn't follow specified rules.