2014-08-28 10:45:55 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Tests;
|
2014-11-09 12:29:20 +01:00
|
|
|
use Szurubooru\Config;
|
2014-10-08 19:39:20 +02:00
|
|
|
use Szurubooru\Dao\PublicFileDao;
|
2014-10-08 14:47:47 +02:00
|
|
|
use Szurubooru\DatabaseConnection;
|
|
|
|
use Szurubooru\Entities\Post;
|
2014-11-10 11:56:30 +01:00
|
|
|
use Szurubooru\Entities\Tag;
|
2014-10-08 14:47:47 +02:00
|
|
|
use Szurubooru\Entities\User;
|
|
|
|
use Szurubooru\Injector;
|
|
|
|
use Szurubooru\Tests\AbstractTestCase;
|
2014-08-28 10:45:55 +02:00
|
|
|
|
2014-10-08 14:47:47 +02:00
|
|
|
abstract class AbstractDatabaseTestCase extends AbstractTestCase
|
2014-08-28 10:45:55 +02:00
|
|
|
{
|
2015-11-25 09:48:03 +01:00
|
|
|
protected $databaseConnection;
|
2014-08-28 10:45:55 +02:00
|
|
|
|
2015-11-25 09:48:03 +01:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$realConfig = Injector::get(Config::class);
|
|
|
|
$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
|
|
|
|
2015-11-25 09:48:03 +01:00
|
|
|
$this->databaseConnection = new DatabaseConnection($config);
|
|
|
|
$this->databaseConnection->getPDO()->exec('USE szuru_test');
|
|
|
|
$this->databaseConnection->getPDO()->beginTransaction();
|
|
|
|
Injector::set(DatabaseConnection::class, $this->databaseConnection);
|
|
|
|
}
|
2014-08-28 10:45:55 +02:00
|
|
|
|
2015-11-25 09:48:03 +01:00
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
$this->databaseConnection->getPDO()->rollBack();
|
|
|
|
parent::tearDown();
|
|
|
|
if ($this->databaseConnection)
|
|
|
|
$this->databaseConnection->close();
|
|
|
|
}
|
2014-10-04 12:06:50 +02:00
|
|
|
|
2015-11-25 09:48:03 +01:00
|
|
|
protected static function getTestTag($name = 'test')
|
|
|
|
{
|
|
|
|
$tag = new Tag();
|
|
|
|
$tag->setName($name);
|
|
|
|
$tag->setCreationTime(date('c'));
|
|
|
|
return $tag;
|
|
|
|
}
|
2014-11-10 11:56:30 +01:00
|
|
|
|
2015-11-25 09:48:03 +01:00
|
|
|
protected static function getTestPost()
|
|
|
|
{
|
|
|
|
$post = new Post();
|
|
|
|
$post->setName('test');
|
|
|
|
$post->setUploadTime(date('c'));
|
|
|
|
$post->setSafety(Post::POST_SAFETY_SAFE);
|
|
|
|
$post->setContentType(Post::POST_TYPE_YOUTUBE);
|
|
|
|
$post->setContentChecksum('whatever');
|
|
|
|
return $post;
|
|
|
|
}
|
2014-10-04 12:06:50 +02:00
|
|
|
|
2015-11-25 09:48:03 +01:00
|
|
|
protected static function getTestUser($userName = 'test')
|
|
|
|
{
|
|
|
|
$user = new User();
|
|
|
|
$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);
|
|
|
|
return $user;
|
|
|
|
}
|
2014-08-28 10:45:55 +02:00
|
|
|
}
|