Files
Phraseanet/tests/Alchemy/Tests/Phrasea/Form/Constraint/PasswordTokenTest.php
Romain Neutron 5e6d506d8d Add forms
2013-05-29 14:23:17 +02:00

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));
}
}