working on unit tests for previous/next categories
This commit is contained in:
parent
2e7028a72e
commit
abcfc8ca2d
|
@ -196,7 +196,8 @@ class ComicPress {
|
||||||
/**
|
/**
|
||||||
* Find the terminal post in a specific category.
|
* Find the terminal post in a specific category.
|
||||||
*/
|
*/
|
||||||
function get_terminal_post_in_category($category_id, $first = true) {
|
function get_terminal_post_in_category($category_id = null, $first = true) {
|
||||||
|
$category_id = is_null($category_id) ? $this->comicpress_options['comic_category_id'] : $category_id;
|
||||||
$sort_order = $first ? "asc" : "desc";
|
$sort_order = $first ? "asc" : "desc";
|
||||||
$terminal_comic_query =$this->_new_wp_query();
|
$terminal_comic_query =$this->_new_wp_query();
|
||||||
$terminal_comic_query->query("showposts=1&order=${sort_order}&cat=${category_id}&status=publish");
|
$terminal_comic_query->query("showposts=1&order=${sort_order}&cat=${category_id}&status=publish");
|
||||||
|
@ -209,15 +210,15 @@ class ComicPress {
|
||||||
/**
|
/**
|
||||||
* Get the first comic in a category.
|
* Get the first comic in a category.
|
||||||
*/
|
*/
|
||||||
function get_first_comic() {
|
function get_first_comic($category_id = null) {
|
||||||
return $this->get_terminal_post_in_category($category);
|
return $this->get_terminal_post_in_category($category_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the last comic in a category.
|
* Get the last comic in a category.
|
||||||
*/
|
*/
|
||||||
function get_last_comic($category) {
|
function get_last_comic($category_id = null) {
|
||||||
return $this->get_terminal_post_in_category($category, false);
|
return $this->get_terminal_post_in_category($category_id, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -375,6 +376,21 @@ class ComicPress {
|
||||||
}
|
}
|
||||||
return $this->layouts;
|
return $this->layouts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_previous_next_categories($category_id) {
|
||||||
|
$prev_next_categories = array();
|
||||||
|
|
||||||
|
for ($i = 0, $il < count($this->category_tree); $i < $il; ++$i) {
|
||||||
|
$parts = explode("/", $this->category_tree);
|
||||||
|
if (count($parts) > 2) {
|
||||||
|
if (end($parts) == $category_id) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $prev_next_categories;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -172,75 +172,45 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function providerTestGetStorylineNavComics() {
|
function providerTestGetPreviousNextCategories() {
|
||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
'1' => array(
|
'0/1'
|
||||||
'first' => 8,
|
|
||||||
'previous' => 9,
|
|
||||||
'next' => 11,
|
|
||||||
'last' => 12
|
|
||||||
),
|
),
|
||||||
'2' => array(
|
1,
|
||||||
'first' => 10,
|
array()
|
||||||
'previous' => false,
|
|
||||||
'next' => 15,
|
|
||||||
'last' => 15
|
|
||||||
),
|
|
||||||
'3' => array(
|
|
||||||
'first' => 20,
|
|
||||||
'previous' => 20,
|
|
||||||
'next' => false,
|
|
||||||
'last' => 21
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'1' => array(
|
array(
|
||||||
'first' => true,
|
'0/1',
|
||||||
'previous' => true,
|
'0/1/2'
|
||||||
'next' => true,
|
|
||||||
'last' => true
|
|
||||||
),
|
),
|
||||||
'2' => array(
|
2,
|
||||||
'first' => true,
|
array()
|
||||||
'previous' => false,
|
|
||||||
'next' => false,
|
|
||||||
'last' => true
|
|
||||||
),
|
),
|
||||||
'3' => array(
|
array(
|
||||||
'first' => true,
|
array(
|
||||||
'previous' => false,
|
'0/1',
|
||||||
'next' => false,
|
'0/1/2',
|
||||||
'last' => true
|
'0/1/3',
|
||||||
)
|
),
|
||||||
|
2,
|
||||||
|
array(
|
||||||
|
'1' => array('next' => 3)
|
||||||
)
|
)
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerTestGetStorylineNavComics
|
* @dataProvider providerTestGetPreviousNextCategories
|
||||||
*/
|
*/
|
||||||
function testGetStorylineNavComics($category_info, $expected_category_results) {
|
function testGetPreviousNextCategories($category_tree, $current_category, $expected_prev_nexts) {
|
||||||
$cp = $this->getMock('ComicPress', array('get_first_comic', 'get_last_comic', 'get_previous_comic', 'get_next_comic'));
|
$this->cp->category_tree = $category_tree;
|
||||||
foreach ($category_info as $category => $nav_comics) {
|
|
||||||
foreach ($nav_comics as $key => $result) {
|
$this->assertEquals($expected_prev_nexts, $this->cp->get_previous_next_categories($current_category));
|
||||||
$return = (is_numeric($result)) ? (object)array('ID' => $result) : false;
|
|
||||||
$cp->expects($this->once())->method("get_${key}_comic")->with($category)->will($this->returnValue($return));
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$post = (is_numeric($given_post)) ? (object)array('ID' => $given_post) : false;
|
|
||||||
|
|
||||||
$comic_posts = $cp->get_nav_comics();
|
|
||||||
|
|
||||||
foreach ($expected_shows as $show => $expected) {
|
|
||||||
$this->assertEquals($expected, $comic_posts["show_${show}"], $show);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function providerTestGetLayoutChoices() {
|
function providerTestGetLayoutChoices() {
|
||||||
return array(
|
return array(
|
||||||
|
|
Loading…
Reference in New Issue