2014-10-04 12:06:50 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Tests\Dao;
|
2014-10-08 14:47:47 +02:00
|
|
|
use Szurubooru\Dao\CommentDao;
|
|
|
|
use Szurubooru\Dao\PostDao;
|
|
|
|
use Szurubooru\Dao\UserDao;
|
|
|
|
use Szurubooru\Entities\Comment;
|
|
|
|
use Szurubooru\Entities\Post;
|
|
|
|
use Szurubooru\Entities\User;
|
|
|
|
use Szurubooru\Injector;
|
|
|
|
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
|
|
|
|
|
|
|
final class CommentDaoTest extends AbstractDatabaseTestCase
|
2014-10-04 12:06:50 +02:00
|
|
|
{
|
2015-11-25 09:48:03 +01:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSaving()
|
|
|
|
{
|
2015-11-25 11:39:32 +01:00
|
|
|
$userDao = Injector::get(UserDao::class);
|
|
|
|
$postDao = Injector::get(PostDao::class);
|
|
|
|
$commentDao = Injector::get(CommentDao::class);
|
2015-11-25 09:48:03 +01:00
|
|
|
|
2015-11-25 11:39:32 +01:00
|
|
|
$user = self::getTestUser('olivia');
|
|
|
|
$userDao->save($user);
|
|
|
|
|
|
|
|
$post = self::getTestPost();
|
|
|
|
$postDao->save($post);
|
2015-11-25 09:48:03 +01:00
|
|
|
|
|
|
|
$comment = new Comment();
|
|
|
|
$comment->setUser($user);
|
|
|
|
$comment->setPost($post);
|
|
|
|
$comment->setCreationTime(date('c'));
|
|
|
|
$comment->setLastEditTime(date('c'));
|
|
|
|
$comment->setText('whatever');
|
|
|
|
$commentDao->save($comment);
|
|
|
|
|
|
|
|
$savedComment = $commentDao->findById($comment->getId());
|
2015-11-25 11:39:32 +01:00
|
|
|
$this->assertNotNull($savedComment->getUserId());
|
|
|
|
$this->assertNotNull($savedComment->getPostId());
|
2015-11-25 09:48:03 +01:00
|
|
|
$this->assertEquals($comment->getCreationTime(), $savedComment->getCreationTime());
|
|
|
|
$this->assertEquals($comment->getLastEditTime(), $savedComment->getLastEditTime());
|
|
|
|
$this->assertEquals($comment->getText(), $savedComment->getText());
|
|
|
|
$this->assertEntitiesEqual($user, $savedComment->getUser());
|
|
|
|
$this->assertEntitiesEqual($post, $savedComment->getPost());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPostMetadataSyncInsert()
|
|
|
|
{
|
|
|
|
$userDao = Injector::get(UserDao::class);
|
|
|
|
$postDao = Injector::get(PostDao::class);
|
|
|
|
$commentDao = Injector::get(CommentDao::class);
|
|
|
|
|
|
|
|
$user = self::getTestUser('olivia');
|
|
|
|
$userDao->save($user);
|
|
|
|
|
|
|
|
$post = self::getTestPost();
|
|
|
|
$postDao->save($post);
|
|
|
|
|
|
|
|
$this->assertEquals(0, $post->getCommentCount());
|
|
|
|
$this->assertNotNull($post->getId());
|
|
|
|
|
|
|
|
$comment = new Comment();
|
|
|
|
$comment->setUser($user);
|
|
|
|
$comment->setPost($post);
|
|
|
|
$comment->setCreationTime(date('c'));
|
|
|
|
$comment->setLastEditTime(date('c'));
|
|
|
|
$comment->setText('whatever');
|
|
|
|
$commentDao->save($comment);
|
|
|
|
|
|
|
|
$post = $postDao->findById($post->getId());
|
|
|
|
$this->assertNotNull($post);
|
|
|
|
$this->assertEquals(1, $post->getCommentCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPostMetadataSyncDelete()
|
|
|
|
{
|
|
|
|
$userDao = Injector::get(UserDao::class);
|
|
|
|
$postDao = Injector::get(PostDao::class);
|
|
|
|
$commentDao = Injector::get(CommentDao::class);
|
|
|
|
|
|
|
|
$user = self::getTestUser('olivia');
|
|
|
|
$userDao->save($user);
|
|
|
|
|
|
|
|
$post = self::getTestPost();
|
|
|
|
$postDao->save($post);
|
|
|
|
|
|
|
|
$this->assertEquals(0, $post->getCommentCount());
|
|
|
|
$this->assertNotNull($post->getId());
|
|
|
|
|
|
|
|
$comment = new Comment();
|
|
|
|
$comment->setUser($user);
|
|
|
|
$comment->setPost($post);
|
|
|
|
$comment->setCreationTime(date('c'));
|
|
|
|
$comment->setLastEditTime(date('c'));
|
|
|
|
$comment->setText('whatever');
|
|
|
|
$commentDao->save($comment);
|
|
|
|
|
|
|
|
$commentDao->deleteById($comment->getId());
|
|
|
|
|
|
|
|
$this->assertNotNull($post->getId());
|
|
|
|
$post = $postDao->findById($post->getId());
|
|
|
|
$this->assertNotNull($post);
|
|
|
|
$this->assertEquals(0, $post->getCommentCount());
|
|
|
|
}
|
2014-10-04 12:06:50 +02:00
|
|
|
}
|