2014-05-11 23:40:09 +02:00
|
|
|
<?php
|
|
|
|
class PostModelTest extends AbstractTest
|
|
|
|
{
|
|
|
|
public function testFeaturedPostRetrieval()
|
|
|
|
{
|
|
|
|
$post = $this->assert->doesNotThrow(function()
|
|
|
|
{
|
|
|
|
return PostModel::getFeaturedPost();
|
|
|
|
});
|
|
|
|
|
2014-05-14 18:07:31 +02:00
|
|
|
$this->assert->isNull($post);
|
2014-05-11 23:40:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFeaturingNoPost()
|
|
|
|
{
|
|
|
|
PostModel::featureRandomPost();
|
|
|
|
|
|
|
|
$post = $this->assert->doesNotThrow(function()
|
|
|
|
{
|
|
|
|
return PostModel::getFeaturedPost();
|
|
|
|
});
|
|
|
|
|
2014-05-14 18:07:31 +02:00
|
|
|
$this->assert->isNull($post);
|
2014-05-11 23:40:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFeaturingRandomPost()
|
|
|
|
{
|
2014-05-13 21:08:07 +02:00
|
|
|
$post = $this->postMocker->mockSingle();
|
2014-05-11 23:40:09 +02:00
|
|
|
|
|
|
|
PostModel::featureRandomPost();
|
|
|
|
|
|
|
|
$this->assert->areEqual($post->getId(), (int) PropertyModel::get(PropertyModel::FeaturedPostId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFeaturingIllegalPosts()
|
|
|
|
{
|
|
|
|
$posts = [];
|
2014-05-13 21:08:07 +02:00
|
|
|
$posts = $this->postMocker->mockMultiple(6);
|
2014-05-11 23:40:09 +02:00
|
|
|
$posts[0]->setSafety(new PostSafety(PostSafety::Sketchy));
|
|
|
|
$posts[1]->setSafety(new PostSafety(PostSafety::Sketchy));
|
|
|
|
$posts[2]->setHidden(true);
|
|
|
|
$posts[3]->setType(new PostType(PostType::Youtube));
|
|
|
|
$posts[4]->setType(new PostType(PostType::Flash));
|
|
|
|
$posts[5]->setType(new PostType(PostType::Video));
|
2014-05-13 21:08:07 +02:00
|
|
|
PostModel::save($posts);
|
2014-05-11 23:40:09 +02:00
|
|
|
|
|
|
|
PostModel::featureRandomPost();
|
|
|
|
|
2014-05-14 18:07:31 +02:00
|
|
|
$this->assert->isNull(PropertyModel::get(PropertyModel::FeaturedPostId));
|
2014-05-11 23:40:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAutoFeaturingFirstTime()
|
|
|
|
{
|
2014-05-13 21:08:07 +02:00
|
|
|
$this->postMocker->mockSingle();
|
2014-05-11 23:40:09 +02:00
|
|
|
|
|
|
|
$this->assert->doesNotThrow(function()
|
|
|
|
{
|
|
|
|
PostModel::featureRandomPostIfNecessary();
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->assert->isNotNull(PostModel::getFeaturedPost());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAutoFeaturingTooSoon()
|
|
|
|
{
|
2014-05-13 21:08:07 +02:00
|
|
|
$this->postMocker->mockSingle();
|
2014-05-11 23:40:09 +02:00
|
|
|
|
|
|
|
$this->assert->isTrue(PostModel::featureRandomPostIfNecessary());
|
|
|
|
$this->assert->isFalse(PostModel::featureRandomPostIfNecessary());
|
|
|
|
|
|
|
|
$this->assert->isNotNull(PostModel::getFeaturedPost());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAutoFeaturingOutdated()
|
|
|
|
{
|
2014-05-13 21:08:07 +02:00
|
|
|
$post = $this->postMocker->mockSingle();
|
2014-05-15 10:32:53 +02:00
|
|
|
$minTimestamp = Core::getConfig()->misc->featuredPostMaxDays * 24 * 3600;
|
2014-05-11 23:40:09 +02:00
|
|
|
|
|
|
|
$this->assert->isTrue(PostModel::featureRandomPostIfNecessary());
|
|
|
|
PropertyModel::set(PropertyModel::FeaturedPostUnixTime, time() - $minTimestamp - 1);
|
|
|
|
$this->assert->isTrue(PostModel::featureRandomPostIfNecessary());
|
|
|
|
PropertyModel::set(PropertyModel::FeaturedPostUnixTime, time() - $minTimestamp + 1);
|
|
|
|
$this->assert->isFalse(PostModel::featureRandomPostIfNecessary());
|
|
|
|
|
|
|
|
$this->assert->isNotNull(PostModel::getFeaturedPost());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAutoFeaturingDeletedPost()
|
|
|
|
{
|
2014-05-13 21:08:07 +02:00
|
|
|
$post = $this->postMocker->mockSingle();
|
2014-05-11 23:40:09 +02:00
|
|
|
$this->assert->isTrue(PostModel::featureRandomPostIfNecessary());
|
|
|
|
$this->assert->isNotNull(PostModel::getFeaturedPost());
|
2014-05-13 21:08:07 +02:00
|
|
|
|
2014-05-11 23:40:09 +02:00
|
|
|
PostModel::remove($post);
|
|
|
|
|
2014-05-13 21:08:07 +02:00
|
|
|
$anotherPost = $this->postMocker->mockSingle();
|
|
|
|
$this->assert->isTrue(PostModel::featureRandomPostIfNecessary());
|
2014-05-11 23:40:09 +02:00
|
|
|
$this->assert->isNotNull(PostModel::getFeaturedPost());
|
|
|
|
}
|
|
|
|
}
|