From ce6912c24eb7d364afb894189a24f3eb2108cf29 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 4 Feb 2010 22:31:30 -0500 Subject: [PATCH] more coverage stuff --- classes/ComicPress.inc | 28 ---------------------------- classes/ComicPressTagBuilder.inc | 5 +++++ functions.inc | 12 ------------ test/ComicPressTagBuilderTest.php | 17 +++++++++++++++++ test/ComicPressTest.php | 4 ++++ test/FunctionsTest.php | 31 ------------------------------- 6 files changed, 26 insertions(+), 71 deletions(-) diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc index efca825..7b303f1 100644 --- a/classes/ComicPress.inc +++ b/classes/ComicPress.inc @@ -209,34 +209,6 @@ class ComicPress { return $available_backends; } - // @codeCoverageIgnoreStart - - function announce_activated_helpers() { - echo "
[ Activated ComicPress helpers: " . implode(", ", array_keys($this->comicpress_options['helpers'])) . " ]
"; - } - /** - * Gather blog posts for the given index page. - */ - function get_index_blog_posts_query() { - global $post, $paged; - - $t = $post; - - $wp_query = new WP_Query(); - $wp_query->query( - 'showposts=' . - (int)$this->comicpress_options['blogpost_count'] . - '&cat=-' . - $this->comicpress_options['comic_category_id'] . - '&paged=' . - $paged - ); - - return $wp_query; - } - - // @codeCoverageIgnoreEnd - /** * Search a path for directories named after the slugs provided. * @param array $categories A list of category slugs going from child -> parent -> root. diff --git a/classes/ComicPressTagBuilder.inc b/classes/ComicPressTagBuilder.inc index 21be199..a3234e4 100644 --- a/classes/ComicPressTagBuilder.inc +++ b/classes/ComicPressTagBuilder.inc @@ -40,6 +40,11 @@ class ComicPressTagBuilderFactory { return $is_in; } + + public function find_file($name, $path = '', $categories = null) { + $comicpress = ComicPress::get_instance(); + return $comicpress->find_file($name, $path, $categories); + } } class ComicPressTagBuilder { diff --git a/functions.inc b/functions.inc index 534f088..bdf076e 100644 --- a/functions.inc +++ b/functions.inc @@ -1,7 +1,6 @@ 3, 'Protect' => 0, 'Restore' => 0, 'Unprotect' => 0, @@ -13,17 +12,6 @@ foreach (array( } } -// Global template functions for ComicPress -// TODO is this even necessary anymore? -function F($name, $path, $override_post = null) { - global $post; - - $comic_post = new ComicPressComicPost(is_null($override_post) ? $post : $override_post); - - $comicpress = ComicPress::get_instance(); - return $comicpress->find_file($name, $path, $comic_post->find_parents()); -} - /** * Protect global $post and $wp_query. * @param object $use_this_post If provided, after saving the current post, set up this post for template tag use. diff --git a/test/ComicPressTagBuilderTest.php b/test/ComicPressTagBuilderTest.php index 0bad75e..bfd19a9 100644 --- a/test/ComicPressTagBuilderTest.php +++ b/test/ComicPressTagBuilderTest.php @@ -505,4 +505,21 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase { } } } + + function testFindFilePassthru() { + $dbi = $this->getMock('ComicPressDBInterface'); + $core = new ComicPressTagBuilderFactory($dbi); + + $comicpress = $this->getMock('ComicPress', array('find_file')); + $comicpress->expects($this->once()) + ->method('find_file') + ->with('name', 'path', 'categories') + ->will($this->returnValue('file')); + + ComicPress::get_instance($comicpress); + + $this->assertEquals('file', $core->find_file('name', 'path', 'categories')); + + ComicPress::get_instance(true); + } } diff --git a/test/ComicPressTest.php b/test/ComicPressTest.php index c11cf09..9bdc167 100644 --- a/test/ComicPressTest.php +++ b/test/ComicPressTest.php @@ -363,4 +363,8 @@ class ComicPressTest extends PHPUnit_Framework_TestCase { $this->assertEquals($expected_backends, $cp->comicpress_options['enabled_backends']); } + + function testGetInstanceObjectOverride() { + $this->assertEquals((object)array(), ComicPress::get_instance((object)array())); + } } diff --git a/test/FunctionsTest.php b/test/FunctionsTest.php index 2d7695a..0a6ed60 100644 --- a/test/FunctionsTest.php +++ b/test/FunctionsTest.php @@ -60,35 +60,4 @@ class FunctionsTest extends PHPUnit_Framework_TestCase { $this->assertTrue(is_null($__post)); $this->assertTrue(is_null($__wp_query)); } - - function providerTestF() { - return array( - array(null, array(1 => 'one')), - array((object)array('ID' => 2), array(2 => 'two')) - ); - } - - /** - * @dataProvider providerTestF - */ - function testF($post_to_use, $expected_parents) { - global $post; - - $post = (object)array('ID' => 1); - - add_category(1, (object)array('slug' => 'one')); - add_category(2, (object)array('slug' => 'two')); - - wp_set_post_categories(1, array(1)); - wp_set_post_categories(2, array(2)); - - $comicpress = $this->getMock('ComicPress', array('find_file')); - $comicpress->expects($this->once())->method('find_file')->with('name', 'path', $expected_parents)->will($this->returnValue('done')); - - ComicPress::get_instance($comicpress); - - $this->assertEquals('done', F('name', 'path', $post_to_use)); - - ComicPress::get_instance(true); - } }