2013-10-10 00:09:28 +02:00
|
|
|
<?php
|
|
|
|
|
2017-01-26 09:28:42 +01:00
|
|
|
namespace SilverStripe\Blog\Tests;
|
|
|
|
|
|
|
|
use SilverStripe\Blog\Model\Blog;
|
2016-12-15 04:41:49 +01:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
|
|
|
use SilverStripe\Security\Member;
|
2017-09-13 23:53:29 +02:00
|
|
|
use SilverStripe\Security\Security;
|
2016-12-15 04:41:49 +01:00
|
|
|
|
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
|
|
|
|
*/
|
2017-01-26 09:28:42 +01:00
|
|
|
protected 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()
|
|
|
|
{
|
2017-09-13 23:53:29 +02:00
|
|
|
$member = Security::getCurrentUser();
|
2013-10-10 00:09:28 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
if ($member) {
|
2017-09-14 01:28:43 +02:00
|
|
|
Security::setCurrentUser(null);
|
2015-11-21 07:17:29 +01:00
|
|
|
}
|
2015-03-06 03:52:07 +01:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
/**
|
|
|
|
* @var Blog $blog
|
|
|
|
*/
|
2017-07-04 19:01:39 +02:00
|
|
|
$blog = $this->objFromFixture(Blog::class, '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
|
|
|
}
|