mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Merge pull request #319 from tractorcow/pulls/fix-paginated-filter
BUG Fix tag / category filters not being filtered in PaginatedList()
This commit is contained in:
commit
a27dd892f6
@ -963,27 +963,21 @@ class Blog_Controller extends Page_Controller {
|
|||||||
* @return PaginatedList
|
* @return PaginatedList
|
||||||
*/
|
*/
|
||||||
public function PaginatedList() {
|
public function PaginatedList() {
|
||||||
/**
|
$allPosts = $this->blogPosts ?: new ArrayList();
|
||||||
* @var Blog $dataRecord
|
$posts = new PaginatedList($allPosts);
|
||||||
*/
|
|
||||||
$dataRecord = $this->dataRecord;
|
|
||||||
|
|
||||||
$posts = new PaginatedList($this->getBlogPosts());
|
|
||||||
|
|
||||||
|
// Set appropriate page size
|
||||||
if($this->PostsPerPage > 0) {
|
if($this->PostsPerPage > 0) {
|
||||||
$posts->setPageLength($this->PostsPerPage);
|
$pageSize = $this->PostsPerPage;
|
||||||
|
} elseif($count = $allPosts->count()) {
|
||||||
|
$pageSize = $count;
|
||||||
} else {
|
} else {
|
||||||
$pageSize = 99999;
|
$pageSize = 99999;
|
||||||
|
|
||||||
if($count = $dataRecord->getBlogPosts()->count()) {
|
|
||||||
$pageSize = $count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$posts->setPageLength($pageSize);
|
$posts->setPageLength($pageSize);
|
||||||
}
|
|
||||||
|
|
||||||
|
// Set current page
|
||||||
$start = $this->request->getVar($posts->getPaginationGetVar());
|
$start = $this->request->getVar($posts->getPaginationGetVar());
|
||||||
|
|
||||||
$posts->setPageStart($start);
|
$posts->setPageStart($start);
|
||||||
|
|
||||||
return $posts;
|
return $posts;
|
||||||
@ -1000,7 +994,9 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*/
|
*/
|
||||||
$dataRecord = $this->dataRecord;
|
$dataRecord = $this->dataRecord;
|
||||||
|
|
||||||
$rss = new RSSFeed($dataRecord->getBlogPosts(), $this->Link(), $this->MetaTitle, $this->MetaDescription);
|
$this->blogPosts = $dataRecord->getBlogPosts();
|
||||||
|
|
||||||
|
$rss = new RSSFeed($this->blogPosts, $this->Link(), $this->MetaTitle, $this->MetaDescription);
|
||||||
|
|
||||||
$this->extend('updateRss', $rss);
|
$this->extend('updateRss', $rss);
|
||||||
|
|
||||||
|
@ -254,4 +254,72 @@ class BlogTest extends SapphireTest {
|
|||||||
$this->assertFalse($postB->canPublish($visitor));
|
$this->assertFalse($postB->canPublish($visitor));
|
||||||
$this->assertFalse($postC->canPublish($visitor));
|
$this->assertFalse($postC->canPublish($visitor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFilteredCategories() {
|
||||||
|
$blog = $this->objFromFixture('Blog', 'FirstBlog');
|
||||||
|
$controller = new Blog_Controller($blog);
|
||||||
|
|
||||||
|
// Root url
|
||||||
|
$this->requestURL($controller, 'first-post');
|
||||||
|
$this->assertIDsEquals(
|
||||||
|
$blog->AllChildren()->column('ID'),
|
||||||
|
$controller->PaginatedList()->column('ID')
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// RSS
|
||||||
|
$this->requestURL($controller, 'first-post/rss');
|
||||||
|
$this->assertIDsEquals(
|
||||||
|
$blog->AllChildren()->column('ID'),
|
||||||
|
$controller->PaginatedList()->column('ID')
|
||||||
|
);
|
||||||
|
|
||||||
|
// Posts
|
||||||
|
$firstPostID = $this->idFromFixture('BlogPost', 'FirstBlogPost');
|
||||||
|
$secondPostID = $this->idFromFixture('BlogPost', 'SecondBlogPost');
|
||||||
|
$firstFuturePostID = $this->idFromFixture('BlogPost', 'FirstFutureBlogPost');
|
||||||
|
$secondFuturePostID = $this->idFromFixture('BlogPost', 'SecondFutureBlogPost');
|
||||||
|
|
||||||
|
// Request first tag
|
||||||
|
$this->requestURL($controller, 'first-post/tag/first-tag');
|
||||||
|
$this->assertIDsEquals(
|
||||||
|
array($firstPostID, $firstFuturePostID, $secondFuturePostID),
|
||||||
|
$controller->PaginatedList()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Request 2013 posts
|
||||||
|
$this->requestURL($controller, 'first-post/archive/2013');
|
||||||
|
$this->assertIDsEquals(
|
||||||
|
array($firstPostID, $secondPostID, $secondFuturePostID),
|
||||||
|
$controller->PaginatedList()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock a request against a given controller
|
||||||
|
*
|
||||||
|
* @param ContentController $controller
|
||||||
|
* @param string $url
|
||||||
|
*/
|
||||||
|
protected function requestURL(ContentController $controller, $url) {
|
||||||
|
$request = new SS_HTTPRequest('get', $url);
|
||||||
|
$request->match('$URLSegment//$Action/$ID/$OtherID');
|
||||||
|
$request->shift();
|
||||||
|
$controller->init();
|
||||||
|
$controller->handleRequest($request, new DataModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user