diff --git a/lib/Alchemy/Phrasea/Form/Constraint/PasswordToken.php b/lib/Alchemy/Phrasea/Form/Constraint/PasswordToken.php index 19b8a6f27a..d5a4eacb5c 100644 --- a/lib/Alchemy/Phrasea/Form/Constraint/PasswordToken.php +++ b/lib/Alchemy/Phrasea/Form/Constraint/PasswordToken.php @@ -31,11 +31,11 @@ class PasswordToken extends Constraint public function isValid($token) { try { - $datas = $this->random->helloToken($this->app, $token); + $data = $this->random->helloToken($token); } catch (\Exception_NotFound $e) { return false; } - return \random::TYPE_PASSWORD === $datas['type']; + return \random::TYPE_PASSWORD === $data['type']; } } diff --git a/lib/Alchemy/Phrasea/Form/Constraint/PasswordTokenValidator.php b/lib/Alchemy/Phrasea/Form/Constraint/PasswordTokenValidator.php index c41e2d1a78..b2fcc0eecb 100644 --- a/lib/Alchemy/Phrasea/Form/Constraint/PasswordTokenValidator.php +++ b/lib/Alchemy/Phrasea/Form/Constraint/PasswordTokenValidator.php @@ -21,7 +21,7 @@ class PasswordTokenValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { - if ($constraint->isValid($value)) { + if (!$constraint->isValid($value)) { $this->context->addViolation('The token provided is not valid anymore'); } } diff --git a/tests/Alchemy/Tests/Phrasea/Form/Constraint/PasswordTokenTest.php b/tests/Alchemy/Tests/Phrasea/Form/Constraint/PasswordTokenTest.php index 65102f90ca..049df43bea 100644 --- a/tests/Alchemy/Tests/Phrasea/Form/Constraint/PasswordTokenTest.php +++ b/tests/Alchemy/Tests/Phrasea/Form/Constraint/PasswordTokenTest.php @@ -19,7 +19,7 @@ class PasswordTokenTest extends \PhraseanetPHPUnitAbstract $random ->expects($this->once()) ->method('helloToken') - ->with(self::$DI['app'], $token) + ->with($token) ->will($this->throwException(new \Exception_NotFound('Token not found'))); $constraint = new PasswordToken(self::$DI['app'], $random); @@ -39,7 +39,7 @@ class PasswordTokenTest extends \PhraseanetPHPUnitAbstract $random ->expects($this->once()) ->method('helloToken') - ->with(self::$DI['app'], $token) + ->with($token) ->will($this->returnValue(array('usr_id' => mt_rand(), 'type' => \random::TYPE_PASSWORD))); $constraint = new PasswordToken(self::$DI['app'], $random); diff --git a/tests/Alchemy/Tests/Phrasea/Form/Constraint/PasswordTokenValidatorTest.php b/tests/Alchemy/Tests/Phrasea/Form/Constraint/PasswordTokenValidatorTest.php index a378c25759..99491d722b 100644 --- a/tests/Alchemy/Tests/Phrasea/Form/Constraint/PasswordTokenValidatorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Form/Constraint/PasswordTokenValidatorTest.php @@ -13,10 +13,10 @@ class PasswordTokenValidatorTest extends \PhraseanetPHPUnitAbstract { $context = $this->getMock('Symfony\Component\Validator\ExecutionContextInterface'); $builder = $context - ->expects($this->exactly($isValid ? 1 : 0)) + ->expects($this->exactly($isValid ? 0 : 1)) ->method('addViolation'); - if ($isValid) { + if (!$isValid) { $builder->with($this->isType('string')); }