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.
@@ 1831-1858 (lines=28) @@
1828
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
1829
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1830
     */
1831
    public function testUpdateUserWhenMissingField()
1832
    {
1833
        $repository = $this->getRepository();
1834
1835
        $userService = $repository->getUserService();
1836
1837
        /* BEGIN: Use Case */
1838
        $user = $this->createUserVersion1();
1839
1840
        // Get the ContentService implementation
1841
        $contentService = $repository->getContentService();
1842
1843
        // Create a content update struct and change the remote id.
1844
        $contentUpdate = $contentService->newContentUpdateStruct();
1845
        $contentUpdate->setField('first_name', null, 'eng-US');
1846
1847
        // Create a new update struct instance
1848
        $userUpdate = $userService->newUserUpdateStruct();
1849
1850
        // Set the content update struct.
1851
        $userUpdate->contentUpdateStruct = $contentUpdate;
1852
1853
        // This call will fail with a "ContentFieldValidationException" because the
1854
        // mandatory field "first_name" is set to an empty value.
1855
        $userService->updateUser($user, $userUpdate);
1856
1857
        /* END: Use Case */
1858
    }
1859
1860
    /**
1861
     * Test for the updateUser() method.
@@ 1867-1894 (lines=28) @@
1864
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1865
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1866
     */
1867
    public function testUpdateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
1868
    {
1869
        $repository = $this->getRepository();
1870
1871
        $userService = $repository->getUserService();
1872
1873
        /* BEGIN: Use Case */
1874
        $user = $this->createUserVersion1();
1875
1876
        // Get the ContentService implementation
1877
        $contentService = $repository->getContentService();
1878
1879
        $contentUpdate = $contentService->newContentUpdateStruct();
1880
        // An object of stdClass is not valid for the field first_name
1881
        $contentUpdate->setField('first_name', new \stdClass(), 'eng-US');
1882
1883
        // Create a new update struct instance
1884
        $userUpdate = $userService->newUserUpdateStruct();
1885
1886
        // Set the content update struct.
1887
        $userUpdate->contentUpdateStruct = $contentUpdate;
1888
1889
        // This call will fail with a "InvalidArgumentException" because the
1890
        // the field "first_name" does not accept the given value.
1891
        $userService->updateUser($user, $userUpdate);
1892
1893
        /* END: Use Case */
1894
    }
1895
1896
    /**
1897
     * Test updating a user throwing UserPasswordValidationException when password doesn't follow specified rules.