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