2014-09-01 20:51:59 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Tests\Dao;
|
|
|
|
|
|
|
|
final class UserDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
|
|
|
{
|
|
|
|
public function testRetrievingByValidName()
|
|
|
|
{
|
2014-09-03 19:07:53 +02:00
|
|
|
$userDao = $this->getUserDao();
|
2014-09-01 20:51:59 +02:00
|
|
|
|
2014-09-14 16:16:15 +02:00
|
|
|
$user = $this->getTestUser();
|
2014-09-01 20:51:59 +02:00
|
|
|
$userDao->save($user);
|
2014-09-14 16:16:15 +02:00
|
|
|
|
2014-09-01 20:51:59 +02:00
|
|
|
$expected = $user;
|
2014-09-13 23:58:13 +02:00
|
|
|
$actual = $userDao->findByName($user->getName());
|
2014-09-01 20:51:59 +02:00
|
|
|
$this->assertEquals($actual, $expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRetrievingByInvalidName()
|
|
|
|
{
|
2014-09-03 19:07:53 +02:00
|
|
|
$userDao = $this->getUserDao();
|
2014-09-01 20:51:59 +02:00
|
|
|
|
2014-09-13 23:58:13 +02:00
|
|
|
$actual = $userDao->findByName('rubbish');
|
2014-09-01 20:51:59 +02:00
|
|
|
|
|
|
|
$this->assertNull($actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCheckingUserPresence()
|
|
|
|
{
|
2014-09-03 19:07:53 +02:00
|
|
|
$userDao = $this->getUserDao();
|
2014-09-01 20:51:59 +02:00
|
|
|
$this->assertFalse($userDao->hasAnyUsers());
|
|
|
|
|
2014-09-14 16:16:15 +02:00
|
|
|
$user = $this->getTestUser();
|
2014-09-01 20:51:59 +02:00
|
|
|
$userDao->save($user);
|
|
|
|
$this->assertTrue($userDao->hasAnyUsers());
|
|
|
|
}
|
2014-09-03 19:07:53 +02:00
|
|
|
|
|
|
|
private function getUserDao()
|
|
|
|
{
|
|
|
|
return new \Szurubooru\Dao\UserDao($this->databaseConnection);
|
|
|
|
}
|
2014-09-14 16:16:15 +02:00
|
|
|
|
|
|
|
private function getTestUser()
|
|
|
|
{
|
|
|
|
$user = new \Szurubooru\Entities\User();
|
|
|
|
$user->setName('test');
|
|
|
|
$user->setPasswordHash('whatever');
|
|
|
|
$user->setLastLoginTime('whatever');
|
|
|
|
$user->setRegistrationTime('whatever');
|
2014-09-16 11:16:48 +02:00
|
|
|
$user->setAccessRank(\Szurubooru\Entities\User::ACCESS_RANK_REGULAR_USER);
|
2014-09-14 16:16:15 +02:00
|
|
|
return $user;
|
|
|
|
}
|
2014-09-01 20:51:59 +02:00
|
|
|
}
|