From 28d631c1ba9d480159329879c0cb5af41cefc1f1 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 25 Nov 2009 14:22:09 -0500 Subject: [PATCH] code coverage for F() --- classes/ComicPress.inc | 8 ++++++-- functions.inc | 2 -- test/FunctionsTest.php | 31 +++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc index 5c971cb..d5cda14 100644 --- a/classes/ComicPress.inc +++ b/classes/ComicPress.inc @@ -35,10 +35,14 @@ class ComicPress { var $backends = array(); - function &get_instance() { + function &get_instance($force = false) { static $instance; - if (!$instance) { + if (is_object($force)) { + $instance = array($force); + } + + if (!$instance || ($force === true)) { $instance = array(new ComicPress()); } diff --git a/functions.inc b/functions.inc index ff9dcb3..4af8df2 100644 --- a/functions.inc +++ b/functions.inc @@ -23,7 +23,6 @@ foreach (array( // Global template functions for ComicPress -// @codeCoverageIgnoreStart function F($name, $path, $override_post = null) { global $post; @@ -32,7 +31,6 @@ function F($name, $path, $override_post = null) { $comicpress = ComicPress::get_instance(); return $comicpress->find_file($name, $path, $comic_post->find_parents()); } -// @codeCoverageIgnoreEnd /** * Protect global $post and $wp_query. diff --git a/test/FunctionsTest.php b/test/FunctionsTest.php index c3d07ef..73d149e 100644 --- a/test/FunctionsTest.php +++ b/test/FunctionsTest.php @@ -258,4 +258,35 @@ class FunctionsTest extends PHPUnit_Framework_TestCase { $this->assertEquals($expected_result, In_R()); } + + 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); + } }