start integration testing on nav building
This commit is contained in:
parent
8b63f3a1fd
commit
1db0f884f3
@ -18,12 +18,7 @@ class ComicPressDBInterface {
|
|||||||
* Set the comic categories for the current run of ComicPress.
|
* Set the comic categories for the current run of ComicPress.
|
||||||
*/
|
*/
|
||||||
function set_comic_categories($categories) {
|
function set_comic_categories($categories) {
|
||||||
$this->_non_comic_categories = array();
|
$this->_all_categories = get_all_category_ids();
|
||||||
$this->_all_categories = array();
|
|
||||||
foreach ($this->_get_categories() as $category_object) {
|
|
||||||
$this->_all_categories[] = $category_object->term_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_non_comic_categories = array_values(array_diff($this->_all_categories, $categories));
|
$this->_non_comic_categories = array_values(array_diff($this->_all_categories, $categories));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,10 +55,11 @@ class ComicPressDBInterface {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the comic post adjacent to the current comic.
|
* Get the comic post adjacent to the current comic.
|
||||||
|
* Wrapper around get_adjacent_post(). Don't unit test this method.
|
||||||
*/
|
*/
|
||||||
function get_adjacent_comic($category, $next = false, $override_post = null) {
|
function get_adjacent_comic($category, $next = false, $override_post = null) {
|
||||||
global $wp_query, $post;
|
global $wp_query, $post;
|
||||||
$temp = $wp_query->is_single;
|
$temp_single = $wp_query->is_single;
|
||||||
$wp_query->is_single = true;
|
$wp_query->is_single = true;
|
||||||
|
|
||||||
if (!is_null($override_post)) {
|
if (!is_null($override_post)) {
|
||||||
@ -71,9 +67,9 @@ class ComicPressDBInterface {
|
|||||||
$post = $override_post;
|
$post = $override_post;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = get_adjacent_post(false, implode(" and ", $categories_to_exclude), !$next);
|
$result = get_adjacent_post(false, implode(" and ", $this->_get_categories_to_exclude($category)), !$next);
|
||||||
|
|
||||||
$wp_query->is_single = $temp;
|
$wp_query->is_single = $temp_single;
|
||||||
|
|
||||||
if (!is_null($override_post)) {
|
if (!is_null($override_post)) {
|
||||||
$post = $temp_post;
|
$post = $temp_post;
|
||||||
|
@ -1,7 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class ComicPressNavigation {
|
require_once('ComicPressStoryline.inc');
|
||||||
|
require_once('ComicPressDBInterface.inc');
|
||||||
|
|
||||||
|
class ComicPressNavigation {
|
||||||
|
function init($storyline) {
|
||||||
|
$this->_storyline = $storyline;
|
||||||
|
$this->_dbi = ComicPressDBInterface::get_instance();
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_post_nav($post) {
|
||||||
|
$nav = array();
|
||||||
|
|
||||||
|
// post
|
||||||
|
foreach (array('previous', 'next') as $field) {
|
||||||
|
$nav[$field] = $this->_dbi->{"get_${field}_comic"}(null, $post);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -16,14 +16,9 @@ class ComicPressDBInterfaceTest extends PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testSetComicCategories() {
|
function testSetComicCategories() {
|
||||||
$dbi = $this->getMock('ComicPressDBInterface', array('_get_categories'));
|
$dbi = ComicPressDBInterface::get_instance();
|
||||||
|
|
||||||
$dbi->expects($this->once())->method('_get_categories')->will($this->returnValue(array(
|
for ($i = 1; $i <= 4; ++$i) { add_category($i, (object)array()); }
|
||||||
(object)array('term_id' => 1),
|
|
||||||
(object)array('term_id' => 2),
|
|
||||||
(object)array('term_id' => 3),
|
|
||||||
(object)array('term_id' => 4)
|
|
||||||
)));
|
|
||||||
|
|
||||||
$dbi->set_comic_categories(array(2,3));
|
$dbi->set_comic_categories(array(2,3));
|
||||||
|
|
||||||
|
@ -4,14 +4,29 @@ require_once('MockPress/mockpress.php');
|
|||||||
require_once('PHPUnit/Framework.php');
|
require_once('PHPUnit/Framework.php');
|
||||||
require_once(dirname(__FILE__) . '/../classes/ComicPressNavigation.inc');
|
require_once(dirname(__FILE__) . '/../classes/ComicPressNavigation.inc');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integration Testing. Just make sure things are called correctly.
|
||||||
|
*/
|
||||||
class ComicPressNavigationTest extends PHPUnit_Framework_TestCase {
|
class ComicPressNavigationTest extends PHPUnit_Framework_TestCase {
|
||||||
function setUp() {
|
function setUp() {
|
||||||
_reset_wp();
|
_reset_wp();
|
||||||
$this->nav = new ComicPressNavigation();
|
$this->nav = new ComicPressNavigation();
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSomething() {
|
function testGetPostNav() {
|
||||||
$this->markTestIncomplete();
|
$dbi = $this->getMock('ComicPressDBInterface', array('get_previous_comic', 'get_next_comic'));
|
||||||
|
|
||||||
|
wp_insert_post(array('ID' => 1));
|
||||||
|
$post = get_post(1);
|
||||||
|
|
||||||
|
wp_set_post_categories(1, array(1));
|
||||||
|
|
||||||
|
$dbi->expects($this->once())->method('get_previous_comic')->with(null, $post);
|
||||||
|
$dbi->expects($this->once())->method('get_next_comic')->with(null, $post);
|
||||||
|
|
||||||
|
$this->nav->_dbi = $dbi;
|
||||||
|
|
||||||
|
$this->nav->get_post_nav($post);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user