2014-09-26 20:41:28 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Tests\Dao;
|
2014-10-08 14:47:47 +02:00
|
|
|
use Szurubooru\Dao\SnapshotDao;
|
|
|
|
use Szurubooru\Dao\UserDao;
|
|
|
|
use Szurubooru\Entities\Snapshot;
|
|
|
|
use Szurubooru\Entities\User;
|
2015-11-25 11:39:32 +01:00
|
|
|
use Szurubooru\Injector;
|
2014-10-08 14:47:47 +02:00
|
|
|
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
2014-09-26 20:41:28 +02:00
|
|
|
|
2014-10-08 14:47:47 +02:00
|
|
|
final class SnapshotDaoTest extends AbstractDatabaseTestCase
|
2014-09-26 20:41:28 +02:00
|
|
|
{
|
2015-11-25 09:48:03 +01:00
|
|
|
public function testSaving()
|
|
|
|
{
|
2015-11-25 11:39:32 +01:00
|
|
|
$snapshotDao = Injector::get(SnapshotDao::class);
|
|
|
|
|
2015-11-25 09:48:03 +01:00
|
|
|
$snapshot = $this->getTestSnapshot();
|
|
|
|
$snapshotDao->save($snapshot);
|
2015-11-25 11:39:32 +01:00
|
|
|
|
2015-11-25 09:48:03 +01:00
|
|
|
$this->assertNotNull($snapshot->getId());
|
|
|
|
$this->assertEntitiesEqual($snapshot, $snapshotDao->findById($snapshot->getId()));
|
|
|
|
}
|
2014-09-26 20:41:28 +02:00
|
|
|
|
2015-11-25 09:48:03 +01:00
|
|
|
public function testUserLazyLoader()
|
|
|
|
{
|
2015-11-25 11:39:32 +01:00
|
|
|
$userDao = Injector::get(UserDao::class);
|
|
|
|
$snapshotDao = Injector::get(SnapshotDao::class);
|
|
|
|
|
|
|
|
$user = self::getTestUser('victoria');
|
|
|
|
$userDao->save($user);
|
|
|
|
|
2015-11-25 09:48:03 +01:00
|
|
|
$snapshot = $this->getTestSnapshot();
|
2015-11-25 11:39:32 +01:00
|
|
|
$snapshot->setUser($user);
|
2015-11-25 09:48:03 +01:00
|
|
|
$snapshotDao->save($snapshot);
|
2014-09-26 20:41:28 +02:00
|
|
|
|
2015-11-25 11:39:32 +01:00
|
|
|
$savedSnapshot = $snapshotDao->findById($snapshot->getId());
|
|
|
|
$this->assertNotNull($savedSnapshot->getUserId());
|
|
|
|
$this->assertEntitiesEqual($user, $savedSnapshot->getUser());
|
|
|
|
}
|
2014-09-26 20:41:28 +02:00
|
|
|
|
2015-11-25 09:48:03 +01:00
|
|
|
private function getTestSnapshot()
|
|
|
|
{
|
|
|
|
$snapshot = new Snapshot();
|
|
|
|
$snapshot->setType(Snapshot::TYPE_POST);
|
|
|
|
$snapshot->setData(['wake up', 'neo', ['follow' => 'white rabbit']]);
|
|
|
|
$snapshot->setPrimaryKey(1);
|
|
|
|
$snapshot->setTime(date('c', mktime(1, 2, 3)));
|
|
|
|
$snapshot->setUserId(null);
|
|
|
|
$snapshot->setOperation(Snapshot::OPERATION_CHANGE);
|
|
|
|
return $snapshot;
|
|
|
|
}
|
2014-09-26 20:41:28 +02:00
|
|
|
}
|