add additional grouping wrapping
This commit is contained in:
parent
8a0239ec40
commit
a4750dc38d
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once('MockPress/mockpress.php');
|
//require_once('MockPress/mockpress.php');
|
||||||
|
require_once(dirname(__FILE__) . '/../../../mockpress/mockpress.php');
|
||||||
require_once('PHPUnit/Framework.php');
|
require_once('PHPUnit/Framework.php');
|
||||||
require_once(dirname(__FILE__) . '/../../widgets/graphical-navigation.php');
|
require_once(dirname(__FILE__) . '/../../widgets/graphical-navigation.php');
|
||||||
|
|
||||||
|
@ -10,6 +11,9 @@ class GraphicalNavigationTest extends PHPUnit_Framework_TestCase {
|
||||||
$this->w = new WidgetComicPressGraphicalStorylineNavigation();
|
$this->w = new WidgetComicPressGraphicalStorylineNavigation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers WidgetComicPressGraphicalStorylineNavigation::update
|
||||||
|
*/
|
||||||
function testUpdateWidget() {
|
function testUpdateWidget() {
|
||||||
$result = $this->w->update(array(
|
$result = $this->w->update(array(
|
||||||
"next" => "<b>test</b>",
|
"next" => "<b>test</b>",
|
||||||
|
@ -38,6 +42,7 @@ class GraphicalNavigationTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerTestIsNavLinkVisible
|
* @dataProvider providerTestIsNavLinkVisible
|
||||||
|
* @covers WidgetComicPressGraphicalStorylineNavigation::_will_display_nav_link
|
||||||
*/
|
*/
|
||||||
function testIsNavLinkVisible($which, $current_id, $target_id, $expected_result) {
|
function testIsNavLinkVisible($which, $current_id, $target_id, $expected_result) {
|
||||||
$current = (object)array('ID' => $current_id);
|
$current = (object)array('ID' => $current_id);
|
||||||
|
@ -45,6 +50,44 @@ class GraphicalNavigationTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
$this->assertEquals($expected_result, $this->w->_will_display_nav_link($which, $current, $target));
|
$this->assertEquals($expected_result, $this->w->_will_display_nav_link($which, $current, $target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function providerTestGroupNavigationButtons() {
|
||||||
|
return array(
|
||||||
|
array(array(), array()),
|
||||||
|
array(
|
||||||
|
array('one' => 'will be left'),
|
||||||
|
array(
|
||||||
|
'left' => array('one' => 'will be left')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array('four' => 'will be right'),
|
||||||
|
array(
|
||||||
|
'right' => array('four' => 'will be right')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array('seven' => 'will be center'),
|
||||||
|
array(
|
||||||
|
'center' => array('seven' => 'will be center')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerTestGroupNavigationButtons
|
||||||
|
* @covers WidgetComicPressGraphicalStorylineNavigation::_group_navigation_buttons
|
||||||
|
*/
|
||||||
|
function testGroupNavigationButtons($buttons, $expected_grouping) {
|
||||||
|
_set_filter_expectation('comicpress_navigation_grouping_details', array(
|
||||||
|
'left' => array('one', 'two', 'three'),
|
||||||
|
'center' => true,
|
||||||
|
'right' => array('four', 'five', 'six'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertEquals($expected_grouping, $this->w->_group_navigation_buttons($buttons, array()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -23,6 +23,7 @@ class WidgetComicPressGraphicalStorylineNavigation extends WP_Widget {
|
||||||
add_filter('comicpress_display_navigation_order', array(&$this, 'comicpress_display_navigation_order'));
|
add_filter('comicpress_display_navigation_order', array(&$this, 'comicpress_display_navigation_order'));
|
||||||
add_filter('comicpress_display_navigation_link', array(&$this, 'comicpress_display_navigation_link'), 10, 5);
|
add_filter('comicpress_display_navigation_link', array(&$this, 'comicpress_display_navigation_link'), 10, 5);
|
||||||
add_filter('comicpress_wrap_navigation_buttons', array(&$this, 'comicpress_wrap_navigation_buttons'), 10, 2);
|
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'));
|
||||||
|
|
||||||
// these two need to be moved one level up
|
// these two need to be moved one level up
|
||||||
add_filter('comicpress_get_random_link_url', array(&$this, 'comicpress_get_random_link_url'));
|
add_filter('comicpress_get_random_link_url', array(&$this, 'comicpress_get_random_link_url'));
|
||||||
|
@ -162,6 +163,42 @@ class WidgetComicPressGraphicalStorylineNavigation extends WP_Widget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function comicpress_navigation_grouping_details($details = array()) {
|
||||||
|
return array(
|
||||||
|
'comic_navi_left' => array('first', 'previous', 'story_prev_in', 'story_prev'),
|
||||||
|
'comic_navi_center' => true,
|
||||||
|
'comic_navi_right' => array('story_next', 'story_next_in', 'next', 'last')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _group_navigation_buttons($buttons = array(), $grouped_buttons = array()) {
|
||||||
|
$grouping_hash = array();
|
||||||
|
|
||||||
|
$default_group = null;
|
||||||
|
foreach (apply_filters('comicpress_navigation_grouping_details', array()) as $group => $members) {
|
||||||
|
if ($members === true) {
|
||||||
|
$default_group = $group;
|
||||||
|
} else {
|
||||||
|
foreach ($members as $member) { $grouping_hash[$member] = $group; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_null($default_group)) {
|
||||||
|
trigger_error('No default group defined for filter comicpress_navigation_grouping_details', E_USER_WARNING);
|
||||||
|
}
|
||||||
|
|
||||||
|
$groups = array();
|
||||||
|
foreach ($buttons as $key => $button) {
|
||||||
|
$group = isset($grouping_hash[$key]) ? $grouping_hash[$key] : $default_group;
|
||||||
|
if (!empty($group)) {
|
||||||
|
if (!isset($groups[$group])) { $groups[$group] = array(); }
|
||||||
|
$groups[$group][$key] = $button;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $groups;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap navigation buttons in a holder.
|
* Wrap navigation buttons in a holder.
|
||||||
* @param string|array $buttons The buttons to wrap.
|
* @param string|array $buttons The buttons to wrap.
|
||||||
|
@ -169,7 +206,14 @@ class WidgetComicPressGraphicalStorylineNavigation extends WP_Widget {
|
||||||
*/
|
*/
|
||||||
function comicpress_wrap_navigation_buttons($buttons = '', $content = '') {
|
function comicpress_wrap_navigation_buttons($buttons = '', $content = '') {
|
||||||
$buttons_text = $buttons;
|
$buttons_text = $buttons;
|
||||||
if (is_array($buttons)) { $buttons_text = implode('', $buttons); }
|
if (is_array($buttons)) {
|
||||||
|
$output = array();
|
||||||
|
foreach ($this->_group_navigation_buttons($buttons) as $group => $grouped_buttons) {
|
||||||
|
$output[] = '<div class="' . $group . '">' . implode('', array_values($grouped_buttons)) . '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$buttons_text = implode('', $output);
|
||||||
|
}
|
||||||
ob_start(); ?>
|
ob_start(); ?>
|
||||||
<div id="comic_navi_wrapper">
|
<div id="comic_navi_wrapper">
|
||||||
<div class="comic_navi"><?php echo $buttons_text; ?></div>
|
<div class="comic_navi"><?php echo $buttons_text; ?></div>
|
||||||
|
@ -214,7 +258,7 @@ class WidgetComicPressGraphicalStorylineNavigation extends WP_Widget {
|
||||||
$target_post = null;
|
$target_post = null;
|
||||||
if (isset($post_nav[$target_post_nav])) { $target_post = $post_nav[$target_post_nav]; }
|
if (isset($post_nav[$target_post_nav])) { $target_post = $post_nav[$target_post_nav]; }
|
||||||
|
|
||||||
$nav_links[] = end(apply_filters('comicpress_display_navigation_link', $order, $post, $target_post, $instance, ''));
|
$nav_links[$order] = end(apply_filters('comicpress_display_navigation_link', $order, $post, $target_post, $instance, ''));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue