szurubooru/tests/AbstractDatabaseTestCase.php

70 lines
2 KiB
PHP
Raw Normal View History

<?php
namespace Szurubooru\Tests;
use Szurubooru\Dao\PublicFileDao;
use Szurubooru\DatabaseConnection;
use Szurubooru\Entities\Post;
use Szurubooru\Entities\User;
use Szurubooru\Helpers\HttpHelper;
use Szurubooru\Injector;
use Szurubooru\Services\UpgradeService;
use Szurubooru\Tests\AbstractTestCase;
use Szurubooru\Upgrades\UpgradeRepository;
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();
$config = $this->mockConfig($this->createTestDirectory());
$config->set('database/dsn', 'sqlite::memory:');
2014-09-28 16:26:44 +02:00
$config->set('database/user', '');
$config->set('database/password', '');
2014-09-14 16:16:15 +02:00
$this->databaseConnection = new DatabaseConnection($config);
Injector::set(DatabaseConnection::class, $this->databaseConnection);
Injector::set(PublicFileDao::class, $this->preparePublicFileDao());
2014-09-14 16:16:15 +02:00
$upgradeRepository = Injector::get(UpgradeRepository::class);
$upgradeService = new UpgradeService($config, $this->databaseConnection, $upgradeRepository);
2014-09-14 16:16:15 +02:00
$upgradeService->runUpgradesQuiet();
}
public function tearDown()
{
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;
}
private function preparePublicFileDao()
{
$testDirectory = $this->createTestDirectory();
$configMock = $this->mockConfig(null, $testDirectory);
return new PublicFileDao($configMock);
}
}