Fixed tests
This commit is contained in:
parent
ee09a09833
commit
ecb3901bbe
12 changed files with 208 additions and 240 deletions
|
@ -23,7 +23,7 @@ maxCustomThumbnailSize = 1048576 ;1mb
|
|||
|
||||
[database.tests]
|
||||
dsn = mysql:host=localhost
|
||||
user = szuru_test
|
||||
user = szuru-test
|
||||
password = cat
|
||||
|
||||
[security]
|
||||
|
|
|
@ -41,6 +41,7 @@ abstract class AbstractDatabaseTestCase extends AbstractTestCase
|
|||
$tag = new Tag();
|
||||
$tag->setName($name);
|
||||
$tag->setCreationTime(date('c'));
|
||||
$tag->setLastEditTime(date('c'));
|
||||
return $tag;
|
||||
}
|
||||
|
||||
|
@ -48,7 +49,8 @@ abstract class AbstractDatabaseTestCase extends AbstractTestCase
|
|||
{
|
||||
$post = new Post();
|
||||
$post->setName('test');
|
||||
$post->setUploadTime(date('c'));
|
||||
$post->setCreationTime(date('c'));
|
||||
$post->setLastEditTime(date('c'));
|
||||
$post->setSafety(Post::POST_SAFETY_SAFE);
|
||||
$post->setContentType(Post::POST_TYPE_YOUTUBE);
|
||||
$post->setContentChecksum('whatever');
|
||||
|
@ -61,7 +63,7 @@ abstract class AbstractDatabaseTestCase extends AbstractTestCase
|
|||
$user->setName($userName);
|
||||
$user->setPasswordHash('whatever');
|
||||
$user->setLastLoginTime(date('c', mktime(1, 2, 3)));
|
||||
$user->setRegistrationTime(date('c', mktime(3, 2, 1)));
|
||||
$user->setCreationTime(date('c', mktime(3, 2, 1)));
|
||||
$user->setAccessRank(User::ACCESS_RANK_REGULAR_USER);
|
||||
return $user;
|
||||
}
|
||||
|
|
|
@ -11,23 +11,22 @@ use Szurubooru\Tests\AbstractDatabaseTestCase;
|
|||
|
||||
final class CommentDaoTest extends AbstractDatabaseTestCase
|
||||
{
|
||||
private $userDaoMock;
|
||||
private $postDaoMock;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->userDaoMock = $this->mock(UserDao::class);
|
||||
$this->postDaoMock = $this->mock(PostDao::class);
|
||||
}
|
||||
|
||||
public function testSaving()
|
||||
{
|
||||
$user = new User(1);
|
||||
$user->setName('olivia');
|
||||
$userDao = Injector::get(UserDao::class);
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
$commentDao = Injector::get(CommentDao::class);
|
||||
|
||||
$post = new Post(2);
|
||||
$post->setName('sword');
|
||||
$user = self::getTestUser('olivia');
|
||||
$userDao->save($user);
|
||||
|
||||
$post = self::getTestPost();
|
||||
$postDao->save($post);
|
||||
|
||||
$comment = new Comment();
|
||||
$comment->setUser($user);
|
||||
|
@ -35,15 +34,11 @@ final class CommentDaoTest extends AbstractDatabaseTestCase
|
|||
$comment->setCreationTime(date('c'));
|
||||
$comment->setLastEditTime(date('c'));
|
||||
$comment->setText('whatever');
|
||||
$commentDao = $this->getCommentDao();
|
||||
$commentDao->save($comment);
|
||||
|
||||
$this->userDaoMock->expects($this->once())->method('findById')->with(1)->willReturn($user);
|
||||
$this->postDaoMock->expects($this->once())->method('findById')->with(2)->willReturn($post);
|
||||
|
||||
$savedComment = $commentDao->findById($comment->getId());
|
||||
$this->assertEquals(1, $savedComment->getUserId());
|
||||
$this->assertEquals(2, $savedComment->getPostId());
|
||||
$this->assertNotNull($savedComment->getUserId());
|
||||
$this->assertNotNull($savedComment->getPostId());
|
||||
$this->assertEquals($comment->getCreationTime(), $savedComment->getCreationTime());
|
||||
$this->assertEquals($comment->getLastEditTime(), $savedComment->getLastEditTime());
|
||||
$this->assertEquals($comment->getText(), $savedComment->getText());
|
||||
|
@ -109,17 +104,4 @@ final class CommentDaoTest extends AbstractDatabaseTestCase
|
|||
$this->assertNotNull($post);
|
||||
$this->assertEquals(0, $post->getCommentCount());
|
||||
}
|
||||
|
||||
public function findByPost(Post $post)
|
||||
{
|
||||
return $this->findOneBy('postId', $post->getId());
|
||||
}
|
||||
|
||||
private function getCommentDao()
|
||||
{
|
||||
return new CommentDao(
|
||||
$this->databaseConnection,
|
||||
$this->userDaoMock,
|
||||
$this->postDaoMock);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,49 +1,42 @@
|
|||
<?php
|
||||
namespace Szurubooru\Tests\Dao;
|
||||
use Szurubooru\Dao\FavoritesDao;
|
||||
use Szurubooru\Dao\PostDao;
|
||||
use Szurubooru\Dao\UserDao;
|
||||
use Szurubooru\Entities\Favorite;
|
||||
use Szurubooru\Entities\Post;
|
||||
use Szurubooru\Entities\User;
|
||||
use Szurubooru\Injector;
|
||||
use Szurubooru\Services\TimeService;
|
||||
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
||||
|
||||
final class FavoritesDaoTest extends AbstractDatabaseTestCase
|
||||
{
|
||||
private $timeServiceMock;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->timeServiceMock = $this->mock(TimeService::class);
|
||||
}
|
||||
|
||||
public function testSaving()
|
||||
{
|
||||
$user = new User(1);
|
||||
$user->setName('olivia');
|
||||
$userDao = Injector::get(UserDao::class);
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
$timeServiceMock = $this->mock(TimeService::class);
|
||||
$favoritesDao = new FavoritesDao(
|
||||
$this->databaseConnection, $userDao, $postDao, $timeServiceMock);
|
||||
|
||||
$post = new Post(2);
|
||||
$post->setName('sword');
|
||||
$user = self::getTestUser('olivia');
|
||||
$userDao->save($user);
|
||||
|
||||
$post = self::getTestPost();
|
||||
$postDao->save($post);
|
||||
|
||||
$favorite = new Favorite();
|
||||
$favorite->setUserId($user->getId());
|
||||
$favorite->setPostId($post->getId());
|
||||
$favorite->setTime(date('c'));
|
||||
$favoritesDao = $this->getFavoritesDao();
|
||||
$favoritesDao->save($favorite);
|
||||
|
||||
$savedFavorite = $favoritesDao->findById($favorite->getId());
|
||||
$this->assertEquals(1, $savedFavorite->getUserId());
|
||||
$this->assertEquals(2, $savedFavorite->getPostId());
|
||||
$this->assertNotNull($savedFavorite->getUserId());
|
||||
$this->assertNotNull($savedFavorite->getPostId());
|
||||
$this->assertEquals($favorite->getTime(), $savedFavorite->getTime());
|
||||
$this->assertEquals($user->getId(), $savedFavorite->getUserId());
|
||||
$this->assertEquals($post->getId(), $savedFavorite->getPostId());
|
||||
}
|
||||
|
||||
private function getFavoritesDao()
|
||||
{
|
||||
return new FavoritesDao(
|
||||
$this->databaseConnection,
|
||||
$this->timeServiceMock);
|
||||
$this->assertEntitiesEqual($user, $savedFavorite->getUser());
|
||||
$this->assertEntitiesEqual($post, $savedFavorite->getPost());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use Szurubooru\Dao\TagDao;
|
|||
use Szurubooru\Dao\UserDao;
|
||||
use Szurubooru\Entities\Tag;
|
||||
use Szurubooru\Entities\User;
|
||||
use Szurubooru\Injector;
|
||||
use Szurubooru\Services\ThumbnailService;
|
||||
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
||||
|
||||
|
@ -19,20 +20,15 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
|||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->fileDaoMock = $this->mock(PublicFileDao::class);
|
||||
$this->thumbnailServiceMock = $this->mock(ThumbnailService::class);
|
||||
|
||||
$this->tagDao = new TagDao($this->databaseConnection);
|
||||
|
||||
$this->userDao = new UserDao(
|
||||
$this->databaseConnection,
|
||||
$this->fileDaoMock,
|
||||
$this->thumbnailServiceMock);
|
||||
$fileDaoMock = $this->mock(PublicFileDao::class);
|
||||
}
|
||||
|
||||
public function testCreating()
|
||||
{
|
||||
$postDao = $this->getPostDao();
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
|
||||
$post = self::getTestPost();
|
||||
$savedPost = $postDao->save($post);
|
||||
|
@ -42,7 +38,8 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
|||
|
||||
public function testUpdating()
|
||||
{
|
||||
$postDao = $this->getPostDao();
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
|
||||
$post = self::getTestPost();
|
||||
$post = $postDao->save($post);
|
||||
$this->assertEquals('test', $post->getName());
|
||||
|
@ -55,7 +52,7 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
|||
|
||||
public function testGettingAll()
|
||||
{
|
||||
$postDao = $this->getPostDao();
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
|
||||
$post1 = self::getTestPost();
|
||||
$post2 = self::getTestPost();
|
||||
|
@ -78,7 +75,7 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
|||
|
||||
public function testGettingTotalFileSize()
|
||||
{
|
||||
$postDao = $this->getPostDao();
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
|
||||
$post1 = self::getTestPost();
|
||||
$post2 = self::getTestPost();
|
||||
|
@ -99,7 +96,7 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
|||
|
||||
public function testGettingById()
|
||||
{
|
||||
$postDao = $this->getPostDao();
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
|
||||
$post1 = self::getTestPost();
|
||||
$post2 = self::getTestPost();
|
||||
|
@ -114,7 +111,7 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
|||
|
||||
public function testDeletingAll()
|
||||
{
|
||||
$postDao = $this->getPostDao();
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
|
||||
$post1 = self::getTestPost();
|
||||
$post2 = self::getTestPost();
|
||||
|
@ -132,7 +129,7 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
|||
|
||||
public function testDeletingById()
|
||||
{
|
||||
$postDao = $this->getPostDao();
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
|
||||
$post1 = self::getTestPost();
|
||||
$post2 = self::getTestPost();
|
||||
|
@ -150,16 +147,18 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
|||
|
||||
public function testFindingByTagName()
|
||||
{
|
||||
$tagDao = Injector::get(TagDao::class);
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
|
||||
$tag1 = new Tag();
|
||||
$tag1->setName('tag1');
|
||||
$tag1->setCreationTime(date('c'));
|
||||
$tag2 = new Tag();
|
||||
$tag2->setName('tag2');
|
||||
$tag2->setCreationTime(date('c'));
|
||||
$this->tagDao->save($tag1);
|
||||
$this->tagDao->save($tag2);
|
||||
$tagDao->save($tag1);
|
||||
$tagDao->save($tag2);
|
||||
|
||||
$postDao = $this->getPostDao();
|
||||
$post1 = self::getTestPost();
|
||||
$post1->setTags([$tag1]);
|
||||
$postDao->save($post1);
|
||||
|
@ -173,6 +172,9 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
|||
|
||||
public function testSavingTags()
|
||||
{
|
||||
$tagDao = Injector::get(TagDao::class);
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
|
||||
$tag1 = new Tag();
|
||||
$tag1->setName('tag1');
|
||||
$tag1->setCreationTime(date('c'));
|
||||
|
@ -183,7 +185,6 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
|||
$this->tagDao->save($tag2);
|
||||
$testTags = ['tag1' => $tag1, 'tag2' => $tag2];
|
||||
|
||||
$postDao = $this->getPostDao();
|
||||
$post = self::getTestPost();
|
||||
$post->setTags($testTags);
|
||||
$postDao->save($post);
|
||||
|
@ -195,17 +196,17 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
|||
$this->assertEquals(2, $post->getTagCount());
|
||||
$this->assertEquals(2, $savedPost->getTagCount());
|
||||
|
||||
$tagDao = $this->getTagDao();
|
||||
$this->assertEquals(2, count($tagDao->findAll()));
|
||||
}
|
||||
|
||||
public function testSavingUnsavedRelations()
|
||||
{
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
|
||||
$post1 = self::getTestPost();
|
||||
$post2 = self::getTestPost();
|
||||
$testPosts = [$post1, $post2];
|
||||
|
||||
$postDao = $this->getPostDao();
|
||||
$post = self::getTestPost();
|
||||
$post->setRelatedPosts($testPosts);
|
||||
$this->setExpectedException(\Exception::class, 'Unsaved entities found');
|
||||
|
@ -214,11 +215,12 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
|||
|
||||
public function testSavingRelations()
|
||||
{
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
|
||||
$post1 = self::getTestPost();
|
||||
$post2 = self::getTestPost();
|
||||
$testPosts = [$post1, $post2];
|
||||
|
||||
$postDao = $this->getPostDao();
|
||||
$postDao->save($post1);
|
||||
$postDao->save($post2);
|
||||
$post = self::getTestPost();
|
||||
|
@ -232,35 +234,45 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
|||
|
||||
public function testSavingUser()
|
||||
{
|
||||
$testUser = new User(5);
|
||||
$testUser->setName('it\'s me');
|
||||
$postDao = $this->getPostDao();
|
||||
$userDao = Injector::get(UserDao::class);
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
|
||||
$user = self::getTestUser('uploader');
|
||||
$userDao->save($user);
|
||||
|
||||
$post = self::getTestPost();
|
||||
$post->setUser($testUser);
|
||||
$post->setUser($user);
|
||||
$postDao->save($post);
|
||||
|
||||
$savedPost = $postDao->findById($post->getId());
|
||||
$this->assertEntitiesEqual($testUser, $post->getUser());
|
||||
$this->assertEquals(5, $post->getUserId());
|
||||
$this->assertNotNull($post->getUserId());
|
||||
$this->assertEntitiesEqual($user, $post->getUser());
|
||||
}
|
||||
|
||||
public function testNotLoadingContentForNewPosts()
|
||||
{
|
||||
$postDao = $this->getPostDao();
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
$newlyCreatedPost = self::getTestPost();
|
||||
$this->assertNull($newlyCreatedPost->getContent());
|
||||
}
|
||||
|
||||
public function testLoadingContentPostsForExistingPosts()
|
||||
{
|
||||
$postDao = $this->getPostDao();
|
||||
$thumbnailServiceMock = $this->mock(ThumbnailService::class);
|
||||
$fileDaoMock = $this->mock(PublicFileDao::class);
|
||||
|
||||
$tagDao = Injector::get(TagDao::class);
|
||||
$userDao = Injector::get(UserDao::class);
|
||||
$postDao = new PostDao(
|
||||
$this->databaseConnection,
|
||||
$tagDao, $userDao, $fileDaoMock, $thumbnailServiceMock);
|
||||
|
||||
$post = self::getTestPost();
|
||||
$postDao->save($post);
|
||||
|
||||
$post = $postDao->findById($post->getId());
|
||||
|
||||
$this->fileDaoMock
|
||||
$fileDaoMock
|
||||
->expects($this->once())
|
||||
->method('load')
|
||||
->with($post->getContentPath())
|
||||
|
@ -271,18 +283,26 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
|||
|
||||
public function testSavingContent()
|
||||
{
|
||||
$postDao = $this->getPostDao();
|
||||
$thumbnailServiceMock = $this->mock(ThumbnailService::class);
|
||||
$fileDaoMock = $this->mock(PublicFileDao::class);
|
||||
|
||||
$tagDao = Injector::get(TagDao::class);
|
||||
$userDao = Injector::get(UserDao::class);
|
||||
$postDao = new PostDao(
|
||||
$this->databaseConnection,
|
||||
$tagDao, $userDao, $fileDaoMock, $thumbnailServiceMock);
|
||||
|
||||
$post = self::getTestPost();
|
||||
$post->setContent('whatever');
|
||||
|
||||
$this->thumbnailServiceMock
|
||||
$thumbnailServiceMock
|
||||
->expects($this->exactly(2))
|
||||
->method('deleteUsedThumbnails')
|
||||
->withConsecutive(
|
||||
[$post->getContentPath()],
|
||||
[$post->getThumbnailSourceContentPath()]);
|
||||
|
||||
$this->fileDaoMock
|
||||
$fileDaoMock
|
||||
->expects($this->exactly(1))
|
||||
->method('save')
|
||||
->withConsecutive(
|
||||
|
@ -293,19 +313,27 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
|||
|
||||
public function testSavingContentAndThumbnail()
|
||||
{
|
||||
$postDao = $this->getPostDao();
|
||||
$thumbnailServiceMock = $this->mock(ThumbnailService::class);
|
||||
$fileDaoMock = $this->mock(PublicFileDao::class);
|
||||
|
||||
$tagDao = Injector::get(TagDao::class);
|
||||
$userDao = Injector::get(UserDao::class);
|
||||
$postDao = new PostDao(
|
||||
$this->databaseConnection,
|
||||
$tagDao, $userDao, $fileDaoMock, $thumbnailServiceMock);
|
||||
|
||||
$post = self::getTestPost();
|
||||
$post->setContent('whatever');
|
||||
$post->setThumbnailSourceContent('an image of sharks');
|
||||
|
||||
$this->thumbnailServiceMock
|
||||
$thumbnailServiceMock
|
||||
->expects($this->exactly(2))
|
||||
->method('deleteUsedThumbnails')
|
||||
->withConsecutive(
|
||||
[$post->getContentPath()],
|
||||
[$post->getThumbnailSourceContentPath()]);
|
||||
|
||||
$this->fileDaoMock
|
||||
$fileDaoMock
|
||||
->expects($this->exactly(2))
|
||||
->method('save')
|
||||
->withConsecutive(
|
||||
|
@ -314,20 +342,4 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
|||
|
||||
$postDao->save($post);
|
||||
}
|
||||
|
||||
|
||||
private function getPostDao()
|
||||
{
|
||||
return new PostDao(
|
||||
$this->databaseConnection,
|
||||
$this->tagDao,
|
||||
$this->userDao,
|
||||
$this->fileDaoMock,
|
||||
$this->thumbnailServiceMock);
|
||||
}
|
||||
|
||||
private function getTagDao()
|
||||
{
|
||||
return $this->tagDao;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,42 +3,32 @@ namespace Szurubooru\Tests\Dao;
|
|||
use Szurubooru\Dao\PostDao;
|
||||
use Szurubooru\Dao\PostNoteDao;
|
||||
use Szurubooru\Entities\PostNote;
|
||||
use Szurubooru\Injector;
|
||||
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
||||
|
||||
final class PostNoteDaoTest extends AbstractDatabaseTestCase
|
||||
{
|
||||
private $postDaoMock;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->postDaoMock = $this->mock(PostDao::class);
|
||||
}
|
||||
|
||||
public function testSettingValues()
|
||||
{
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
$postNoteDao = Injector::get(PostNoteDao::class);
|
||||
|
||||
$post = self::getTestPost();
|
||||
$postDao->save($post);
|
||||
|
||||
$expected = new PostNote();
|
||||
$expected->setPostId(5);
|
||||
$expected->setPost($post);
|
||||
$expected->setLeft(5);
|
||||
$expected->setTop(10);
|
||||
$expected->setWidth(50);
|
||||
$expected->setHeight(50);
|
||||
$expected->setText('text');
|
||||
|
||||
$postNoteDao = $this->getPostNoteDao();
|
||||
$postNoteDao->save($expected);
|
||||
|
||||
$actual = $postNoteDao->findById($expected->getId());
|
||||
$this->assertEntitiesEqual($actual, $expected);
|
||||
|
||||
$this->postDaoMock->expects($this->once())->method('findById')->with(5)->willReturn('lazy post');
|
||||
$this->assertEquals('lazy post', $actual->getPost());
|
||||
}
|
||||
|
||||
private function getPostNoteDao()
|
||||
{
|
||||
return new PostNoteDao(
|
||||
$this->databaseConnection,
|
||||
$this->postDaoMock);
|
||||
$this->assertNotNull($actual->getPostId());
|
||||
$this->assertEntitiesEqual($post, $actual->getPost());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,41 +1,38 @@
|
|||
<?php
|
||||
namespace Szurubooru\Tests\Dao;
|
||||
use Szurubooru\Dao\PostDao;
|
||||
use Szurubooru\Dao\ScoreDao;
|
||||
use Szurubooru\Dao\UserDao;
|
||||
use Szurubooru\Entities\Post;
|
||||
use Szurubooru\Entities\Score;
|
||||
use Szurubooru\Entities\User;
|
||||
use Szurubooru\Services\TimeService;
|
||||
use Szurubooru\Injector;
|
||||
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
||||
|
||||
final class ScoreDaoTest extends AbstractDatabaseTestCase
|
||||
{
|
||||
private $timeServiceMock;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->timeServiceMock = $this->mock(TimeService::class);
|
||||
}
|
||||
|
||||
public function testSaving()
|
||||
{
|
||||
$user = new User(1);
|
||||
$user->setName('olivia');
|
||||
$userDao = Injector::get(UserDao::class);
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
$scoreDao = Injector::get(ScoreDao::class);
|
||||
|
||||
$post = new Post(2);
|
||||
$post->setName('sword');
|
||||
$user = self::getTestUser('olivia');
|
||||
$userDao->save($user);
|
||||
|
||||
$post = self::getTestPost();
|
||||
$postDao->save($post);
|
||||
|
||||
$score = new Score();
|
||||
$score->setUserId($user->getId());
|
||||
$score->setPostId($post->getId());
|
||||
$score->setTime(date('c'));
|
||||
$score->setScore(1);
|
||||
$scoreDao = $this->getScoreDao();
|
||||
$scoreDao->save($score);
|
||||
|
||||
$savedScore = $scoreDao->findById($score->getId());
|
||||
$this->assertEquals(1, $savedScore->getUserId());
|
||||
$this->assertEquals(2, $savedScore->getPostId());
|
||||
$this->assertNotNull($savedScore->getUserId());
|
||||
$this->assertNotNull($savedScore->getPostId());
|
||||
$this->assertEquals($score->getTime(), $savedScore->getTime());
|
||||
$this->assertEquals($user->getId(), $savedScore->getUserId());
|
||||
$this->assertEquals($post->getId(), $savedScore->getPostId());
|
||||
|
@ -43,14 +40,23 @@ final class ScoreDaoTest extends AbstractDatabaseTestCase
|
|||
|
||||
public function testFindingByUserAndPost()
|
||||
{
|
||||
$post1 = new Post(1);
|
||||
$post2 = new Post(2);
|
||||
$user1 = new User(3);
|
||||
$user2 = new User(4);
|
||||
$userDao = Injector::get(UserDao::class);
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
$scoreDao = Injector::get(ScoreDao::class);
|
||||
|
||||
$user1 = self::getTestUser('olivia');
|
||||
$user2 = self::getTestUser('victoria');
|
||||
$userDao->save($user1);
|
||||
$userDao->save($user2);
|
||||
|
||||
$post1 = self::getTestPost();
|
||||
$post2 = self::getTestPost();
|
||||
$postDao->save($post1);
|
||||
$postDao->save($post2);
|
||||
|
||||
$score1 = new Score();
|
||||
$score1->setUserId($user1->getId());
|
||||
$score1->setPostId($post1->getId());
|
||||
$score1->setPostId($post1->geTId());
|
||||
$score1->setTime(date('c', mktime(1)));
|
||||
$score1->setScore(1);
|
||||
|
||||
|
@ -66,7 +72,6 @@ final class ScoreDaoTest extends AbstractDatabaseTestCase
|
|||
$score3->setTime(date('c', mktime(3)));
|
||||
$score3->setScore(-1);
|
||||
|
||||
$scoreDao = $this->getScoreDao();
|
||||
$scoreDao->save($score1);
|
||||
$scoreDao->save($score2);
|
||||
$scoreDao->save($score3);
|
||||
|
@ -76,16 +81,4 @@ final class ScoreDaoTest extends AbstractDatabaseTestCase
|
|||
$this->assertEntitiesEqual($score3, $scoreDao->getUserScore($user1, $post2));
|
||||
$this->assertNull($scoreDao->getUserScore($user2, $post1));
|
||||
}
|
||||
|
||||
public function findByPost(Post $post)
|
||||
{
|
||||
return $this->findOneBy('postId', $post->getId());
|
||||
}
|
||||
|
||||
private function getScoreDao()
|
||||
{
|
||||
return new ScoreDao(
|
||||
$this->databaseConnection,
|
||||
$this->timeServiceMock);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,40 +4,38 @@ use Szurubooru\Dao\SnapshotDao;
|
|||
use Szurubooru\Dao\UserDao;
|
||||
use Szurubooru\Entities\Snapshot;
|
||||
use Szurubooru\Entities\User;
|
||||
use Szurubooru\Injector;
|
||||
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
||||
|
||||
final class SnapshotDaoTest extends AbstractDatabaseTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->userDaoMock = $this->mock(UserDao::class);
|
||||
}
|
||||
|
||||
public function testSaving()
|
||||
{
|
||||
$snapshotDao = Injector::get(SnapshotDao::class);
|
||||
|
||||
$snapshot = $this->getTestSnapshot();
|
||||
$snapshotDao = $this->getSnapshotDao();
|
||||
$snapshotDao->save($snapshot);
|
||||
|
||||
$this->assertNotNull($snapshot->getId());
|
||||
$this->assertEntitiesEqual($snapshot, $snapshotDao->findById($snapshot->getId()));
|
||||
}
|
||||
|
||||
public function testUserLazyLoader()
|
||||
{
|
||||
$snapshot = $this->getTestSnapshot();
|
||||
$snapshot->setUser(new User(5));
|
||||
$this->assertEquals(5, $snapshot->getUserId());
|
||||
$snapshotDao = $this->getSnapshotDao();
|
||||
$snapshotDao->save($snapshot);
|
||||
$savedSnapshot = $snapshotDao->findById($snapshot->getId());
|
||||
$this->assertEquals(5, $savedSnapshot->getUserId());
|
||||
$userDao = Injector::get(UserDao::class);
|
||||
$snapshotDao = Injector::get(SnapshotDao::class);
|
||||
|
||||
$this->userDaoMock
|
||||
->expects($this->once())
|
||||
->method('findById');
|
||||
$savedSnapshot->getUser();
|
||||
}
|
||||
$user = self::getTestUser('victoria');
|
||||
$userDao->save($user);
|
||||
|
||||
$snapshot = $this->getTestSnapshot();
|
||||
$snapshot->setUser($user);
|
||||
$snapshotDao->save($snapshot);
|
||||
|
||||
$savedSnapshot = $snapshotDao->findById($snapshot->getId());
|
||||
$this->assertNotNull($savedSnapshot->getUserId());
|
||||
$this->assertEntitiesEqual($user, $savedSnapshot->getUser());
|
||||
}
|
||||
|
||||
private function getTestSnapshot()
|
||||
{
|
||||
|
@ -50,11 +48,4 @@ final class SnapshotDaoTest extends AbstractDatabaseTestCase
|
|||
$snapshot->setOperation(Snapshot::OPERATION_CHANGE);
|
||||
return $snapshot;
|
||||
}
|
||||
|
||||
private function getSnapshotDao()
|
||||
{
|
||||
return new SnapshotDao(
|
||||
$this->databaseConnection,
|
||||
$this->userDaoMock);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,22 @@
|
|||
<?php
|
||||
namespace Szurubooru\Tests\Dao;
|
||||
use Szurubooru\Dao\PostDao;
|
||||
use Szurubooru\Dao\TagDao;
|
||||
use Szurubooru\Entities\Tag;
|
||||
use Szurubooru\Injector;
|
||||
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
||||
|
||||
final class TagDaoTest extends AbstractDatabaseTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testSaving()
|
||||
{
|
||||
$tagDao = Injector::get(TagDao::class);
|
||||
|
||||
$tag = self::getTestTag('test');
|
||||
$tag->setCreationTime(date('c', mktime(0, 0, 0, 10, 1, 2014)));
|
||||
$this->assertFalse($tag->isBanned());
|
||||
$tag->setBanned(true);
|
||||
|
||||
$tagDao = $this->getTagDao();
|
||||
$tagDao->save($tag);
|
||||
$actualTag = $tagDao->findById($tag->getId());
|
||||
$this->assertEntitiesEqual($tag, $actualTag);
|
||||
|
@ -26,11 +24,12 @@ final class TagDaoTest extends AbstractDatabaseTestCase
|
|||
|
||||
public function testSavingRelations()
|
||||
{
|
||||
$tagDao = Injector::get(TagDao::class);
|
||||
|
||||
$tag1 = self::getTestTag('test 1');
|
||||
$tag2 = self::getTestTag('test 2');
|
||||
$tag3 = self::getTestTag('test 3');
|
||||
$tag4 = self::getTestTag('test 4');
|
||||
$tagDao = $this->getTagDao();
|
||||
$tagDao->save($tag1);
|
||||
$tagDao->save($tag2);
|
||||
$tagDao->save($tag3);
|
||||
|
@ -55,33 +54,30 @@ final class TagDaoTest extends AbstractDatabaseTestCase
|
|||
|
||||
public function testFindByPostIds()
|
||||
{
|
||||
$postDao = Injector::get(PostDao::class);
|
||||
$tagDao = Injector::get(TagDao::class);
|
||||
|
||||
$post1 = self::getTestPost();
|
||||
$post2 = self::getTestPost();
|
||||
$postDao->save($post1);
|
||||
$postDao->save($post2);
|
||||
|
||||
$tag1 = self::getTestTag('test1');
|
||||
$tag2 = self::getTestTag('test2');
|
||||
$tagDao->save($tag1);
|
||||
$tagDao->save($tag2);
|
||||
|
||||
$pdo = $this->databaseConnection->getPDO();
|
||||
|
||||
$pdo->exec('INSERT INTO tags(id, name, creationTime) VALUES (1, \'test1\', \'2014-10-01 00:00:00\')');
|
||||
$pdo->exec('INSERT INTO tags(id, name, creationTime) VALUES (2, \'test2\', \'2014-10-01 00:00:00\')');
|
||||
$pdo->exec('INSERT INTO postTags(postId, tagId) VALUES (5, 1)');
|
||||
$pdo->exec('INSERT INTO postTags(postId, tagId) VALUES (6, 1)');
|
||||
$pdo->exec('INSERT INTO postTags(postId, tagId) VALUES (5, 2)');
|
||||
$pdo->exec('INSERT INTO postTags(postId, tagId) VALUES (6, 2)');
|
||||
|
||||
$tag1 = new Tag(1);
|
||||
$tag1->setName('test1');
|
||||
$tag1->setCreationTime(date('c', mktime(0, 0, 0, 10, 1, 2014)));
|
||||
$tag2 = new Tag(2);
|
||||
$tag2->setName('test2');
|
||||
$tag2->setCreationTime(date('c', mktime(0, 0, 0, 10, 1, 2014)));
|
||||
$pdo->exec(sprintf('INSERT INTO postTags(postId, tagId) VALUES (%d, %d)', $post1->getId(), $tag1->getId()));
|
||||
$pdo->exec(sprintf('INSERT INTO postTags(postId, tagId) VALUES (%d, %d)', $post2->getId(), $tag1->getId()));
|
||||
$pdo->exec(sprintf('INSERT INTO postTags(postId, tagId) VALUES (%d, %d)', $post1->getId(), $tag2->getId()));
|
||||
$pdo->exec(sprintf('INSERT INTO postTags(postId, tagId) VALUES (%d, %d)', $post2->getId(), $tag2->getId()));
|
||||
|
||||
$expected = [
|
||||
$tag1->getId() => $tag1,
|
||||
$tag2->getId() => $tag2,
|
||||
];
|
||||
$tagDao = $this->getTagDao();
|
||||
$actual = $tagDao->findByPostId(5);
|
||||
$actual = $tagDao->findByPostId($post1->getId());
|
||||
$this->assertEntitiesEqual($expected, $actual);
|
||||
}
|
||||
|
||||
private function getTagDao()
|
||||
{
|
||||
return new TagDao($this->databaseConnection);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ final class UserDaoFilterTest extends AbstractDatabaseTestCase
|
|||
{
|
||||
list ($user1, $user2) = $this->prepareUsers();
|
||||
$this->doTestSorting(
|
||||
UserFilter::ORDER_REGISTRATION_TIME,
|
||||
UserFilter::ORDER_CREATION_TIME,
|
||||
UserFilter::ORDER_ASC,
|
||||
[$user2, $user1]);
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ final class UserDaoFilterTest extends AbstractDatabaseTestCase
|
|||
{
|
||||
list ($user1, $user2) = $this->prepareUsers();
|
||||
$this->doTestSorting(
|
||||
UserFilter::ORDER_REGISTRATION_TIME,
|
||||
UserFilter::ORDER_CREATION_TIME,
|
||||
UserFilter::ORDER_DESC,
|
||||
[$user1, $user2]);
|
||||
}
|
||||
|
@ -119,8 +119,8 @@ final class UserDaoFilterTest extends AbstractDatabaseTestCase
|
|||
{
|
||||
$user1 = self::getTestUser('beartato');
|
||||
$user2 = self::getTestUser('reginald');
|
||||
$user1->setRegistrationTime(date('c', mktime(3, 2, 1)));
|
||||
$user2->setRegistrationTime(date('c', mktime(1, 2, 3)));
|
||||
$user1->setCreationTime(date('c', mktime(3, 2, 1)));
|
||||
$user2->setCreationTime(date('c', mktime(1, 2, 3)));
|
||||
|
||||
$userDao = $this->getUserDao();
|
||||
$userDao->save($user1);
|
||||
|
|
|
@ -2,24 +2,25 @@
|
|||
namespace Szurubooru\Tests\SearchService;
|
||||
use \Szurubooru\Helpers\InputReader;
|
||||
use \Szurubooru\Search\Filters\UserFilter;
|
||||
use \Szurubooru\Search\Parsers\UserSearchParser;
|
||||
use \Szurubooru\Search\ParserConfigs\UserSearchParserConfig;
|
||||
use \Szurubooru\Search\SearchParser;
|
||||
use \Szurubooru\Tests\AbstractTestCase;
|
||||
|
||||
final class UserSearchParserTest extends AbstractTestCase
|
||||
{
|
||||
private $inputReader;
|
||||
private $userSearchParser;
|
||||
private $searchParser;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->inputReader = new InputReader;
|
||||
$this->userSearchParser = new UserSearchParser();
|
||||
$this->searchParser = new SearchParser(new UserSearchParserConfig);
|
||||
}
|
||||
|
||||
public function testDefaultOrder()
|
||||
{
|
||||
$filter = $this->userSearchParser->createFilterFromInputReader($this->inputReader);
|
||||
$filter = $this->searchParser->createFilterFromInputReader($this->inputReader);
|
||||
$this->assertOrderEquals([UserFilter::ORDER_NAME => UserFilter::ORDER_ASC], $filter->getOrder());
|
||||
}
|
||||
|
||||
|
@ -27,36 +28,36 @@ final class UserSearchParserTest extends AbstractTestCase
|
|||
{
|
||||
$this->inputReader->order = 'invalid,desc';
|
||||
$this->setExpectedException(\Exception::class);
|
||||
$filter = $this->userSearchParser->createFilterFromInputReader($this->inputReader);
|
||||
$filter = $this->searchParser->createFilterFromInputReader($this->inputReader);
|
||||
}
|
||||
|
||||
public function testInvalidOrderDirection()
|
||||
{
|
||||
$this->inputReader->order = 'name,invalid';
|
||||
$this->setExpectedException(\Exception::class);
|
||||
$filter = $this->userSearchParser->createFilterFromInputReader($this->inputReader);
|
||||
$filter = $this->searchParser->createFilterFromInputReader($this->inputReader);
|
||||
}
|
||||
|
||||
public function testParamOrder()
|
||||
{
|
||||
$this->inputReader->order = 'name,desc';
|
||||
$filter = $this->userSearchParser->createFilterFromInputReader($this->inputReader);
|
||||
$filter = $this->searchParser->createFilterFromInputReader($this->inputReader);
|
||||
$this->assertOrderEquals([UserFilter::ORDER_NAME => UserFilter::ORDER_DESC], $filter->getOrder());
|
||||
}
|
||||
|
||||
public function testTokenOverwriteDefaultOrder()
|
||||
{
|
||||
$this->inputReader->query = 'order:name,desc';
|
||||
$filter = $this->userSearchParser->createFilterFromInputReader($this->inputReader);
|
||||
$filter = $this->searchParser->createFilterFromInputReader($this->inputReader);
|
||||
$this->assertOrderEquals([UserFilter::ORDER_NAME => UserFilter::ORDER_DESC], $filter->getOrder());
|
||||
}
|
||||
|
||||
public function testTokenOrder()
|
||||
{
|
||||
$this->inputReader->query = 'order:registration_time,desc';
|
||||
$filter = $this->userSearchParser->createFilterFromInputReader($this->inputReader);
|
||||
$this->inputReader->query = 'order:creation_time,desc';
|
||||
$filter = $this->searchParser->createFilterFromInputReader($this->inputReader);
|
||||
$this->assertOrderEquals([
|
||||
UserFilter::ORDER_REGISTRATION_TIME => UserFilter::ORDER_DESC,
|
||||
UserFilter::ORDER_CREATION_TIME => UserFilter::ORDER_DESC,
|
||||
UserFilter::ORDER_NAME => UserFilter::ORDER_ASC],
|
||||
$filter->getOrder());
|
||||
}
|
||||
|
@ -64,10 +65,10 @@ final class UserSearchParserTest extends AbstractTestCase
|
|||
public function testParamAndTokenOrder()
|
||||
{
|
||||
$this->inputReader->order = 'name,desc';
|
||||
$this->inputReader->query = 'order:registration_time,desc';
|
||||
$filter = $this->userSearchParser->createFilterFromInputReader($this->inputReader);
|
||||
$this->inputReader->query = 'order:creation_time,desc';
|
||||
$filter = $this->searchParser->createFilterFromInputReader($this->inputReader);
|
||||
$this->assertOrderEquals([
|
||||
UserFilter::ORDER_REGISTRATION_TIME => UserFilter::ORDER_DESC,
|
||||
UserFilter::ORDER_CREATION_TIME => UserFilter::ORDER_DESC,
|
||||
UserFilter::ORDER_NAME => UserFilter::ORDER_DESC],
|
||||
$filter->getOrder());
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use Szurubooru\Services\ImageManipulation\IImageManipulator;
|
|||
use Szurubooru\Services\ImageManipulation\ImageManipulator;
|
||||
use Szurubooru\Services\ImageManipulation\ImagickImageManipulator;
|
||||
use Szurubooru\Tests\AbstractTestCase;
|
||||
use Szurubooru\Tests\ConfigMock;
|
||||
|
||||
final class ImageManipulatorTest extends AbstractTestCase
|
||||
{
|
||||
|
@ -47,10 +48,11 @@ final class ImageManipulatorTest extends AbstractTestCase
|
|||
|
||||
/**
|
||||
* @dataProvider imageManipulatorProvider
|
||||
* @expectedException Exception
|
||||
*/
|
||||
public function testNonImage($imageManipulator)
|
||||
{
|
||||
$this->assertNull($imageManipulator->loadFromBuffer($this->getTestFile('flash.swf')));
|
||||
$imageManipulator->loadFromBuffer($this->getTestFile('flash.swf'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,12 +140,18 @@ final class ImageManipulatorTest extends AbstractTestCase
|
|||
|
||||
private static function getAutoImageManipulator()
|
||||
{
|
||||
if (extension_loaded('gd') && extension_loaded('imagick'))
|
||||
{
|
||||
return new ImageManipulator(
|
||||
self::getImagickImageManipulator(),
|
||||
self::getGdImageManipulator());
|
||||
}
|
||||
return null;
|
||||
$configMock = new ConfigMock(null, null);
|
||||
|
||||
if (extension_loaded('imagick'))
|
||||
$configMock->set('misc/imageExtension', 'imagick');
|
||||
elseif (extension_loaded('gd'))
|
||||
$configMock->set('misc/imageExtension', 'gd');
|
||||
else
|
||||
return null;
|
||||
|
||||
return new ImageManipulator(
|
||||
self::getImagickImageManipulator(),
|
||||
self::getGdImageManipulator(),
|
||||
$configMock);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue