|
@@ 984-1014 (lines=31) @@
|
| 981 |
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
| 982 |
|
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
| 983 |
|
*/ |
| 984 |
|
public function testCreateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept() |
| 985 |
|
{ |
| 986 |
|
$repository = $this->getRepository(); |
| 987 |
|
|
| 988 |
|
$editorsGroupId = $this->generateId('group', 13); |
| 989 |
|
/* BEGIN: Use Case */ |
| 990 |
|
// $editorsGroupId is the ID of the "Editors" user group in an eZ |
| 991 |
|
// Publish demo installation |
| 992 |
|
|
| 993 |
|
$userService = $repository->getUserService(); |
| 994 |
|
|
| 995 |
|
// Instantiate a create struct with mandatory properties |
| 996 |
|
$userCreate = $userService->newUserCreateStruct( |
| 997 |
|
'user', |
| 998 |
|
'[email protected]', |
| 999 |
|
'secret', |
| 1000 |
|
'eng-US' |
| 1001 |
|
); |
| 1002 |
|
|
| 1003 |
|
// An object of stdClass is not a valid value for the field first_name |
| 1004 |
|
$userCreate->setField('first_name', new \stdClass()); |
| 1005 |
|
$userCreate->setField('last_name', 'User'); |
| 1006 |
|
|
| 1007 |
|
// Load parent group for the user |
| 1008 |
|
$group = $userService->loadUserGroup($editorsGroupId); |
| 1009 |
|
|
| 1010 |
|
// This call will fail with an "InvalidArgumentException", because the |
| 1011 |
|
// value for the firled "first_name" is not accepted by the field type. |
| 1012 |
|
$userService->createUser($userCreate, [$group]); |
| 1013 |
|
/* END: Use Case */ |
| 1014 |
|
} |
| 1015 |
|
|
| 1016 |
|
/** |
| 1017 |
|
* Test for the createUser() method. |
|
@@ 1024-1054 (lines=31) @@
|
| 1021 |
|
* @expectedExceptionMessage Argument 'userCreateStruct' is invalid: User with provided login already exists |
| 1022 |
|
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
| 1023 |
|
*/ |
| 1024 |
|
public function testCreateUserThrowsInvalidArgumentException() |
| 1025 |
|
{ |
| 1026 |
|
$repository = $this->getRepository(); |
| 1027 |
|
|
| 1028 |
|
$editorsGroupId = $this->generateId('group', 13); |
| 1029 |
|
/* BEGIN: Use Case */ |
| 1030 |
|
// $editorsGroupId is the ID of the "Editors" user group in an eZ |
| 1031 |
|
// Publish demo installation |
| 1032 |
|
|
| 1033 |
|
$userService = $repository->getUserService(); |
| 1034 |
|
|
| 1035 |
|
// Instantiate a create struct with mandatory properties |
| 1036 |
|
$userCreate = $userService->newUserCreateStruct( |
| 1037 |
|
// admin is an existing login |
| 1038 |
|
'admin', |
| 1039 |
|
'[email protected]', |
| 1040 |
|
'secret', |
| 1041 |
|
'eng-US' |
| 1042 |
|
); |
| 1043 |
|
|
| 1044 |
|
$userCreate->setField('first_name', 'Example'); |
| 1045 |
|
$userCreate->setField('last_name', 'User'); |
| 1046 |
|
|
| 1047 |
|
// Load parent group for the user |
| 1048 |
|
$group = $userService->loadUserGroup($editorsGroupId); |
| 1049 |
|
|
| 1050 |
|
// This call will fail with a "InvalidArgumentException", because the |
| 1051 |
|
// user with "admin" login already exists. |
| 1052 |
|
$userService->createUser($userCreate, [$group]); |
| 1053 |
|
/* END: Use Case */ |
| 1054 |
|
} |
| 1055 |
|
|
| 1056 |
|
/** |
| 1057 |
|
* Test for the createUser() method. |