Code Duplication    Length = 20-31 lines in 3 locations

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

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

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

@@ 302-327 (lines=26) @@
299
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
300
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUserGroup
301
     */
302
    public function testCreateUserGroupThrowsInvalidArgumentException()
303
    {
304
        $repository = $this->getRepository();
305
306
        $mainGroupId = $this->generateId('group', 4);
307
        /* BEGIN: Use Case */
308
        // $mainGroupId is the ID of the main "Users" group
309
310
        $userService = $repository->getUserService();
311
312
        // Load main group
313
        $parentUserGroup = $userService->loadUserGroup($mainGroupId);
314
315
        // Instantiate a new create struct
316
        $userGroupCreate = $userService->newUserGroupCreateStruct('eng-US');
317
        $userGroupCreate->setField('name', 'Example Group');
318
        $userGroupCreate->remoteId = '5f7f0bdb3381d6a461d8c29ff53d908f';
319
320
        // This call will fail with an "InvalidArgumentException", because the
321
        // specified remoteId is already used for the "Members" user group.
322
        $userService->createUserGroup(
323
            $userGroupCreate,
324
            $parentUserGroup
325
        );
326
        /* END: Use Case */
327
    }
328
329
    /**
330
     * Test for the createUserGroup() method.
@@ 977-1007 (lines=31) @@
974
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
975
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
976
     */
977
    public function testCreateUserWhenMissingField()
978
    {
979
        $repository = $this->getRepository();
980
981
        $editorsGroupId = $this->generateId('group', 13);
982
        /* BEGIN: Use Case */
983
        // $editorsGroupId is the ID of the "Editors" user group in an eZ
984
        // Publish demo installation
985
986
        $userService = $repository->getUserService();
987
988
        // Instantiate a create struct with mandatory properties
989
        $userCreate = $userService->newUserCreateStruct(
990
            'user',
991
            '[email protected]',
992
            'secret',
993
            'eng-US'
994
        );
995
996
        // Do not set the mandatory fields "first_name" and "last_name"
997
        //$userCreate->setField( 'first_name', 'Example' );
998
        //$userCreate->setField( 'last_name', 'User' );
999
1000
        // Load parent group for the user
1001
        $group = $userService->loadUserGroup($editorsGroupId);
1002
1003
        // This call will fail with a "ContentFieldValidationException", because the
1004
        // mandatory fields "first_name" and "last_name" are not set.
1005
        $userService->createUser($userCreate, array($group));
1006
        /* END: Use Case */
1007
    }
1008
1009
    /**
1010
     * Test for the createUser() method.