| @@ 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. |
|
| @@ 282-307 (lines=26) @@ | ||
| 279 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
|
| 280 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUserGroup |
|
| 281 | */ |
|
| 282 | public function testCreateUserGroupThrowsInvalidArgumentException() |
|
| 283 | { |
|
| 284 | $repository = $this->getRepository(); |
|
| 285 | ||
| 286 | $mainGroupId = $this->generateId('group', 4); |
|
| 287 | /* BEGIN: Use Case */ |
|
| 288 | // $mainGroupId is the ID of the main "Users" group |
|
| 289 | ||
| 290 | $userService = $repository->getUserService(); |
|
| 291 | ||
| 292 | // Load main group |
|
| 293 | $parentUserGroup = $userService->loadUserGroup($mainGroupId); |
|
| 294 | ||
| 295 | // Instantiate a new create struct |
|
| 296 | $userGroupCreate = $userService->newUserGroupCreateStruct('eng-US'); |
|
| 297 | $userGroupCreate->setField('name', 'Example Group'); |
|
| 298 | $userGroupCreate->remoteId = '5f7f0bdb3381d6a461d8c29ff53d908f'; |
|
| 299 | ||
| 300 | // This call will fail with an "InvalidArgumentException", because the |
|
| 301 | // specified remoteId is already used for the "Members" user group. |
|
| 302 | $userService->createUserGroup( |
|
| 303 | $userGroupCreate, |
|
| 304 | $parentUserGroup |
|
| 305 | ); |
|
| 306 | /* END: Use Case */ |
|
| 307 | } |
|
| 308 | ||
| 309 | /** |
|
| 310 | * Test for the createUserGroup() method. |
|
| @@ 907-937 (lines=31) @@ | ||
| 904 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
|
| 905 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
|
| 906 | */ |
|
| 907 | public function testCreateUserWhenMissingField() |
|
| 908 | { |
|
| 909 | $repository = $this->getRepository(); |
|
| 910 | ||
| 911 | $editorsGroupId = $this->generateId('group', 13); |
|
| 912 | /* BEGIN: Use Case */ |
|
| 913 | // $editorsGroupId is the ID of the "Editors" user group in an eZ |
|
| 914 | // Publish demo installation |
|
| 915 | ||
| 916 | $userService = $repository->getUserService(); |
|
| 917 | ||
| 918 | // Instantiate a create struct with mandatory properties |
|
| 919 | $userCreate = $userService->newUserCreateStruct( |
|
| 920 | 'user', |
|
| 921 | '[email protected]', |
|
| 922 | 'secret', |
|
| 923 | 'eng-US' |
|
| 924 | ); |
|
| 925 | ||
| 926 | // Do not set the mandatory fields "first_name" and "last_name" |
|
| 927 | //$userCreate->setField( 'first_name', 'Example' ); |
|
| 928 | //$userCreate->setField( 'last_name', 'User' ); |
|
| 929 | ||
| 930 | // Load parent group for the user |
|
| 931 | $group = $userService->loadUserGroup($editorsGroupId); |
|
| 932 | ||
| 933 | // This call will fail with a "ContentFieldValidationException", because the |
|
| 934 | // mandatory fields "first_name" and "last_name" are not set. |
|
| 935 | $userService->createUser($userCreate, array($group)); |
|
| 936 | /* END: Use Case */ |
|
| 937 | } |
|
| 938 | ||
| 939 | /** |
|
| 940 | * Test for the createUser() method. |
|