|
@@ 1014-1044 (lines=31) @@
|
| 1011 |
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
| 1012 |
|
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
| 1013 |
|
*/ |
| 1014 |
|
public function testCreateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept() |
| 1015 |
|
{ |
| 1016 |
|
$repository = $this->getRepository(); |
| 1017 |
|
|
| 1018 |
|
$editorsGroupId = $this->generateId('group', 13); |
| 1019 |
|
/* BEGIN: Use Case */ |
| 1020 |
|
// $editorsGroupId is the ID of the "Editors" user group in an eZ |
| 1021 |
|
// Publish demo installation |
| 1022 |
|
|
| 1023 |
|
$userService = $repository->getUserService(); |
| 1024 |
|
|
| 1025 |
|
// Instantiate a create struct with mandatory properties |
| 1026 |
|
$userCreate = $userService->newUserCreateStruct( |
| 1027 |
|
'user', |
| 1028 |
|
'[email protected]', |
| 1029 |
|
'secret', |
| 1030 |
|
'eng-US' |
| 1031 |
|
); |
| 1032 |
|
|
| 1033 |
|
// An object of stdClass is not a valid value for the field first_name |
| 1034 |
|
$userCreate->setField('first_name', new \stdClass()); |
| 1035 |
|
$userCreate->setField('last_name', 'User'); |
| 1036 |
|
|
| 1037 |
|
// Load parent group for the user |
| 1038 |
|
$group = $userService->loadUserGroup($editorsGroupId); |
| 1039 |
|
|
| 1040 |
|
// This call will fail with an "InvalidArgumentException", because the |
| 1041 |
|
// value for the firled "first_name" is not accepted by the field type. |
| 1042 |
|
$userService->createUser($userCreate, array($group)); |
| 1043 |
|
/* END: Use Case */ |
| 1044 |
|
} |
| 1045 |
|
|
| 1046 |
|
/** |
| 1047 |
|
* Test for the createUser() method. |
|
@@ 1054-1084 (lines=31) @@
|
| 1051 |
|
* @expectedExceptionMessage Argument 'userCreateStruct' is invalid: User with provided login already exists |
| 1052 |
|
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
| 1053 |
|
*/ |
| 1054 |
|
public function testCreateUserThrowsInvalidArgumentException() |
| 1055 |
|
{ |
| 1056 |
|
$repository = $this->getRepository(); |
| 1057 |
|
|
| 1058 |
|
$editorsGroupId = $this->generateId('group', 13); |
| 1059 |
|
/* BEGIN: Use Case */ |
| 1060 |
|
// $editorsGroupId is the ID of the "Editors" user group in an eZ |
| 1061 |
|
// Publish demo installation |
| 1062 |
|
|
| 1063 |
|
$userService = $repository->getUserService(); |
| 1064 |
|
|
| 1065 |
|
// Instantiate a create struct with mandatory properties |
| 1066 |
|
$userCreate = $userService->newUserCreateStruct( |
| 1067 |
|
// admin is an existing login |
| 1068 |
|
'admin', |
| 1069 |
|
'[email protected]', |
| 1070 |
|
'secret', |
| 1071 |
|
'eng-US' |
| 1072 |
|
); |
| 1073 |
|
|
| 1074 |
|
$userCreate->setField('first_name', 'Example'); |
| 1075 |
|
$userCreate->setField('last_name', 'User'); |
| 1076 |
|
|
| 1077 |
|
// Load parent group for the user |
| 1078 |
|
$group = $userService->loadUserGroup($editorsGroupId); |
| 1079 |
|
|
| 1080 |
|
// This call will fail with a "InvalidArgumentException", because the |
| 1081 |
|
// user with "admin" login already exists. |
| 1082 |
|
$userService->createUser($userCreate, array($group)); |
| 1083 |
|
/* END: Use Case */ |
| 1084 |
|
} |
| 1085 |
|
|
| 1086 |
|
/** |
| 1087 |
|
* Test for the createUser() method. |