2014-08-31 17:42:48 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Tests\Dao;
|
|
|
|
|
2014-09-01 20:51:59 +02:00
|
|
|
final class TokenDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
2014-08-31 17:42:48 +02:00
|
|
|
{
|
|
|
|
public function testRetrievingByValidName()
|
|
|
|
{
|
|
|
|
$token = new \Szurubooru\Entities\Token();
|
2014-09-13 23:58:13 +02:00
|
|
|
$token->setName('test');
|
2014-09-14 16:16:15 +02:00
|
|
|
$token->setPurpose(\Szurubooru\Entities\Token::PURPOSE_LOGIN);
|
2014-08-31 17:42:48 +02:00
|
|
|
|
2014-09-30 10:35:55 +02:00
|
|
|
$tokenDao = $this->getTokenDao();
|
2014-08-31 17:42:48 +02:00
|
|
|
$tokenDao->save($token);
|
|
|
|
$expected = $token;
|
2014-09-13 23:58:13 +02:00
|
|
|
$actual = $tokenDao->findByName($token->getName());
|
2014-08-31 17:42:48 +02:00
|
|
|
|
2014-09-21 09:35:43 +02:00
|
|
|
$this->assertEntitiesEqual($actual, $expected);
|
2014-08-31 17:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRetrievingByInvalidName()
|
|
|
|
{
|
2014-09-30 10:35:55 +02:00
|
|
|
$tokenDao = $this->getTokenDao();
|
2014-09-13 23:58:13 +02:00
|
|
|
$actual = $tokenDao->findByName('rubbish');
|
2014-08-31 17:42:48 +02:00
|
|
|
|
|
|
|
$this->assertNull($actual);
|
|
|
|
}
|
2014-09-30 10:35:55 +02:00
|
|
|
|
|
|
|
public function testRetrievingByAdditionalDataAndPurpose()
|
|
|
|
{
|
|
|
|
$token = new \Szurubooru\Entities\Token();
|
|
|
|
$token->setName('test');
|
|
|
|
$token->setPurpose(\Szurubooru\Entities\Token::PURPOSE_LOGIN);
|
|
|
|
|
|
|
|
$tokenDao = $this->getTokenDao();
|
|
|
|
$tokenDao->save($token);
|
|
|
|
$expected = $token;
|
|
|
|
|
|
|
|
$this->assertEntitiesEqual($expected, $tokenDao->findByAdditionalDataAndPurpose(null, \Szurubooru\Entities\Token::PURPOSE_LOGIN));
|
|
|
|
$this->assertNull($tokenDao->findByAdditionalDataAndPurpose(null, \Szurubooru\Entities\Token::PURPOSE_ACTIVATE));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getTokenDao()
|
|
|
|
{
|
|
|
|
return new \Szurubooru\Dao\TokenDao($this->databaseConnection);
|
|
|
|
}
|
2014-08-31 17:42:48 +02:00
|
|
|
}
|