mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Alchemy\Tests\Phrasea\Form\Constraint;
|
|
|
|
use Alchemy\Phrasea\Form\Constraint\PasswordToken;
|
|
use Alchemy\Phrasea\Model\Entities\Token;
|
|
use Alchemy\Phrasea\Model\Manipulator\TokenManipulator;
|
|
|
|
class PasswordTokenTest extends \PhraseanetTestCase
|
|
{
|
|
public function testInvalidTokenIsNotValid()
|
|
{
|
|
$repo = $this
|
|
->getMockBuilder('Doctrine\ORM\EntityRepository')
|
|
->disableOriginalConstructor()
|
|
->setMethods(['findValidToken'])
|
|
->getMock();
|
|
|
|
$tokenValue = self::$DI['app']['random.low']->generateString(8);
|
|
|
|
$repo
|
|
->expects($this->once())
|
|
->method('findValidToken')
|
|
->with($tokenValue)
|
|
->will($this->returnValue(null));
|
|
|
|
$constraint = new PasswordToken($repo);
|
|
$this->assertFalse($constraint->isValid($tokenValue));
|
|
}
|
|
|
|
public function testValidTokenIsValid()
|
|
{
|
|
$repo = $this
|
|
->getMockBuilder('Doctrine\ORM\EntityRepository')
|
|
->disableOriginalConstructor()
|
|
->setMethods(['findValidToken'])
|
|
->getMock();
|
|
|
|
$tokenValue = self::$DI['app']['random.low']->generateString(8);
|
|
$token = new Token();
|
|
$token->setType(TokenManipulator::TYPE_PASSWORD);
|
|
|
|
$repo
|
|
->expects($this->once())
|
|
->method('findValidToken')
|
|
->with($tokenValue)
|
|
->will($this->returnValue($token));
|
|
|
|
$constraint = new PasswordToken($repo);
|
|
$this->assertTrue($constraint->isValid($tokenValue));
|
|
}
|
|
}
|