szurubooru/tests/AbstractDatabaseTestCase.php

60 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace Szurubooru\Tests;
use Szurubooru\Config;
use Szurubooru\Dao\PublicFileDao;
use Szurubooru\DatabaseConnection;
use Szurubooru\Entities\Post;
use Szurubooru\Entities\User;
use Szurubooru\Injector;
use Szurubooru\Tests\AbstractTestCase;
abstract class AbstractDatabaseTestCase extends AbstractTestCase
{
2014-08-30 17:10:45 +02:00
protected $databaseConnection;
public function setUp()
{
2014-09-14 16:16:15 +02:00
parent::setUp();
$realConfig = Injector::get(Config::class);
2014-09-14 16:16:15 +02:00
$config = $this->mockConfig($this->createTestDirectory());
$config->set('database/dsn', $realConfig->database->tests->dsn);
$config->set('database/user', $realConfig->database->tests->user);
$config->set('database/password', $realConfig->database->tests->password);
2014-09-14 16:16:15 +02:00
$this->databaseConnection = new DatabaseConnection($config);
$this->databaseConnection->getPDO()->exec('USE szuru_test');
$this->databaseConnection->getPDO()->beginTransaction();
Injector::set(DatabaseConnection::class, $this->databaseConnection);
}
public function tearDown()
{
$this->databaseConnection->getPDO()->rollBack();
2014-09-14 16:16:15 +02:00
parent::tearDown();
if ($this->databaseConnection)
$this->databaseConnection->close();
}
2014-10-04 12:06:50 +02:00
protected static function getTestPost()
{
$post = new Post();
2014-10-04 12:06:50 +02:00
$post->setName('test');
$post->setUploadTime(date('c'));
$post->setSafety(Post::POST_SAFETY_SAFE);
$post->setContentType(Post::POST_TYPE_YOUTUBE);
2014-10-04 12:06:50 +02:00
$post->setContentChecksum('whatever');
return $post;
}
protected static function getTestUser($userName = 'test')
{
$user = new User();
2014-10-04 12:06:50 +02:00
$user->setName($userName);
$user->setPasswordHash('whatever');
$user->setLastLoginTime(date('c', mktime(1, 2, 3)));
$user->setRegistrationTime(date('c', mktime(3, 2, 1)));
$user->setAccessRank(User::ACCESS_RANK_REGULAR_USER);
2014-10-04 12:06:50 +02:00
return $user;
}
}