fix validation for create user command (#709)
This commit is contained in:
@@ -111,7 +111,7 @@ class CreateUserCommand extends Command
|
|||||||
$pwd = $this->encoder->encodePassword($user, $user->getPlainPassword());
|
$pwd = $this->encoder->encodePassword($user, $user->getPlainPassword());
|
||||||
$user->setPassword($pwd);
|
$user->setPassword($pwd);
|
||||||
|
|
||||||
$errors = $this->validator->validate($user, null, ['registration']);
|
$errors = $this->validator->validate($user, null, ['Registration']);
|
||||||
if ($errors->count() > 0) {
|
if ($errors->count() > 0) {
|
||||||
/** @var \Symfony\Component\Validator\ConstraintViolation $error */
|
/** @var \Symfony\Component\Validator\ConstraintViolation $error */
|
||||||
foreach ($errors as $error) {
|
foreach ($errors as $error) {
|
||||||
|
|||||||
@@ -72,8 +72,10 @@ class CreateUserCommandTest extends KernelTestCase
|
|||||||
{
|
{
|
||||||
$commandTester = $this->createUser('xx', '', 'ROLE_USER', '');
|
$commandTester = $this->createUser('xx', '', 'ROLE_USER', '');
|
||||||
$output = $commandTester->getDisplay();
|
$output = $commandTester->getDisplay();
|
||||||
|
$this->assertContains('[ERROR] email ()', $output);
|
||||||
|
$this->assertContains('Please enter an email', $output);
|
||||||
$this->assertContains('[ERROR] plainPassword ()', $output);
|
$this->assertContains('[ERROR] plainPassword ()', $output);
|
||||||
// TODO the test validator is misconfigured, doesn't find "short username" and "empty email"
|
$this->assertContains('Please enter a password', $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUserAlreadyExisting()
|
public function testUserAlreadyExisting()
|
||||||
@@ -82,6 +84,16 @@ class CreateUserCommandTest extends KernelTestCase
|
|||||||
$commandTester = $this->createUser('MyTestUser', 'user@example.com', 'ROLE_USER', 'foobar');
|
$commandTester = $this->createUser('MyTestUser', 'user@example.com', 'ROLE_USER', 'foobar');
|
||||||
|
|
||||||
$output = $commandTester->getDisplay();
|
$output = $commandTester->getDisplay();
|
||||||
$this->assertContains('[ERROR] Failed to create user: MyTestUser', $output);
|
$this->assertContains('[ERROR] username (mytestuser)', $output);
|
||||||
|
$this->assertContains('The username is already used', $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUserEmail()
|
||||||
|
{
|
||||||
|
$commandTester = $this->createUser('MyTestUser', 'ROLE_USER', 'ROLE_USER', 'foobar');
|
||||||
|
|
||||||
|
$output = $commandTester->getDisplay();
|
||||||
|
$this->assertContains('[ERROR] email (ROLE_USER)', $output);
|
||||||
|
$this->assertContains('The email is not valid', $output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user