From c781cab239409f3c8a7d01e5eb4fc2e77da63f8a Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 10 Feb 2010 18:31:31 -0500 Subject: [PATCH] working on actually getting this thing working --- classes/ComicPressDBInterface.inc | 5 ++--- classes/ComicPressTagBuilder.inc | 8 +++++++- comicpress-core.php | 6 ++++++ test/ComicPressTagBuilderTest.php | 12 ++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/classes/ComicPressDBInterface.inc b/classes/ComicPressDBInterface.inc index 47d0194..61d6d4d 100644 --- a/classes/ComicPressDBInterface.inc +++ b/classes/ComicPressDBInterface.inc @@ -45,15 +45,14 @@ class ComicPressDBInterface { $this->_prepare_wp_query(); if (!is_array($categories)) { $categories = array($categories); } - $sort_order = $first ? "asc" : "desc"; $terminal_comic_query = new WP_Query(); $terminal_comic_query->query(array( 'showposts' => 1, 'order' => $sort_order, - 'category__in' => $categories, - 'status' => 'publish' + 'category__in' => $categories )); + $post = false; if ($terminal_comic_query->have_posts()) { $post = reset($terminal_comic_query->posts); diff --git a/classes/ComicPressTagBuilder.inc b/classes/ComicPressTagBuilder.inc index 4183dbe..f4c64a3 100644 --- a/classes/ComicPressTagBuilder.inc +++ b/classes/ComicPressTagBuilder.inc @@ -112,7 +112,13 @@ class ComicPressTagBuilder { switch ($method) { case 'setup': - if (empty($this->post)) { throw new Exception('You need to have retrieved a post for setup to work'); } + if (empty($this->post)) { + if (isset($arguments[0])) { + throw new ComicPressException('You need to have retrieved a post for setup to work'); + } else { + return false; + } + } $this->_setup_postdata($this->post); return $this->post; case 'from': diff --git a/comicpress-core.php b/comicpress-core.php index 16baa16..6e472cc 100644 --- a/comicpress-core.php +++ b/comicpress-core.php @@ -31,6 +31,8 @@ add_action('init', '__comicpress_init'); // @codeCoverageIgnoreStart function __comicpress_init() { + global $core; + $classes_search = array( '/classes/', '/classes/backends/' ); @@ -47,4 +49,8 @@ function __comicpress_init() { $comicpress_admin = new ComicPressAdmin(); $comicpress_admin->init(); $comicpress_admin->handle_update(); + + if (!is_admin()) { + $core = new ComicPressTagBuilderFactory(); + } } diff --git a/test/ComicPressTagBuilderTest.php b/test/ComicPressTagBuilderTest.php index e017d15..4b9a50e 100644 --- a/test/ComicPressTagBuilderTest.php +++ b/test/ComicPressTagBuilderTest.php @@ -523,6 +523,18 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase { ComicPress::get_instance(true); } + /** + * @expectedException ComicPressException + */ + function testSetupEmptyPostException() { + $core = new ComicPressTagBuilderFactory(); + unset($core->post); + + $this->assertTrue(false === $core->setup()); + + $core->setup(true); + } + function providerTestProtect() { return array( array(null, 'test'),