Code Duplication    Length = 20-33 lines in 2 locations

eZ/Publish/API/Repository/Tests/Values/User/Limitation/UserGroupLimitationTest.php 1 location

@@ 87-106 (lines=20) @@
84
     *
85
     * @return \eZ\Publish\API\Repository\Values\User\UserGroup
86
     */
87
    protected function prepareUserGroup()
88
    {
89
        $repository = $this->getRepository();
90
        $userService = $repository->getUserService();
91
92
        $parentUserGroupId = $this->generateId('location', 4);
93
        /* BEGIN: Inline */
94
        $userGroupCreate = $userService->newUserGroupCreateStruct('eng-GB');
95
        $userGroupCreate->setField('name', 'Shared wiki');
96
97
        $userGroup = $userService->createUserGroup(
98
            $userGroupCreate,
99
            $userService->loadUserGroup(
100
                $parentUserGroupId
101
            )
102
        );
103
        /* END: Inline */
104
105
        return $userGroup;
106
    }
107
108
    /**
109
     * Prepares the limitation fixture.

eZ/Publish/API/Repository/Tests/UserServiceTest.php 1 location

@@ 954-986 (lines=33) @@
951
     * @see \eZ\Publish\API\Repository\UserService::createUser()
952
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
953
     */
954
    public function testCreateUserWhenMissingField()
955
    {
956
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException::class);
957
958
        $repository = $this->getRepository();
959
960
        $editorsGroupId = $this->generateId('group', 13);
961
        /* BEGIN: Use Case */
962
        // $editorsGroupId is the ID of the "Editors" user group in an eZ
963
        // Publish demo installation
964
965
        $userService = $repository->getUserService();
966
967
        // Instantiate a create struct with mandatory properties
968
        $userCreate = $userService->newUserCreateStruct(
969
            'user',
970
            '[email protected]',
971
            'secret',
972
            'eng-US'
973
        );
974
975
        // Do not set the mandatory fields "first_name" and "last_name"
976
        //$userCreate->setField( 'first_name', 'Example' );
977
        //$userCreate->setField( 'last_name', 'User' );
978
979
        // Load parent group for the user
980
        $group = $userService->loadUserGroup($editorsGroupId);
981
982
        // This call will fail with a "ContentFieldValidationException", because the
983
        // mandatory fields "first_name" and "last_name" are not set.
984
        $userService->createUser($userCreate, [$group]);
985
        /* END: Use Case */
986
    }
987
988
    /**
989
     * Test for the createUser() method.