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

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