silverstripe-blog/tests/BlogPostFilterTest.php

59 lines
1.3 KiB
PHP
Raw Normal View History

2013-10-10 00:09:28 +02:00
<?php
namespace SilverStripe\Blog\Tests;
use SilverStripe\Blog\Model\Blog;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\Security\Security;
2015-05-09 16:33:12 +02:00
/**
* @mixin PHPUnit_Framework_TestCase
* @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
*/
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
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()
{
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
/**
* Tests that unpublished articles are not returned
* @covers ::augmentSQL
*/
2015-11-21 07:17:29 +01:00
public function testFilter()
{
$member = Security::getCurrentUser();
2013-10-10 00:09:28 +02:00
2015-11-21 07:17:29 +01:00
if ($member) {
Security::setCurrentUser(null);
2015-11-21 07:17:29 +01:00
}
2015-11-21 07:17:29 +01:00
/**
* @var Blog $blog
*/
$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
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
}