/** * @dataProvider previousAndNextPostsDataProvider */ public function testPreviousAndNextPosts($postCount, $currentPostIndex) { $pc = new MockPieCrust(); $pc->getConfig()->setValue('blog/posts_per_page', 5); $pc->getConfig()->setValue('blog/date_format', 'F j, Y'); $posts = $this->buildPaginationDataSource($pc, $postCount); // The pagination data source is ordered in reverse // chronological order. Let's reverse it to be able // to index next/current/previous posts easily. // (the Paginator will reorder them internally) $posts = array_reverse($posts); $page = $posts[$currentPostIndex]; $paginator = new Paginator($page); $paginator->setPaginationDataSource($posts); $nextPost = $paginator->next_post(); $prevPost = $paginator->prev_post(); if ($currentPostIndex > 0) { $this->assertEquals($posts[$currentPostIndex - 1]->getUri(), $prevPost['slug']); } else { $this->assertNull($prevPost); } if ($currentPostIndex < $postCount - 1) { $this->assertEquals($posts[$currentPostIndex + 1]->getUri(), $nextPost['slug']); } else { $this->assertNull($nextPost); } }