Code Duplication    Length = 25-28 lines in 3 locations

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

@@ 706-730 (lines=25) @@
703
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
704
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUserGroup
705
     */
706
    public function testUpdateUserGroupThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
707
    {
708
        $repository = $this->getRepository();
709
        $userService = $repository->getUserService();
710
711
        /* BEGIN: Use Case */
712
        $userGroup = $this->createUserGroupVersion1();
713
714
        // Load the content service
715
        $contentService = $repository->getContentService();
716
717
        // Create a content update struct and update the group name
718
        $contentUpdate = $contentService->newContentUpdateStruct();
719
        // An object of stdClass is not accepted as a value by the field "name"
720
        $contentUpdate->setField('name', new \stdClass(), 'eng-US');
721
722
        // Create a group update struct and set content update struct
723
        $groupUpdate = $userService->newUserGroupUpdateStruct();
724
        $groupUpdate->contentUpdateStruct = $contentUpdate;
725
726
        // This call will fail with an InvalidArgumentException, because the
727
        // field "name" does not accept the given value
728
        $userService->updateUserGroup($userGroup, $groupUpdate);
729
        /* END: Use Case */
730
    }
731
732
    /**
733
     * Test for the newUserCreateStruct() method.
@@ 1807-1834 (lines=28) @@
1804
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
1805
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1806
     */
1807
    public function testUpdateUserWhenMissingField()
1808
    {
1809
        $repository = $this->getRepository();
1810
1811
        $userService = $repository->getUserService();
1812
1813
        /* BEGIN: Use Case */
1814
        $user = $this->createUserVersion1();
1815
1816
        // Get the ContentService implementation
1817
        $contentService = $repository->getContentService();
1818
1819
        // Create a content update struct and change the remote id.
1820
        $contentUpdate = $contentService->newContentUpdateStruct();
1821
        $contentUpdate->setField('first_name', null, 'eng-US');
1822
1823
        // Create a new update struct instance
1824
        $userUpdate = $userService->newUserUpdateStruct();
1825
1826
        // Set the content update struct.
1827
        $userUpdate->contentUpdateStruct = $contentUpdate;
1828
1829
        // This call will fail with a "ContentFieldValidationException" because the
1830
        // mandatory field "first_name" is set to an empty value.
1831
        $userService->updateUser($user, $userUpdate);
1832
1833
        /* END: Use Case */
1834
    }
1835
1836
    /**
1837
     * Test for the updateUser() method.
@@ 1843-1870 (lines=28) @@
1840
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1841
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1842
     */
1843
    public function testUpdateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
1844
    {
1845
        $repository = $this->getRepository();
1846
1847
        $userService = $repository->getUserService();
1848
1849
        /* BEGIN: Use Case */
1850
        $user = $this->createUserVersion1();
1851
1852
        // Get the ContentService implementation
1853
        $contentService = $repository->getContentService();
1854
1855
        $contentUpdate = $contentService->newContentUpdateStruct();
1856
        // An object of stdClass is not valid for the field first_name
1857
        $contentUpdate->setField('first_name', new \stdClass(), 'eng-US');
1858
1859
        // Create a new update struct instance
1860
        $userUpdate = $userService->newUserUpdateStruct();
1861
1862
        // Set the content update struct.
1863
        $userUpdate->contentUpdateStruct = $contentUpdate;
1864
1865
        // This call will fail with a "InvalidArgumentException" because the
1866
        // the field "first_name" does not accept the given value.
1867
        $userService->updateUser($user, $userUpdate);
1868
1869
        /* END: Use Case */
1870
    }
1871
1872
    /**
1873
     * Test updating a user throwing UserPasswordValidationException when password doesn't follow specified rules.