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

@@ 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.
@@ 981-1011 (lines=31) @@
978
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
979
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
980
     */
981
    public function testCreateUserWhenMissingField()
982
    {
983
        $repository = $this->getRepository();
984
985
        $editorsGroupId = $this->generateId('group', 13);
986
        /* BEGIN: Use Case */
987
        // $editorsGroupId is the ID of the "Editors" user group in an eZ
988
        // Publish demo installation
989
990
        $userService = $repository->getUserService();
991
992
        // Instantiate a create struct with mandatory properties
993
        $userCreate = $userService->newUserCreateStruct(
994
            'user',
995
            '[email protected]',
996
            'secret',
997
            'eng-US'
998
        );
999
1000
        // Do not set the mandatory fields "first_name" and "last_name"
1001
        //$userCreate->setField( 'first_name', 'Example' );
1002
        //$userCreate->setField( 'last_name', 'User' );
1003
1004
        // Load parent group for the user
1005
        $group = $userService->loadUserGroup($editorsGroupId);
1006
1007
        // This call will fail with a "ContentFieldValidationException", because the
1008
        // mandatory fields "first_name" and "last_name" are not set.
1009
        $userService->createUser($userCreate, array($group));
1010
        /* END: Use Case */
1011
    }
1012
1013
    /**
1014
     * Test for the createUser() method.
@@ 847-859 (lines=13) @@
844
     * @covers \eZ\Publish\API\Repository\UserService::updateUserGroup
845
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
846
     */
847
    public function testUpdateUserGroupThrowsContentFieldValidationExceptionOnRequiredFieldEmpty()
848
    {
849
        $repository = $this->getRepository();
850
        $userService = $repository->getUserService();
851
        $contentService = $repository->getContentService();
852
853
        $userGroup = $userService->loadUserGroup(42);
854
        $userGroupUpdateStruct = $userService->newUserGroupUpdateStruct();
855
        $userGroupUpdateStruct->contentUpdateStruct = $contentService->newContentUpdateStruct();
856
        $userGroupUpdateStruct->contentUpdateStruct->setField('name', '', 'eng-US');
857
858
        $userService->updateUserGroup($userGroup, $userGroupUpdateStruct);
859
    }
860
861
    /**
862
     * Test for the newUserCreateStruct() method.