more code coverage cleanups

This commit is contained in:
John Bintz 2009-11-11 08:46:26 -05:00
parent 510fadcf43
commit 843d3eb34c
4 changed files with 64 additions and 4 deletions

View File

@ -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('<img src="%s" alt="%s" title="%s" %s />', $this->url(), $this->alt(), $this->title(), implode(" ", $extras));
$output = sprintf('<img src="%s" alt="%s" title="%s" %s/>', $this->url(), $this->alt(), $this->title(), implode("", $extras));
return apply_filters('comicpress_embed_image', $output, $this);
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,45 @@
<?php
require_once('PHPUnit/Framework.php');
require_once('MockPress/mockpress.php');
require_once('ComicPressBackend.inc');
class ComicPressBackendTest extends PHPUnit_Framework_TestCase {
function providerTestEmbedImage() {
return array(
array(
false, array(
'#^<img src="http://comic" alt="alt" title="title" />$#'
)
),
array(
array(), array(
'#^<img src="http://comic" alt="alt" title="title" />$#'
)
),
array(
array('width' => 320, 'height' => 240), array(
'#^<img src="http://comic" alt="alt" title="title" width="320" height="240" />$#'
)
),
);
}
/**
* @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);
}
}
}

View File

@ -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();