Code Duplication    Length = 13-31 lines in 4 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 3 locations

@@ 273-298 (lines=26) @@
270
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
271
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUserGroup
272
     */
273
    public function testCreateUserGroupThrowsInvalidArgumentException()
274
    {
275
        $repository = $this->getRepository();
276
277
        $mainGroupId = $this->generateId('group', 4);
278
        /* BEGIN: Use Case */
279
        // $mainGroupId is the ID of the main "Users" group
280
281
        $userService = $repository->getUserService();
282
283
        // Load main group
284
        $parentUserGroup = $userService->loadUserGroup($mainGroupId);
285
286
        // Instantiate a new create struct
287
        $userGroupCreate = $userService->newUserGroupCreateStruct('eng-US');
288
        $userGroupCreate->setField('name', 'Example Group');
289
        $userGroupCreate->remoteId = '5f7f0bdb3381d6a461d8c29ff53d908f';
290
291
        // This call will fail with an "InvalidArgumentException", because the
292
        // specified remoteId is already used for the "Members" user group.
293
        $userService->createUserGroup(
294
            $userGroupCreate,
295
            $parentUserGroup
296
        );
297
        /* END: Use Case */
298
    }
299
300
    /**
301
     * Test for the createUserGroup() method.
@@ 757-769 (lines=13) @@
754
     * @covers \eZ\Publish\API\Repository\UserService::updateUserGroup
755
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
756
     */
757
    public function testUpdateUserGroupThrowsContentFieldValidationExceptionOnRequiredFieldEmpty()
758
    {
759
        $repository = $this->getRepository();
760
        $userService = $repository->getUserService();
761
        $contentService = $repository->getContentService();
762
763
        $userGroup = $userService->loadUserGroup(42);
764
        $userGroupUpdateStruct = $userService->newUserGroupUpdateStruct();
765
        $userGroupUpdateStruct->contentUpdateStruct = $contentService->newContentUpdateStruct();
766
        $userGroupUpdateStruct->contentUpdateStruct->setField('name', '', 'eng-US');
767
768
        $userService->updateUserGroup($userGroup, $userGroupUpdateStruct);
769
    }
770
771
    /**
772
     * Test for the newUserCreateStruct() method.
@@ 885-915 (lines=31) @@
882
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
883
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
884
     */
885
    public function testCreateUserWhenMissingField()
886
    {
887
        $repository = $this->getRepository();
888
889
        $editorsGroupId = $this->generateId('group', 13);
890
        /* BEGIN: Use Case */
891
        // $editorsGroupId is the ID of the "Editors" user group in an eZ
892
        // Publish demo installation
893
894
        $userService = $repository->getUserService();
895
896
        // Instantiate a create struct with mandatory properties
897
        $userCreate = $userService->newUserCreateStruct(
898
            'user',
899
            '[email protected]',
900
            'secret',
901
            'eng-US'
902
        );
903
904
        // Do not set the mandatory fields "first_name" and "last_name"
905
        //$userCreate->setField( 'first_name', 'Example' );
906
        //$userCreate->setField( 'last_name', 'User' );
907
908
        // Load parent group for the user
909
        $group = $userService->loadUserGroup($editorsGroupId);
910
911
        // This call will fail with a "ContentFieldValidationException", because the
912
        // mandatory fields "first_name" and "last_name" are not set.
913
        $userService->createUser($userCreate, array($group));
914
        /* END: Use Case */
915
    }
916
917
    /**
918
     * Test for the createUser() method.