Files
Phraseanet/tests/Alchemy/Tests/Phrasea/Form/Constraint/PasswordTokenTest.php
Nicolas Le Goff e317f86c51 Fix CS
2014-03-23 23:07:01 +01:00

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