Code Duplication    Length = 27-30 lines in 3 locations

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

@@ 751-777 (lines=27) @@
748
     * @see \eZ\Publish\API\Repository\UserService::updateUserGroup()
749
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUserGroup
750
     */
751
    public function testUpdateUserGroupThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
752
    {
753
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class);
754
755
        $repository = $this->getRepository();
756
        $userService = $repository->getUserService();
757
758
        /* BEGIN: Use Case */
759
        $userGroup = $this->createUserGroupVersion1();
760
761
        // Load the content service
762
        $contentService = $repository->getContentService();
763
764
        // Create a content update struct and update the group name
765
        $contentUpdate = $contentService->newContentUpdateStruct();
766
        // An object of stdClass is not accepted as a value by the field "name"
767
        $contentUpdate->setField('name', new \stdClass(), 'eng-US');
768
769
        // Create a group update struct and set content update struct
770
        $groupUpdate = $userService->newUserGroupUpdateStruct();
771
        $groupUpdate->contentUpdateStruct = $contentUpdate;
772
773
        // This call will fail with an InvalidArgumentException, because the
774
        // field "name" does not accept the given value
775
        $userService->updateUserGroup($userGroup, $groupUpdate);
776
        /* END: Use Case */
777
    }
778
779
    /**
780
     * Test for the newUserCreateStruct() method.
@@ 1891-1920 (lines=30) @@
1888
     * @see \eZ\Publish\API\Repository\UserService::updateUser()
1889
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1890
     */
1891
    public function testUpdateUserWhenMissingField()
1892
    {
1893
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException::class);
1894
1895
        $repository = $this->getRepository();
1896
1897
        $userService = $repository->getUserService();
1898
1899
        /* BEGIN: Use Case */
1900
        $user = $this->createUserVersion1();
1901
1902
        // Get the ContentService implementation
1903
        $contentService = $repository->getContentService();
1904
1905
        // Create a content update struct and change the remote id.
1906
        $contentUpdate = $contentService->newContentUpdateStruct();
1907
        $contentUpdate->setField('first_name', null, 'eng-US');
1908
1909
        // Create a new update struct instance
1910
        $userUpdate = $userService->newUserUpdateStruct();
1911
1912
        // Set the content update struct.
1913
        $userUpdate->contentUpdateStruct = $contentUpdate;
1914
1915
        // This call will fail with a "ContentFieldValidationException" because the
1916
        // mandatory field "first_name" is set to an empty value.
1917
        $userService->updateUser($user, $userUpdate);
1918
1919
        /* END: Use Case */
1920
    }
1921
1922
    /**
1923
     * Test for the updateUser() method.
@@ 1928-1957 (lines=30) @@
1925
     * @see \eZ\Publish\API\Repository\UserService::updateUser()
1926
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1927
     */
1928
    public function testUpdateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
1929
    {
1930
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class);
1931
1932
        $repository = $this->getRepository();
1933
1934
        $userService = $repository->getUserService();
1935
1936
        /* BEGIN: Use Case */
1937
        $user = $this->createUserVersion1();
1938
1939
        // Get the ContentService implementation
1940
        $contentService = $repository->getContentService();
1941
1942
        $contentUpdate = $contentService->newContentUpdateStruct();
1943
        // An object of stdClass is not valid for the field first_name
1944
        $contentUpdate->setField('first_name', new \stdClass(), 'eng-US');
1945
1946
        // Create a new update struct instance
1947
        $userUpdate = $userService->newUserUpdateStruct();
1948
1949
        // Set the content update struct.
1950
        $userUpdate->contentUpdateStruct = $contentUpdate;
1951
1952
        // This call will fail with a "InvalidArgumentException" because the
1953
        // the field "first_name" does not accept the given value.
1954
        $userService->updateUser($user, $userUpdate);
1955
1956
        /* END: Use Case */
1957
    }
1958
1959
    /**
1960
     * Test updating a user throwing UserPasswordValidationException when password doesn't follow specified rules.