2013-10-10 00:09:28 +02:00
|
|
|
<?php
|
|
|
|
|
2016-12-15 04:41:49 +01:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
|
|
|
use SilverStripe\Security\Member;
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* @mixin PHPUnit_Framework_TestCase
|
2016-12-15 23:57:25 +01:00
|
|
|
* @coversDefaultClass \SilverStripe\Blog\Model\BlogPostFilter
|
2015-05-09 16:33:12 +02:00
|
|
|
*/
|
2015-11-21 07:17:29 +01:00
|
|
|
class BlogPostFilterTest extends SapphireTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public static $fixture_file = 'blog.yml';
|
2013-10-10 00:09:28 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2016-12-15 04:41:49 +01:00
|
|
|
DBDatetime::set_mock_now('2013-10-10 20:00:00');
|
2015-11-21 07:17:29 +01:00
|
|
|
}
|
2013-10-10 00:09:28 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
public function tearDown()
|
|
|
|
{
|
2016-12-15 04:41:49 +01:00
|
|
|
DBDatetime::clear_mock_now();
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
parent::tearDown();
|
|
|
|
}
|
2015-02-08 08:03:55 +01:00
|
|
|
|
2016-12-15 23:57:25 +01:00
|
|
|
/**
|
|
|
|
* Tests that unpublished articles are not returned
|
|
|
|
* @covers ::augmentSQL
|
|
|
|
*/
|
2015-11-21 07:17:29 +01:00
|
|
|
public function testFilter()
|
|
|
|
{
|
|
|
|
$member = Member::currentUser();
|
2013-10-10 00:09:28 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
if ($member) {
|
|
|
|
$member->logout();
|
|
|
|
}
|
2015-03-06 03:52:07 +01:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
/**
|
|
|
|
* @var Blog $blog
|
|
|
|
*/
|
2016-12-15 04:41:49 +01:00
|
|
|
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog');
|
2013-10-10 00:09:28 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$this->assertEquals(3, $blog->AllChildren()->Count(), 'Filtered blog posts');
|
2013-10-10 00:09:28 +02:00
|
|
|
|
2016-12-15 04:41:49 +01:00
|
|
|
DBDatetime::set_mock_now('2020-01-01 00:00:00');
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$this->assertEquals(5, $blog->AllChildren()->Count(), 'Unfiltered blog posts');
|
|
|
|
}
|
2013-10-10 00:09:28 +02:00
|
|
|
}
|