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;
|
2017-01-11 22:56:08 +01:00
|
|
|
use SilverStripe\Blog\Model\BlogController;
|
2017-01-26 09:28:42 +01:00
|
|
|
use SilverStripe\Blog\Model\BlogPost;
|
2016-12-15 04:41:49 +01:00
|
|
|
use SilverStripe\CMS\Controllers\ContentController;
|
|
|
|
use SilverStripe\Control\Controller;
|
|
|
|
use SilverStripe\Control\Director;
|
|
|
|
use SilverStripe\Control\HTTPRequest;
|
2017-11-02 20:32:38 +01:00
|
|
|
use SilverStripe\Control\HTTPResponse_Exception;
|
2017-07-04 19:01:39 +02:00
|
|
|
use SilverStripe\Control\Session;
|
2016-12-15 04:41:49 +01:00
|
|
|
use SilverStripe\Core\Config\Config;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\ORM\DataModel;
|
|
|
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
|
|
|
use SilverStripe\ORM\SS_List;
|
|
|
|
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
|
|
|
|
*/
|
2015-11-21 07:17:29 +01:00
|
|
|
class BlogTest extends SapphireTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2017-01-26 09:28:42 +01:00
|
|
|
protected static $fixture_file = 'blog.yml';
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
Config::nest();
|
2016-12-15 04:41:49 +01:00
|
|
|
DBDatetime::set_mock_now('2013-10-10 20:00:00');
|
2015-05-09 16:33:12 +02: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');
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$blog->publish('Stage', 'Live');
|
|
|
|
}
|
2015-02-08 08:03:55 +01:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function tearDown()
|
|
|
|
{
|
2016-12-15 04:41:49 +01:00
|
|
|
DBDatetime::clear_mock_now();
|
2015-11-21 07:17:29 +01:00
|
|
|
Config::unnest();
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
parent::tearDown();
|
|
|
|
}
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
public function testGetExcludedSiteTreeClassNames()
|
|
|
|
{
|
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
|
|
|
}
|
2013-10-10 00:09:28 +02: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
|
|
|
|
2017-01-26 09:28:42 +01:00
|
|
|
Config::inst()->update(BlogPost::class, 'show_in_sitetree', true);
|
2015-11-21 07:17:29 +01:00
|
|
|
$classes = $blog->getExcludedSiteTreeClassNames();
|
2013-10-10 00:09:28 +02:00
|
|
|
|
2017-01-26 09:28:42 +01:00
|
|
|
$this->assertNotContains(BlogPost::class, $classes, 'BlogPost class should be hidden.');
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2017-01-26 09:28:42 +01:00
|
|
|
Config::inst()->update(BlogPost::class, 'show_in_sitetree', false);
|
2015-11-21 07:17:29 +01:00
|
|
|
$classes = $blog->getExcludedSiteTreeClassNames();
|
2013-10-10 00:09:28 +02:00
|
|
|
|
2017-01-26 09:28:42 +01:00
|
|
|
$this->assertContains(BlogPost::class, $classes, 'BlogPost class should be hidden.');
|
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 testGetArchivedBlogPosts()
|
|
|
|
{
|
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-05-09 16:33:12 +02: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
|
|
|
$archive = $blog->getArchivedBlogPosts(2013);
|
2013-10-10 00:09:28 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$this->assertEquals(2, $archive->count(), 'Incorrect Yearly Archive count for 2013');
|
|
|
|
$this->assertEquals('First Post', $archive->first()->Title, 'Incorrect First Blog post');
|
|
|
|
$this->assertEquals('Second Post', $archive->last()->Title, 'Incorrect Last Blog post');
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$archive = $blog->getArchivedBlogPosts(2013, 10);
|
2013-10-10 00:09:28 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$this->assertEquals(1, $archive->count(), 'Incorrect monthly archive count.');
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$archive = $blog->getArchivedBlogPosts(2013, 10, 01);
|
2013-10-10 00:09:28 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$this->assertEquals(1, $archive->count(), 'Incorrect daily archive count.');
|
|
|
|
}
|
2014-04-10 14:44:17 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
public function testArchiveLinks()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Blog $blog
|
|
|
|
*/
|
2017-07-04 19:01:39 +02:00
|
|
|
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$link = Controller::join_links($blog->Link('archive'), '2013', '10', '01');
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$this->assertEquals(200, $this->getStatusOf($link), 'HTTP Status should be 200');
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$link = Controller::join_links($blog->Link('archive'), '2013', '10');
|
2014-04-10 14:44:17 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$this->assertEquals(200, $this->getStatusOf($link), 'HTTP Status should be 200');
|
2014-04-10 14:44:17 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$link = Controller::join_links($blog->Link('archive'), '2013');
|
2014-04-10 14:44:17 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$this->assertEquals(200, $this->getStatusOf($link), 'HTTP Status should be 200');
|
2014-04-10 14:44:17 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$link = Controller::join_links($blog->Link('archive'), '2011', '10', '01');
|
2014-04-10 14:44:17 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$this->assertEquals(200, $this->getStatusOf($link), 'HTTP Status should be 200');
|
2014-04-10 14:44:17 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$link = Controller::join_links($blog->Link('archive'));
|
|
|
|
$this->assertEquals(200, $this->getStatusOf($link), 'HTTP Status should be 200');
|
2014-04-10 14:44:17 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$link = Controller::join_links($blog->Link('archive'), 'invalid-year');
|
2014-04-10 14:44:17 +02:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
$this->assertEquals(404, $this->getStatusOf($link), 'HTTP Status should be 404');
|
|
|
|
|
|
|
|
$link = Controller::join_links($blog->Link('archive'), '2013', '99');
|
|
|
|
|
|
|
|
$this->assertEquals(404, $this->getStatusOf($link), 'HTTP Status should be 404');
|
|
|
|
|
|
|
|
$link = Controller::join_links($blog->Link('archive'), '2013', '10', '99');
|
|
|
|
|
|
|
|
$this->assertEquals(404, $this->getStatusOf($link), 'HTTP Status should be 404');
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test archive year
|
|
|
|
*/
|
|
|
|
public function testArchiveYear()
|
|
|
|
{
|
2017-07-04 19:01:39 +02:00
|
|
|
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');
|
2017-01-11 22:56:08 +01:00
|
|
|
$controller = new BlogController($blog);
|
2015-11-21 07:17:29 +01:00
|
|
|
$this->requestURL($controller, 'first-post/archive/');
|
|
|
|
$this->assertEquals(2013, $controller->getArchiveYear(), 'getArchiveYear should return 2013');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $link
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
protected function getStatusOf($link)
|
|
|
|
{
|
|
|
|
return Director::test($link)->getStatusCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRoles()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Blog $firstBlog
|
|
|
|
*/
|
2017-07-04 19:01:39 +02:00
|
|
|
$firstBlog = $this->objFromFixture(Blog::class, 'FirstBlog');
|
2015-11-21 07:17:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Blog $fourthBlog
|
|
|
|
*/
|
2017-07-04 19:01:39 +02:00
|
|
|
$fourthBlog = $this->objFromFixture(Blog::class, 'FourthBlog');
|
2015-11-21 07:17:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var BlogPost $postA
|
|
|
|
*/
|
2017-07-04 19:01:39 +02:00
|
|
|
$postA = $this->objFromFixture(BlogPost::class, 'PostA');
|
2015-11-21 07:17:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var BlogPost $postB
|
|
|
|
*/
|
2017-07-04 19:01:39 +02:00
|
|
|
$postB = $this->objFromFixture(BlogPost::class, 'PostB');
|
2015-11-21 07:17:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var BlogPost $postC
|
|
|
|
*/
|
2017-07-04 19:01:39 +02:00
|
|
|
$postC = $this->objFromFixture(BlogPost::class, 'PostC');
|
2015-11-21 07:17:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Member $editor
|
|
|
|
*/
|
2017-07-04 19:01:39 +02:00
|
|
|
$editor = $this->objFromFixture(Member::class, 'BlogEditor');
|
2015-11-21 07:17:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Member $writer
|
|
|
|
*/
|
2017-07-04 19:01:39 +02:00
|
|
|
$writer = $this->objFromFixture(Member::class, 'Writer');
|
2015-11-21 07:17:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Member $contributor
|
|
|
|
*/
|
2017-07-04 19:01:39 +02:00
|
|
|
$contributor = $this->objFromFixture(Member::class, 'Contributor');
|
2015-11-21 07:17:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Member $visitor
|
|
|
|
*/
|
2017-07-04 19:01:39 +02:00
|
|
|
$visitor = $this->objFromFixture(Member::class, 'Visitor');
|
2015-11-21 07:17:29 +01:00
|
|
|
|
|
|
|
$this->assertEquals('Editor', $fourthBlog->RoleOf($editor));
|
|
|
|
$this->assertEquals('Contributor', $fourthBlog->RoleOf($contributor));
|
|
|
|
$this->assertEquals('Writer', $fourthBlog->RoleOf($writer));
|
|
|
|
$this->assertEmpty($fourthBlog->RoleOf($visitor));
|
|
|
|
$this->assertEquals('Author', $postA->RoleOf($writer));
|
|
|
|
$this->assertEquals('Author', $postA->RoleOf($contributor));
|
|
|
|
$this->assertEquals('Editor', $postA->RoleOf($editor));
|
|
|
|
$this->assertEmpty($postA->RoleOf($visitor));
|
|
|
|
|
|
|
|
// Test RoleOf with string values given
|
|
|
|
$this->assertEquals('Editor', $fourthBlog->RoleOf((string)(int)$editor->ID));
|
|
|
|
$this->assertEquals('Contributor', $fourthBlog->RoleOf((string)(int)$contributor->ID));
|
|
|
|
$this->assertEquals('Writer', $fourthBlog->RoleOf((string)(int)$writer->ID));
|
|
|
|
$this->assertEmpty($fourthBlog->RoleOf((string)(int)$visitor->ID));
|
|
|
|
$this->assertEquals('Author', $postA->RoleOf((string)(int)$writer->ID));
|
|
|
|
$this->assertEquals('Author', $postA->RoleOf((string)(int)$contributor->ID));
|
|
|
|
$this->assertEquals('Editor', $postA->RoleOf((string)(int)$editor->ID));
|
|
|
|
$this->assertEmpty($postA->RoleOf((string)(int)$visitor->ID));
|
|
|
|
|
|
|
|
// Test RoleOf with int values given
|
|
|
|
$this->assertEquals('Editor', $fourthBlog->RoleOf((int)$editor->ID));
|
|
|
|
$this->assertEquals('Contributor', $fourthBlog->RoleOf((int)$contributor->ID));
|
|
|
|
$this->assertEquals('Writer', $fourthBlog->RoleOf((int)$writer->ID));
|
|
|
|
$this->assertEmpty($fourthBlog->RoleOf((int)$visitor->ID));
|
|
|
|
$this->assertEquals('Author', $postA->RoleOf((int)$writer->ID));
|
|
|
|
$this->assertEquals('Author', $postA->RoleOf((int)$contributor->ID));
|
|
|
|
$this->assertEquals('Editor', $postA->RoleOf((int)$editor->ID));
|
|
|
|
$this->assertEmpty($postA->RoleOf((int)$visitor->ID));
|
|
|
|
|
|
|
|
$this->assertTrue($fourthBlog->canEdit($editor));
|
|
|
|
$this->assertFalse($firstBlog->canEdit($editor));
|
|
|
|
$this->assertTrue($fourthBlog->canAddChildren($editor));
|
|
|
|
$this->assertFalse($firstBlog->canAddChildren($editor));
|
|
|
|
$this->assertTrue($postA->canEdit($editor));
|
|
|
|
$this->assertTrue($postB->canEdit($editor));
|
|
|
|
$this->assertTrue($postC->canEdit($editor));
|
|
|
|
$this->assertTrue($postA->canPublish($editor));
|
|
|
|
$this->assertTrue($postB->canPublish($editor));
|
|
|
|
$this->assertTrue($postC->canPublish($editor));
|
|
|
|
|
|
|
|
$this->assertFalse($fourthBlog->canEdit($writer));
|
|
|
|
$this->assertFalse($firstBlog->canEdit($writer));
|
|
|
|
$this->assertTrue($fourthBlog->canAddChildren($writer));
|
|
|
|
$this->assertFalse($firstBlog->canAddChildren($writer));
|
|
|
|
$this->assertTrue($postA->canEdit($writer));
|
|
|
|
$this->assertFalse($postB->canEdit($writer));
|
|
|
|
$this->assertTrue($postC->canEdit($writer));
|
|
|
|
$this->assertTrue($postA->canPublish($writer));
|
|
|
|
$this->assertFalse($postB->canPublish($writer));
|
|
|
|
$this->assertTrue($postC->canPublish($writer));
|
|
|
|
|
|
|
|
$this->assertFalse($fourthBlog->canEdit($contributor));
|
|
|
|
$this->assertFalse($firstBlog->canEdit($contributor));
|
|
|
|
$this->assertTrue($fourthBlog->canAddChildren($contributor));
|
|
|
|
$this->assertFalse($firstBlog->canAddChildren($contributor));
|
|
|
|
$this->assertTrue($postA->canEdit($contributor));
|
|
|
|
$this->assertFalse($postB->canEdit($contributor));
|
|
|
|
$this->assertTrue($postC->canEdit($contributor));
|
|
|
|
$this->assertFalse($postA->canPublish($contributor));
|
|
|
|
$this->assertFalse($postB->canPublish($contributor));
|
|
|
|
$this->assertFalse($postC->canPublish($contributor));
|
|
|
|
|
|
|
|
$this->assertFalse($fourthBlog->canEdit($visitor));
|
|
|
|
$this->assertFalse($firstBlog->canEdit($visitor));
|
|
|
|
$this->assertFalse($fourthBlog->canAddChildren($visitor));
|
|
|
|
$this->assertFalse($firstBlog->canAddChildren($visitor));
|
|
|
|
$this->assertFalse($postA->canEdit($visitor));
|
|
|
|
$this->assertFalse($postB->canEdit($visitor));
|
|
|
|
$this->assertFalse($postC->canEdit($visitor));
|
|
|
|
$this->assertFalse($postA->canPublish($visitor));
|
|
|
|
$this->assertFalse($postB->canPublish($visitor));
|
|
|
|
$this->assertFalse($postC->canPublish($visitor));
|
|
|
|
}
|
|
|
|
|
2017-07-04 19:01:39 +02:00
|
|
|
public function testFilteredCategoriesRoot()
|
2015-11-21 07:17:29 +01:00
|
|
|
{
|
2017-07-04 19:01:39 +02:00
|
|
|
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');
|
2017-01-11 22:56:08 +01:00
|
|
|
$controller = new BlogController($blog);
|
2015-11-21 07:17:29 +01:00
|
|
|
$this->requestURL($controller, 'first-post');
|
|
|
|
$this->assertIDsEquals(
|
|
|
|
$blog->AllChildren()->column('ID'),
|
|
|
|
$controller->PaginatedList()->column('ID')
|
|
|
|
);
|
2017-07-04 19:01:39 +02:00
|
|
|
}
|
2015-11-21 07:17:29 +01:00
|
|
|
|
2017-07-04 19:01:39 +02:00
|
|
|
public function testFilteredCategoriesRSS()
|
|
|
|
{
|
|
|
|
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');
|
|
|
|
$controller = new BlogController($blog);
|
2015-11-21 07:17:29 +01:00
|
|
|
$this->requestURL($controller, 'first-post/rss');
|
|
|
|
$this->assertIDsEquals(
|
|
|
|
$blog->AllChildren()->column('ID'),
|
|
|
|
$controller->PaginatedList()->column('ID')
|
|
|
|
);
|
2017-07-04 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFilteredCategoriesTags()
|
|
|
|
{
|
|
|
|
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');
|
|
|
|
$controller = new BlogController($blog);
|
2015-11-21 07:17:29 +01:00
|
|
|
|
|
|
|
// Posts
|
2017-07-04 19:01:39 +02:00
|
|
|
$firstPostID = $this->idFromFixture(BlogPost::class, 'FirstBlogPost');
|
|
|
|
$firstFuturePostID = $this->idFromFixture(BlogPost::class, 'FirstFutureBlogPost');
|
|
|
|
$secondFuturePostID = $this->idFromFixture(BlogPost::class, 'SecondFutureBlogPost');
|
2015-11-21 07:17:29 +01:00
|
|
|
|
|
|
|
// Request first tag
|
|
|
|
$this->requestURL($controller, 'first-post/tag/first-tag');
|
|
|
|
$this->assertIDsEquals(
|
2017-09-14 00:59:01 +02:00
|
|
|
[$firstPostID, $firstFuturePostID, $secondFuturePostID],
|
2015-11-21 07:17:29 +01:00
|
|
|
$controller->PaginatedList()
|
|
|
|
);
|
2017-07-04 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFilteredCategoriesArchive()
|
|
|
|
{
|
|
|
|
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');
|
|
|
|
$controller = new BlogController($blog);
|
|
|
|
|
|
|
|
// Posts
|
|
|
|
$firstPostID = $this->idFromFixture(BlogPost::class, 'FirstBlogPost');
|
|
|
|
$secondPostID = $this->idFromFixture(BlogPost::class, 'SecondBlogPost');
|
|
|
|
$secondFuturePostID = $this->idFromFixture(BlogPost::class, 'SecondFutureBlogPost');
|
2015-11-21 07:17:29 +01:00
|
|
|
|
|
|
|
// Request 2013 posts
|
|
|
|
$this->requestURL($controller, 'first-post/archive/2013');
|
|
|
|
$this->assertIDsEquals(
|
2017-09-14 00:59:01 +02:00
|
|
|
[$firstPostID, $secondPostID, $secondFuturePostID],
|
2015-11-21 07:17:29 +01:00
|
|
|
$controller->PaginatedList()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-11-02 20:32:38 +01:00
|
|
|
public function testDisabledProfiles()
|
|
|
|
{
|
|
|
|
Config::modify()->set(BlogController::class, 'disable_profiles', true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$controller = BlogController::create();
|
|
|
|
$controller->setRequest(Controller::curr()->getRequest());
|
|
|
|
$controller->profile();
|
|
|
|
|
|
|
|
$this->fail('The "profile" action should throw a HTTPResponse_Exception when disable_profiles is enabled');
|
|
|
|
} catch (HTTPResponse_Exception $e) {
|
|
|
|
$this->assertEquals(404, $e->getResponse()->getStatusCode(), 'The response status code should be 404 Not Found');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
/**
|
|
|
|
* Mock a request against a given controller
|
|
|
|
*
|
|
|
|
* @param ContentController $controller
|
|
|
|
* @param string $url
|
|
|
|
*/
|
|
|
|
protected function requestURL(ContentController $controller, $url)
|
|
|
|
{
|
2016-12-15 04:41:49 +01:00
|
|
|
$request = new HTTPRequest('get', $url);
|
2015-11-21 07:17:29 +01:00
|
|
|
$request->match('$URLSegment//$Action/$ID/$OtherID');
|
|
|
|
$request->shift();
|
2017-07-04 19:01:39 +02:00
|
|
|
$session = new Session(null);
|
|
|
|
$session->start($request);
|
|
|
|
$request->setSession($session);
|
2017-01-26 09:28:42 +01:00
|
|
|
$controller->doInit();
|
2017-07-04 19:01:39 +02:00
|
|
|
$controller->handleRequest($request);
|
|
|
|
$session->clearAll();
|
|
|
|
$session->destroy();
|
2015-11-21 07:17:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert these id lists match
|
|
|
|
*
|
|
|
|
* @param array|SS_List $left
|
|
|
|
* @param array|SS_List $right
|
|
|
|
*/
|
|
|
|
protected function assertIDsEquals($left, $right)
|
|
|
|
{
|
|
|
|
if ($left instanceof SS_List) {
|
|
|
|
$left = $left->column('ID');
|
|
|
|
}
|
|
|
|
if ($right instanceof SS_List) {
|
|
|
|
$right = $right->column('ID');
|
|
|
|
}
|
|
|
|
asort($left);
|
|
|
|
asort($right);
|
|
|
|
$this->assertEquals(array_values($left), array_values($right));
|
|
|
|
}
|
2015-05-09 16:33:12 +02:00
|
|
|
}
|