From 843d3eb34ce4f22ec531ba2569fd13bcc3414a1b Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 11 Nov 2009 08:46:26 -0500 Subject: [PATCH] more code coverage cleanups --- classes/ComicPressBackend.inc | 12 ++++++--- classes/ComicPressNavigation.inc | 3 +++ test/ComicPressBackendTest.php | 45 +++++++++++++++++++++++++++++++ test/ComicPressNavigationTest.php | 8 ++++++ 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 test/ComicPressBackendTest.php diff --git a/classes/ComicPressBackend.inc b/classes/ComicPressBackend.inc index 7ddd7ff..e494dc6 100644 --- a/classes/ComicPressBackend.inc +++ b/classes/ComicPressBackend.inc @@ -3,15 +3,19 @@ class ComicPressBackend { function _embed_image($size) { $extras = array(); - if (($dims = $this->dims($size)) !== false) { - $extras = array_merge($extras, $dims); + $dims = $this->dims($size); + if (!empty($dims)) { + if (is_array($dims)) { + $extras = array_merge($extras, $dims); + } } + foreach ($extras as $field => $value) { - $extras[] = "${field}=\"${value}\""; + $extras[] = "${field}=\"${value}\" "; unset($extras[$field]); } - $output = sprintf('%s', $this->url(), $this->alt(), $this->title(), implode(" ", $extras)); + $output = sprintf('%s', $this->url(), $this->alt(), $this->title(), implode("", $extras)); return apply_filters('comicpress_embed_image', $output, $this); } } \ No newline at end of file diff --git a/classes/ComicPressNavigation.inc b/classes/ComicPressNavigation.inc index 31288a9..a025259 100644 --- a/classes/ComicPressNavigation.inc +++ b/classes/ComicPressNavigation.inc @@ -4,10 +4,12 @@ require_once('ComicPressStoryline.inc'); require_once('ComicPressDBInterface.inc'); class ComicPressNavigation { + // @codeCoverageIgnoreStart function init($storyline) { $this->_storyline = $storyline; $this->_dbi = ComicPressDBInterface::get_instance(); } + // @codeCoverageIgnoreEnd function get_post_nav($post) { $nav = array(); @@ -61,6 +63,7 @@ class ComicPressNavigation { return $nav; } } + return false; } } diff --git a/test/ComicPressBackendTest.php b/test/ComicPressBackendTest.php new file mode 100644 index 0000000..b9f341e --- /dev/null +++ b/test/ComicPressBackendTest.php @@ -0,0 +1,45 @@ +$#' + ) + ), + array( + array(), array( + '#^alt$#' + ) + ), + array( + array('width' => 320, 'height' => 240), array( + '#^alt$#' + ) + ), + ); + } + + /** + * @dataProvider providerTestEmbedImage + */ + function testEmbedImage($dims_result, $expected_result_patterns) { + $backend = $this->getMock('ComicPressBackend', array('dims', 'url', 'alt', 'title')); + + $backend->expects($this->once())->method('dims')->with('comic')->will($this->returnValue($dims_result)); + $backend->expects($this->once())->method('url')->will($this->returnValue('http://comic')); + $backend->expects($this->once())->method('alt')->will($this->returnValue('alt')); + $backend->expects($this->once())->method('title')->will($this->returnValue('title')); + + $result = $backend->_embed_image('comic'); + + foreach ($expected_result_patterns as $pattern) { + $this->assertTrue(preg_match($pattern, $result) > 0); + } + } +} \ No newline at end of file diff --git a/test/ComicPressNavigationTest.php b/test/ComicPressNavigationTest.php index 7579fe1..24da147 100644 --- a/test/ComicPressNavigationTest.php +++ b/test/ComicPressNavigationTest.php @@ -13,6 +13,14 @@ class ComicPressNavigationTest extends PHPUnit_Framework_TestCase { $this->nav = new ComicPressNavigation(); } + function testGetPostNavNotAPost() { + $this->assertTrue($this->nav->get_post_nav(false) === false); + } + + function testGetPostNavFromCache() { + $this->markTestIncomplete(); + } + function testGetPostNav() { $dbi = $this->getMock('ComicPressDBInterface', array('get_previous_comic', 'get_next_comic', 'get_first_comic', 'get_last_comic')); $storyline = new ComicPressStoryline();