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.
|
||||
*/
|
||||
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";
|
||||
$terminal_comic_query =$this->_new_wp_query();
|
||||
$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.
|
||||
*/
|
||||
function get_first_comic() {
|
||||
return $this->get_terminal_post_in_category($category);
|
||||
function get_first_comic($category_id = null) {
|
||||
return $this->get_terminal_post_in_category($category_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last comic in a category.
|
||||
*/
|
||||
function get_last_comic($category) {
|
||||
return $this->get_terminal_post_in_category($category, false);
|
||||
function get_last_comic($category_id = null) {
|
||||
return $this->get_terminal_post_in_category($category_id, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -375,6 +376,21 @@ class ComicPress {
|
|||
}
|
||||
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(
|
||||
array(
|
||||
array(
|
||||
'1' => array(
|
||||
'first' => 8,
|
||||
'previous' => 9,
|
||||
'next' => 11,
|
||||
'last' => 12
|
||||
),
|
||||
'2' => array(
|
||||
'first' => 10,
|
||||
'previous' => false,
|
||||
'next' => 15,
|
||||
'last' => 15
|
||||
),
|
||||
'3' => array(
|
||||
'first' => 20,
|
||||
'previous' => 20,
|
||||
'next' => false,
|
||||
'last' => 21
|
||||
)
|
||||
)
|
||||
'0/1'
|
||||
),
|
||||
1,
|
||||
array()
|
||||
),
|
||||
array(
|
||||
'1' => array(
|
||||
'first' => true,
|
||||
'previous' => true,
|
||||
'next' => true,
|
||||
'last' => true
|
||||
array(
|
||||
'0/1',
|
||||
'0/1/2'
|
||||
),
|
||||
'2' => array(
|
||||
'first' => true,
|
||||
'previous' => false,
|
||||
'next' => false,
|
||||
'last' => true
|
||||
2,
|
||||
array()
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'0/1',
|
||||
'0/1/2',
|
||||
'0/1/3',
|
||||
),
|
||||
'3' => array(
|
||||
'first' => true,
|
||||
'previous' => false,
|
||||
'next' => false,
|
||||
'last' => true
|
||||
2,
|
||||
array(
|
||||
'1' => array('next' => 3)
|
||||
)
|
||||
)
|
||||
);
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestGetStorylineNavComics
|
||||
* @dataProvider providerTestGetPreviousNextCategories
|
||||
*/
|
||||
function testGetStorylineNavComics($category_info, $expected_category_results) {
|
||||
$cp = $this->getMock('ComicPress', array('get_first_comic', 'get_last_comic', 'get_previous_comic', 'get_next_comic'));
|
||||
foreach ($category_info as $category => $nav_comics) {
|
||||
foreach ($nav_comics as $key => $result) {
|
||||
$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 testGetPreviousNextCategories($category_tree, $current_category, $expected_prev_nexts) {
|
||||
$this->cp->category_tree = $category_tree;
|
||||
|
||||
$this->assertEquals($expected_prev_nexts, $this->cp->get_previous_next_categories($current_category));
|
||||
}
|
||||
|
||||
|
||||
function providerTestGetLayoutChoices() {
|
||||
return array(
|
||||
|
|
Loading…
Reference in New Issue