Enhanced support for MySQL

This commit is contained in:
Marcin Kurczewski 2014-05-15 11:51:01 +02:00
parent 3f93973a12
commit aa20b81229
8 changed files with 31 additions and 25 deletions

@ -1 +1 @@
Subproject commit f912adb6115feaac885c0fc6728cff8c8ce606fc Subproject commit 6bb18c1c6ed7ea952ae7a8dab792d5364a334201

View file

@ -15,9 +15,9 @@ final class CommentEntity extends AbstractEntity implements IValidatable
{ {
$this->id = (int) $row['id']; $this->id = (int) $row['id'];
$this->text = $row['text']; $this->text = $row['text'];
$this->postId = (int) $row['post_id']; $this->postId = TextHelper::toIntegerOrNull($row['post_id']);
$this->commentDate = $row['comment_date']; $this->commentDate = $row['comment_date'];
$this->commenterId = (int) $row['commenter_id']; $this->commenterId = TextHelper::toIntegerOrNull($row['commenter_id']);
} }
public function validate() public function validate()

View file

@ -22,6 +22,7 @@ final class PostEntity extends AbstractEntity implements IValidatable
{ {
$this->setSafety(new PostSafety(PostSafety::Safe)); $this->setSafety(new PostSafety(PostSafety::Safe));
$this->setHidden(false); $this->setHidden(false);
$this->setUploader(null);
$this->setCreationTime(time()); $this->setCreationTime(time());
do do
{ {
@ -36,13 +37,13 @@ final class PostEntity extends AbstractEntity implements IValidatable
$this->name = $row['name']; $this->name = $row['name'];
$this->origName = $row['orig_name']; $this->origName = $row['orig_name'];
$this->fileHash = $row['file_hash']; $this->fileHash = $row['file_hash'];
$this->fileSize = (int) $row['file_size']; $this->fileSize = TextHelper::toIntegerOrNull($row['file_size']);
$this->mimeType = $row['mime_type']; $this->mimeType = $row['mime_type'];
$this->hidden = (bool) $row['hidden']; $this->hidden = TextHelper::toBooleanOrNull($row['hidden']);
$this->uploadDate = $row['upload_date']; $this->uploadDate = $row['upload_date'];
$this->imageWidth = (int) $row['image_width']; $this->imageWidth = TextHelper::toIntegerOrNull($row['image_width']);
$this->imageHeight = (int) $row['image_height']; $this->imageHeight = TextHelper::toIntegerOrNull($row['image_height']);
$this->uploaderId = (int) $row['uploader_id']; $this->uploaderId = TextHelper::toIntegerOrNull($row['uploader_id']);
$this->source = $row['source']; $this->source = $row['source'];
$this->setCache('comment_count', $row['comment_count']); $this->setCache('comment_count', $row['comment_count']);
$this->setCache('fav_count', $row['fav_count']); $this->setCache('fav_count', $row['fav_count']);

View file

@ -25,9 +25,9 @@ final class TokenEntity extends AbstractEntity implements IValidatable
public function fillFromDatabase($row) public function fillFromDatabase($row)
{ {
$this->id = (int) $row['id']; $this->id = (int) $row['id'];
$this->userId = (int) $row['user_id']; $this->userId = TextHelper::toIntegerOrNull($row['user_id']);
$this->token = $row['token']; $this->token = $row['token'];
$this->used = (bool) $row['used']; $this->used = TextHelper::toBooleanOrNull($row['used']);
$this->expires = $row['expires']; $this->expires = $row['expires'];
} }

View file

@ -17,7 +17,7 @@ class AddCommentJobTest extends AbstractTest
$this->assert->areEqual(1, CommentModel::getCount()); $this->assert->areEqual(1, CommentModel::getCount());
$this->assert->areEqual($text, $comment->getText()); $this->assert->areEqual($text, $comment->getText());
$this->assert->areEqual(Auth::getCurrentUser()->getId(), $comment->getCommenter()->getId()); $this->assert->areEqual(Auth::getCurrentUser()->getId(), $comment->getCommenter()->getId());
$this->assert->areEqual(1, $post->getId()); $this->assert->isNotNull($post->getId());
$this->assert->areEqual(1, $post->getCommentCount()); $this->assert->areEqual(1, $post->getCommentCount());
$this->assert->isNotNull($comment->getCreationTime()); $this->assert->isNotNull($comment->getCreationTime());
$this->assert->doesNotThrow(function() use ($comment) $this->assert->doesNotThrow(function() use ($comment)

View file

@ -14,7 +14,7 @@ class EditCommentJobTest extends AbstractTest
$this->assert->areEqual($text, $comment->getText()); $this->assert->areEqual($text, $comment->getText());
$this->assert->areEqual(Auth::getCurrentUser()->getId(), $comment->getCommenter()->getId()); $this->assert->areEqual(Auth::getCurrentUser()->getId(), $comment->getCommenter()->getId());
$this->assert->areEqual(1, $comment->getPost()->getId()); $this->assert->isNotNull($comment->getPost()->getId());
$this->assert->isNotNull($comment->getCreationTime()); $this->assert->isNotNull($comment->getCreationTime());
$this->assert->doesNotThrow(function() use ($comment) $this->assert->doesNotThrow(function() use ($comment)
{ {

View file

@ -135,7 +135,7 @@ class EditPostContentJobTest extends AbstractTest
$this->assert->throws(function() $this->assert->throws(function()
{ {
$this->uploadFromFile('image.png'); $this->uploadFromFile('image.png');
}, 'Duplicate upload: @1'); }, 'Duplicate upload: @' . $post->getId());
} }
public function testDuplicateUrl() public function testDuplicateUrl()
@ -147,7 +147,7 @@ class EditPostContentJobTest extends AbstractTest
$this->assert->throws(function() $this->assert->throws(function()
{ {
$this->uploadFromUrl('image.png'); $this->uploadFromUrl('image.png');
}, 'Duplicate upload: @1'); }, 'Duplicate upload: @' . $post->getId());
} }
public function testDuplicateYoutube() public function testDuplicateYoutube()
@ -165,16 +165,16 @@ class EditPostContentJobTest extends AbstractTest
JobArgs::ARG_NEW_POST_CONTENT_URL => $url, JobArgs::ARG_NEW_POST_CONTENT_URL => $url,
]); ]);
$post = $this->postMocker->mockSingle(); $anotherPost = $this->postMocker->mockSingle();
$this->assert->throws(function() use ($post, $url) $this->assert->throws(function() use ($anotherPost, $url)
{ {
Api::run( Api::run(
new EditPostContentJob(), new EditPostContentJob(),
[ [
JobArgs::ARG_POST_ID => $post->getId(), JobArgs::ARG_POST_ID => $anotherPost->getId(),
JobArgs::ARG_NEW_POST_CONTENT_URL => $url, JobArgs::ARG_NEW_POST_CONTENT_URL => $url,
]); ]);
}, 'Duplicate upload: @1'); }, 'Duplicate upload: @' . $post->getId());
} }
protected function prepare() protected function prepare()

View file

@ -203,9 +203,13 @@ class ListPostsJobTest extends AbstractTest
foreach (['id', 'ids'] as $alias) foreach (['id', 'ids'] as $alias)
{ {
$ret = $this->assert->doesNotThrow(function() use ($alias) $ret = $this->assert->doesNotThrow(function() use ($alias, $posts)
{ {
return Api::run(new ListPostsJob(), [JobArgs::ARG_QUERY => $alias . ':1,3,5']); $query = sprintf('%s:9999,%d,%d',
$alias,
$posts[0]->getId(),
$posts[2]->getId());
return Api::run(new ListPostsJob(), [JobArgs::ARG_QUERY => $query]);
}); });
$this->assert->areEqual(2, $ret->entityCount); $this->assert->areEqual(2, $ret->entityCount);
@ -311,9 +315,9 @@ class ListPostsJobTest extends AbstractTest
foreach (['idmin', 'id_min'] as $alias) foreach (['idmin', 'id_min'] as $alias)
{ {
$ret = $this->assert->doesNotThrow(function() use ($alias) $ret = $this->assert->doesNotThrow(function() use ($alias, $posts)
{ {
return Api::run(new ListPostsJob(), [JobArgs::ARG_QUERY => $alias . ':2']); return Api::run(new ListPostsJob(), [JobArgs::ARG_QUERY => $alias . ':' . $posts[1]->getId()]);
}); });
$this->assert->areEqual(2, $ret->entityCount); $this->assert->areEqual(2, $ret->entityCount);
@ -323,9 +327,9 @@ class ListPostsJobTest extends AbstractTest
foreach (['idmax', 'id_max'] as $alias) foreach (['idmax', 'id_max'] as $alias)
{ {
$ret = $this->assert->doesNotThrow(function() use ($alias) $ret = $this->assert->doesNotThrow(function() use ($alias, $posts)
{ {
return Api::run(new ListPostsJob(), [JobArgs::ARG_QUERY => $alias . ':2']); return Api::run(new ListPostsJob(), [JobArgs::ARG_QUERY => $alias . ':' . $posts[1]->getId()]);
}); });
$this->assert->areEqual(2, $ret->entityCount); $this->assert->areEqual(2, $ret->entityCount);
@ -680,7 +684,8 @@ class ListPostsJobTest extends AbstractTest
$this->grantAccess('listPosts'); $this->grantAccess('listPosts');
$num = 15; $num = 15;
$posts = $this->postMocker->mockMultiple($num); $posts = $this->postMocker->mockMultiple($num);
$expectedPostIdsSorted = range(1, $num); $expectedPostIdsSorted = array_map(function($post) { return $post->getId(); }, $posts);
sort($expectedPostIdsSorted);
$ret = $this->assert->doesNotThrow(function() $ret = $this->assert->doesNotThrow(function()
{ {