|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\MockObject\MockObject;
|
15 | 15 | use Symfony\Component\Form\Exception\InvalidConfigurationException;
|
| 16 | +use Symfony\Component\Form\Extension\Core\Type\FormType; |
16 | 17 | use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
17 | 18 | use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
|
18 | 19 | use Symfony\Component\Form\Extension\PasswordHasher\EventListener\PasswordHasherListener;
|
@@ -80,6 +81,36 @@ public function testPasswordHashSuccess()
|
80 | 81 | $this->assertSame($user->getPassword(), $hashedPassword);
|
81 | 82 | }
|
82 | 83 |
|
| 84 | + public function testPasswordHashSkippedWithEmptyPassword() |
| 85 | + { |
| 86 | + $oldHashedPassword = 'PreviousHashedPassword'; |
| 87 | + |
| 88 | + $user = new User(); |
| 89 | + $user->setPassword($oldHashedPassword); |
| 90 | + |
| 91 | + $this->passwordHasher |
| 92 | + ->expects($this->never()) |
| 93 | + ->method('hashPassword') |
| 94 | + ; |
| 95 | + |
| 96 | + $this->assertEquals($user->getPassword(), $oldHashedPassword); |
| 97 | + |
| 98 | + $form = $this->factory |
| 99 | + ->createBuilder(FormType::class, $user) |
| 100 | + ->add('plainPassword', PasswordType::class, [ |
| 101 | + 'hash_property_path' => 'password', |
| 102 | + 'mapped' => false, |
| 103 | + 'required' => false, |
| 104 | + ]) |
| 105 | + ->getForm() |
| 106 | + ; |
| 107 | + |
| 108 | + $form->submit(['plainPassword' => '']); |
| 109 | + |
| 110 | + $this->assertTrue($form->isValid()); |
| 111 | + $this->assertSame($user->getPassword(), $oldHashedPassword); |
| 112 | + } |
| 113 | + |
83 | 114 | public function testPasswordHashSuccessWithEmptyData()
|
84 | 115 | {
|
85 | 116 | $user = new User();
|
|
0 commit comments