Code Duplication    Length = 20-31 lines in 3 locations

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

@@ 266-291 (lines=26) @@
263
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
264
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUserGroup
265
     */
266
    public function testCreateUserGroupThrowsInvalidArgumentException()
267
    {
268
        $repository = $this->getRepository();
269
270
        $mainGroupId = $this->generateId('group', 4);
271
        /* BEGIN: Use Case */
272
        // $mainGroupId is the ID of the main "Users" group
273
274
        $userService = $repository->getUserService();
275
276
        // Load main group
277
        $parentUserGroup = $userService->loadUserGroup($mainGroupId);
278
279
        // Instantiate a new create struct
280
        $userGroupCreate = $userService->newUserGroupCreateStruct('eng-US');
281
        $userGroupCreate->setField('name', 'Example Group');
282
        $userGroupCreate->remoteId = '5f7f0bdb3381d6a461d8c29ff53d908f';
283
284
        // This call will fail with an "InvalidArgumentException", because the
285
        // specified remoteId is already used for the "Members" user group.
286
        $userService->createUserGroup(
287
            $userGroupCreate,
288
            $parentUserGroup
289
        );
290
        /* END: Use Case */
291
    }
292
293
    /**
294
     * Test for the createUserGroup() method.
@@ 860-890 (lines=31) @@
857
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException
858
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
859
     */
860
    public function testCreateUserThrowsContentValidationExceptionForMissingField()
861
    {
862
        $repository = $this->getRepository();
863
864
        $editorsGroupId = $this->generateId('group', 13);
865
        /* BEGIN: Use Case */
866
        // $editorsGroupId is the ID of the "Editors" user group in an eZ
867
        // Publish demo installation
868
869
        $userService = $repository->getUserService();
870
871
        // Instantiate a create struct with mandatory properties
872
        $userCreate = $userService->newUserCreateStruct(
873
            'user',
874
            '[email protected]',
875
            'secret',
876
            'eng-US'
877
        );
878
879
        // Do not set the mandatory fields "first_name" and "last_name"
880
        //$userCreate->setField( 'first_name', 'Example' );
881
        //$userCreate->setField( 'last_name', 'User' );
882
883
        // Load parent group for the user
884
        $group = $userService->loadUserGroup($editorsGroupId);
885
886
        // This call will fail with a "ContentValidationException", because the
887
        // mandatory fields "first_name" and "last_name" are not set.
888
        $userService->createUser($userCreate, array($group));
889
        /* END: Use Case */
890
    }
891
892
    /**
893
     * Test for the createUser() method.

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

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