Files
Phraseanet/tests/Alchemy/Tests/Phrasea/Form/Constraint/PasswordTokenTest.php
2013-12-10 01:29:02 +01:00

50 lines
1.4 KiB
PHP

<?php
namespace Alchemy\Tests\Phrasea\Form\Constraint;
use Alchemy\Phrasea\Form\Constraint\PasswordToken;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class PasswordTokenTest extends \PhraseanetTestCase
{
public function testInvalidTokenIsNotValid()
{
$random = $this
->getMockBuilder('random')
->disableOriginalConstructor()
->setMethods(['helloToken'])
->getMock();
$token = \random::generatePassword();
$random
->expects($this->once())
->method('helloToken')
->with($token)
->will($this->throwException(new NotFoundHttpException('Token not found')));
$constraint = new PasswordToken(self::$DI['app'], $random);
$this->assertFalse($constraint->isValid($token));
}
public function testValidTokenIsValid()
{
$random = $this
->getMockBuilder('random')
->disableOriginalConstructor()
->setMethods(['helloToken'])
->getMock();
$token = \random::generatePassword();
$random
->expects($this->once())
->method('helloToken')
->with($token)
->will($this->returnValue(['usr_id' => mt_rand(), 'type' => \random::TYPE_PASSWORD]));
$constraint = new PasswordToken(self::$DI['app'], $random);
$this->assertTrue($constraint->isValid($token));
}
}