work on db interface

This commit is contained in:
John Bintz 2009-10-19 22:20:25 -04:00
parent 975f8c9b4b
commit 2517034936
2 changed files with 27 additions and 13 deletions

View File

@ -8,16 +8,15 @@ class ComicPressDBInterface {
function get_instance() {
static $instance;
if (!isset($instance)) {
$instance = new ComicPressDBInterface();
}
if (!isset($instance)) { $instance = new ComicPressDBInterface(); }
return $instance;
}
function _get_categories() {
return get_categories("hide_empty=0");
}
function _get_categories() { return get_categories("hide_empty=0"); }
/**
* Set the comic categories for the current run of ComicPress.
*/
function set_comic_categories($categories) {
$this->_non_comic_categories = array();
$this->_all_categories = array();
@ -28,6 +27,10 @@ class ComicPressDBInterface {
$this->_non_comic_categories = array_values(array_diff($this->_all_categories, $categories));
}
function _get_categories_to_exclude($category = null) {
return (is_null($category)) ? $this->_non_comic_categories : array_values(array_diff($this->_all_categories, array($category)));
}
/**
* Find the terminal post in a specific category.
*/
@ -68,11 +71,6 @@ class ComicPressDBInterface {
$post = $override_post;
}
$categories_to_exclude = $this->get_leaves_of_tree($this->non_comic_categories);
if (!is_null($category)) {
$categories_to_exclude = $this->exclude_all_but_provided_categories($category);
}
$result = get_adjacent_post(false, implode(" and ", $categories_to_exclude), !$next);
$wp_query->is_single = $temp;
@ -93,8 +91,6 @@ class ComicPressDBInterface {
* Get the next comic from the current one.
*/
function get_next_comic($category = null, $override_post = null) { return $this->get_adjacent_comic($category, true, $override_post); }
}
?>

View File

@ -30,6 +30,24 @@ class ComicPressDBInterfaceTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(array(1,2,3,4), $dbi->_all_categories);
$this->assertEquals(array(1,4), $dbi->_non_comic_categories);
}
function providerTestGetCategoriesToExclude() {
return array(
array(null, array(1 ,4)),
array(2, array(1, 3, 4)),
);
}
/**
* @dataProvider providerTestGetCategoriesToExclude
*/
function testGetCategoriesToExclude($category, $expected_results) {
$dbi = ComicPressDBInterface::get_instance();
$dbi->_all_categories = array(1,2,3,4);
$dbi->_non_comic_categories = array(1,4);
$this->assertEquals($expected_results, $dbi->_get_categories_to_exclude($category));
}
}
?>