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