szuru/tests/Dao/TokenDaoTest.php

50 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2014-08-31 17:42:48 +02:00
<?php
namespace Szurubooru\Tests\Dao;
use Szurubooru\Dao\TokenDao;
use Szurubooru\Entities\Token;
use Szurubooru\Tests\AbstractDatabaseTestCase;
2014-08-31 17:42:48 +02:00
final class TokenDaoTest extends AbstractDatabaseTestCase
2014-08-31 17:42:48 +02:00
{
2015-11-25 09:48:03 +01:00
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);
}
2014-08-31 17:42:48 +02:00
}