mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Alchemy\Tests\Phrasea\Form\Constraint;
|
|
|
|
use Alchemy\Phrasea\Form\Constraint\PasswordToken;
|
|
|
|
class PasswordTokenTest extends \PhraseanetPHPUnitAbstract
|
|
{
|
|
public function testInvalidTokenIsNotValid()
|
|
{
|
|
$random = $this
|
|
->getMockBuilder('random')
|
|
->disableOriginalConstructor()
|
|
->setMethods(array('helloToken'))
|
|
->getMock();
|
|
|
|
$token = \random::generatePassword();
|
|
|
|
$random
|
|
->expects($this->once())
|
|
->method('helloToken')
|
|
->with(self::$DI['app'], $token)
|
|
->will($this->throwException(new \Exception_NotFound('Token not found')));
|
|
|
|
$constraint = new PasswordToken(self::$DI['app'], $random);
|
|
$this->assertFalse($constraint->isValid($token));
|
|
}
|
|
|
|
public function testValidTokenIsValid()
|
|
{
|
|
$random = $this
|
|
->getMockBuilder('random')
|
|
->disableOriginalConstructor()
|
|
->setMethods(array('helloToken'))
|
|
->getMock();
|
|
|
|
$token = \random::generatePassword();
|
|
|
|
$random
|
|
->expects($this->once())
|
|
->method('helloToken')
|
|
->with(self::$DI['app'], $token)
|
|
->will($this->returnValue(array('usr_id' => mt_rand(), 'type' => \random::TYPE_PASSWORD)));
|
|
|
|
$constraint = new PasswordToken(self::$DI['app'], $random);
|
|
$this->assertTrue($constraint->isValid($token));
|
|
}
|
|
}
|