improve graphical nav tests, implements GH#14
This commit is contained in:
parent
0b7b641e84
commit
87f3c71534
|
@ -87,6 +87,57 @@ class GraphicalNavigationTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
$this->assertEquals($expected_grouping, $this->w->_group_navigation_buttons($buttons, array()));
|
$this->assertEquals($expected_grouping, $this->w->_group_navigation_buttons($buttons, array()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function providerTestSetUpPostNav() {
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
array('story_prev_acts_as_prev_in' => 'off'),
|
||||||
|
array('storyline-previous' => 'test', 'storyline-chapter-previous' => 'test'),
|
||||||
|
array('storyline-previous' => 'test', 'storyline-chapter-previous' => 'test')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array('story_prev_acts_as_prev_in' => 'on'),
|
||||||
|
array('storyline-previous' => 'test2', 'storyline-chapter-previous' => 'test'),
|
||||||
|
array('storyline-previous' => 'test2', 'storyline-chapter-previous' => 'test2')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array('story_prev_acts_as_prev_in' => 'off'),
|
||||||
|
array('storyline-previous' => false, 'storyline-chapter-previous' => 'test'),
|
||||||
|
array('storyline-previous' => false, 'storyline-chapter-previous' => 'test')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array('story_prev_acts_as_prev_in' => 'on'),
|
||||||
|
array('storyline-previous' => false, 'storyline-chapter-previous' => 'test'),
|
||||||
|
array('storyline-previous' => false, 'storyline-chapter-previous' => 'test')
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerTestSetUpPostNav
|
||||||
|
*/
|
||||||
|
function testSetUpPostNav($instance, $post_nav, $expected_post_nav) {
|
||||||
|
global $post;
|
||||||
|
|
||||||
|
$post = 'post';
|
||||||
|
|
||||||
|
$css = $this->getMock('WidgetComicPressGraphicalStorylineNavigation', array('_new_comicpress_storyline', '_new_comicpress_navigation'));
|
||||||
|
|
||||||
|
update_option('comicpress-storyline-category-order', 'test');
|
||||||
|
|
||||||
|
$storyline = $this->getMock('ComicPressStoryline', array('set_order_via_flattened_storyline'));
|
||||||
|
$storyline->expects($this->once())->method('set_order_via_flattened_storyline')->with('test');
|
||||||
|
|
||||||
|
$css->expects($this->once())->method('_new_comicpress_storyline')->will($this->returnValue($storyline));
|
||||||
|
|
||||||
|
$navigation = $this->getMock('ComicPressNavigation', array('init', 'get_post_nav'));
|
||||||
|
$navigation->expects($this->once())->method('init');
|
||||||
|
$navigation->expects($this->once())->method('get_post_nav')->with($post)->will($this->returnValue($post_nav));
|
||||||
|
|
||||||
|
$css->expects($this->once())->method('_new_comicpress_navigation')->will($this->returnValue($navigation));
|
||||||
|
|
||||||
|
$this->assertEquals($expected_post_nav, $css->set_up_post_nav($instance));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -235,21 +235,8 @@ class WidgetComicPressGraphicalStorylineNavigation extends WP_Widget {
|
||||||
* Render the widget.
|
* Render the widget.
|
||||||
*/
|
*/
|
||||||
function widget($args, $instance) {
|
function widget($args, $instance) {
|
||||||
global $post;
|
|
||||||
|
|
||||||
if (is_home() || is_single()) {
|
if (is_home() || is_single()) {
|
||||||
$storyline = new ComicPressStoryline();
|
$post_nav = $this->set_up_post_nav($instance);
|
||||||
$storyline->set_order_via_flattened_storyline(get_option('comicpress-storyline-category-order'));
|
|
||||||
|
|
||||||
$navigation = new ComicPressNavigation();
|
|
||||||
$navigation->init($storyline);
|
|
||||||
$post_nav = $navigation->get_post_nav($post);
|
|
||||||
|
|
||||||
if ($instance['story_prev_acts_as_prev_in'] == 'on') {
|
|
||||||
if ($post_nav['storyline-previous'] !== false) {
|
|
||||||
$post_nav['storyline-chapter-previous'] = $post_nav['storyline-previous'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$storyline_to_nav_mapping = array(
|
$storyline_to_nav_mapping = array(
|
||||||
'story_prev' => 'storyline-chapter-previous',
|
'story_prev' => 'storyline-chapter-previous',
|
||||||
|
@ -274,6 +261,28 @@ class WidgetComicPressGraphicalStorylineNavigation extends WP_Widget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _new_comicpress_storyline() { return new ComicPressStoryline(); }
|
||||||
|
function _new_comicpress_navigation() { return new ComicPressNavigation(); }
|
||||||
|
|
||||||
|
function set_up_post_nav($instance) {
|
||||||
|
global $post;
|
||||||
|
|
||||||
|
$storyline = $this->_new_comicpress_storyline();
|
||||||
|
$storyline->set_order_via_flattened_storyline(get_option('comicpress-storyline-category-order'));
|
||||||
|
|
||||||
|
$navigation = $this->_new_comicpress_navigation();
|
||||||
|
$navigation->init($storyline);
|
||||||
|
$post_nav = $navigation->get_post_nav($post);
|
||||||
|
|
||||||
|
if ($instance['story_prev_acts_as_prev_in'] == 'on') {
|
||||||
|
if ($post_nav['storyline-previous'] !== false) {
|
||||||
|
$post_nav['storyline-chapter-previous'] = $post_nav['storyline-previous'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $post_nav;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the current widget instance.
|
* Update the current widget instance.
|
||||||
* @param array $new_instance The new widget instance data.
|
* @param array $new_instance The new widget instance data.
|
||||||
|
|
Loading…
Reference in New Issue