szurubooru/tests/Dao/TokenDaoTest.php
Marcin Kurczewski 632bac8661 Added "use ..." statements
This version ditches backwards compatibility with PHP earlier than 5.6.
2014-10-18 18:48:36 +02:00

49 lines
1.2 KiB
PHP

<?php
namespace Szurubooru\Tests\Dao;
use Szurubooru\Dao\TokenDao;
use Szurubooru\Entities\Token;
use Szurubooru\Tests\AbstractDatabaseTestCase;
final class TokenDaoTest extends AbstractDatabaseTestCase
{
public function testRetrievingByValidName()
{
$token = new Token();
$token->setName('test');
$token->setPurpose(Token::PURPOSE_LOGIN);
$tokenDao = $this->getTokenDao();
$tokenDao->save($token);
$expected = $token;
$actual = $tokenDao->findByName($token->getName());
$this->assertEntitiesEqual($actual, $expected);
}
public function testRetrievingByInvalidName()
{
$tokenDao = $this->getTokenDao();
$actual = $tokenDao->findByName('rubbish');
$this->assertNull($actual);
}
public function testRetrievingByAdditionalDataAndPurpose()
{
$token = new Token();
$token->setName('test');
$token->setPurpose(Token::PURPOSE_LOGIN);
$tokenDao = $this->getTokenDao();
$tokenDao->save($token);
$expected = $token;
$this->assertEntitiesEqual($expected, $tokenDao->findByAdditionalDataAndPurpose(null, Token::PURPOSE_LOGIN));
$this->assertNull($tokenDao->findByAdditionalDataAndPurpose(null, Token::PURPOSE_ACTIVATE));
}
private function getTokenDao()
{
return new TokenDao($this->databaseConnection);
}
}