/** * @covers User::create * @depends testValidateModel */ public function testCreateWithLoginAlreadyUsed() { $user = new User(); $user->login = '******'; $user->name = 'name'; $user->password = '******'; $user->status = 1; if (!$this->object->validateModel($user, $error)) { $this->markTestIncomplete('User creation has been skipped because model validation failed'); return; } $this->assertFalse($this->object->create($user, $error), 'User creation should be refused because requested login is already used'); $this->assertEquals('login `' . $user->login . '` already exists', $error, 'Error message should explain that login is already used, but following reason is returned: ' . $error); }
if (!$api->checkAuth()) { //User not authentified/authorized return; } if (!$api->checkScope('admin')) { $api->output(403, 'Admin scope is required for creating user'); //indicate the requester do not have the required scope for creating another user return; } $user = new User(); //adapt and validate object received $requestedUser = $api->query['body']; if ($requestedUser !== null) { $requestedUser->status = 1; } if (!$user->validateModel($requestedUser, $errorMessage)) { $api->output(400, 'User is not valid: ' . $errorMessage); //provided user is not valid return; } //create user if (!$user->create($requestedUser, $errorMessage)) { $api->output(500, 'Error during creation: ' . $errorMessage); //something gone wrong :( return; } //add scope if (property_exists($requestedUser, 'scope')) { if (!$user->updateScope($requestedUser->scope)) { $api->output(500, 'User is created but not his scope'); //something gone wrong :(