build in post page link

This commit is contained in:
John Bintz 2009-11-27 19:48:01 -05:00
parent 737466c654
commit a5a72a9128
2 changed files with 43 additions and 6 deletions

View File

@ -88,7 +88,7 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected_grouping, $this->w->_group_navigation_buttons($buttons, array()));
}
function providerTestSetUpPostNav() {
function providerTestSetUpPostNavStoryPrev() {
return array(
array(
array('story_prev_acts_as_prev_in' => 'off'),
@ -114,10 +114,35 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase {
}
/**
* @dataProvider providerTestSetUpPostNav
* @dataProvider providerTestSetUpPostNavStoryPrev
*/
function testComicPressSetUpPostNavFilter($instance, $post_nav, $expected_post_nav) {
$this->assertEquals($expected_post_nav, array_shift($this->w->comicpress_set_up_post_nav($post_nav, $instance)));
function testComicPressSetUpPostNavFilterStoryPrev($instance, $post_nav, $expected_post_nav) {
$this->assertEquals($expected_post_nav, array_shift($this->w->_comicpress_set_up_post_nav_story_prev($post_nav, $instance)));
}
/*function testComicPressSetUpPostNavFilterMultiPageSupport($instance, $post_nav, $_page, $_numpages, $expected_post_nav) {
global $post, $page, $numpages;
$post = (object)array('ID' => 1);
}*/
function providerTestBuildInPostPageLink() {
return array(
array('', 'publish', 'post-guid&page=2'),
array('test', 'publish', 'post-guid/2'),
array('test/', 'publish', 'post-guid/2/'),
array('test/', 'draft', 'post-guid&page=2'),
);
}
/**
* @dataProvider providerTestBuildInPostPageLink
*/
function testBuildInPostPageLink($permalink_structure, $post_status, $expected_link) {
update_option('permalink_structure', $permalink_structure);
$post = (object)array('guid' => 'post-guid', 'post_status' => $post_status);
$this->assertEquals($expected_link, $this->w->_build_in_post_page_link($post, 2));
}
function testSetUpPostNav() {

View File

@ -25,7 +25,11 @@ class GraphicalNavigationWidget extends WP_Widget {
add_filter('comicpress_wrap_navigation_buttons', array(&$this, 'comicpress_wrap_navigation_buttons'), 10, 2);
add_filter('comicpress_navigation_grouping_details', array(&$this, 'comicpress_navigation_grouping_details'));
add_filter('comicpress_set_up_post_nav', array(&$this, 'comicpress_set_up_post_nav'), 10, 2);
foreach (get_class_methods($this) as $method) {
if (strpos($method, '_comicpress_set_up_post_nav') === 0) {
add_filter('comicpress_set_up_post_nav', array(&$this, $method), 10, 2);
}
}
// these two need to be moved one level up
add_filter('comicpress_get_random_link_url', array(&$this, 'comicpress_get_random_link_url'));
@ -299,7 +303,15 @@ class GraphicalNavigationWidget extends WP_Widget {
}
}
function comicpress_set_up_post_nav($post_nav, $instance) {
function _build_in_post_page_link($post, $page) {
if (!get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending'))) {
return get_permalink($post) . "&page=${page}";
} else {
return trailingslashit(get_permalink($post)) . user_trailingslashit($page, 'single_paged');
}
}
function _comicpress_set_up_post_nav_story_prev($post_nav, $instance) {
if ($instance['story_prev_acts_as_prev_in'] == 'on') {
if ($post_nav['storyline-previous'] !== false) {
$post_nav['storyline-chapter-previous'] = $post_nav['storyline-previous'];