backend filesystem code coveragae

This commit is contained in:
John Bintz 2009-11-24 18:49:32 -05:00
parent f1845daed5
commit 7afe5f7f83
3 changed files with 33 additions and 6 deletions

View File

@ -1,8 +1,11 @@
comicpress28 = $(realpath ../../themes/comicpress-2.8)
.PHONY : copy-storyline
.PHONY : copy-storyline test
copy-storyline :
ifdef comicpress28
cp classes/ComicPressDBInterface.inc classes/ComicPressNavigation.inc classes/ComicPressStoryline.inc $(comicpress28)/classes
endif
test:
taskset -c 1 phpunit --syntax-check --coverage-html coverage test

View File

@ -29,12 +29,18 @@ class ComicPressBackendFilesystem extends ComicPressBackend {
}
}
}
} while ($any_found);
}
// @codeCoverageIgnoreStart
while ($any_found);
// @codeCoverageIgnoreEnd
return $this->_searches;
}
// @codeCoverageIgnoreStart
function _replace_wordpress($post, $type) { return ABSPATH; }
// @codeCoverageIgnoreEnd
function _replace_type($post, $type) { return $type; }
function _replace_y_m_d($post, $type) { return date('Y-m-d', strtotime($post->post_date)); }
function _replace_year($post, $type) { return date('Y', strtotime($post->post_date)); }
@ -50,10 +56,14 @@ class ComicPressBackendFilesystem extends ComicPressBackend {
array_unshift($all_slugs, $category->slug);
$current_parent = $category->parent;
} else {
$all_slugs = array();
break;
}
}
} while ($keep_searching);
}
// @codeCoverageIgnoreStart
while ($keep_searching);
// @codeCoverageIgnoreEnd
$new_searches = array();
$slug_count = count($all_slugs);

View File

@ -15,6 +15,7 @@ class ComicPressBackendFilesystemTest extends PHPUnit_Framework_TestCase {
return array(
array('/comic/*.jpg', array('/comic/*.jpg')),
array('%wordpress%/comic/*.jpg', array('/wordpress/comic/*.jpg')),
array('%test%/comic/*.jpg', array('/comic/*.jpg')),
array('%wordpress%/%type%/*.jpg', array('/wordpress/comic/*.jpg')),
array('%wordpress%/comic/%y-m-d%*.jpg', array('/wordpress/comic/2009-01-01*.jpg')),
array('%wordpress%/comic/%year%/%y-m-d%*.jpg', array('/wordpress/comic/2009/2009-01-01*.jpg')),
@ -25,25 +26,38 @@ class ComicPressBackendFilesystemTest extends PHPUnit_Framework_TestCase {
'/wordpress/comic/parent/2009-01-01*.jpg',
)
),
array(
'%wordpress%/comic/%categories%/%y-m-d%*.jpg',
array(
'/wordpress/comic//2009-01-01*.jpg',
),
2
),
);
}
/**
* @dataProvider providerTestProcessSearchString
*/
function testProcessSearchString($string, $expected_searches) {
function testProcessSearchString($string, $expected_searches, $post_id_to_use = 1) {
$fs = $this->getMock('ComicPressBackendFilesystem', array('_replace_wordpress'));
$fs->expects($this->any())->method('_replace_wordpress')->will($this->returnValue('/wordpress'));
$post = (object)array('ID' => 1, 'post_date' => '2009-01-01');
$posts = array(
1 => (object)array('ID' => 1, 'post_date' => '2009-01-01'),
2 => (object)array('ID' => 2, 'post_date' => '2009-01-01'),
);
add_category(1, (object)array('slug' => 'parent', 'parent' => 0));
add_category(2, (object)array('slug' => 'child', 'parent' => 1));
add_category(4, (object)array('slug' => 'bad', 'parent' => 3));
wp_set_post_categories(1, array(2));
wp_set_post_categories(2, array(4));
$fs->search_string = $string;
$this->assertEquals($expected_searches, $fs->process_search_string($post, 'comic'));
$this->assertEquals($expected_searches, $fs->process_search_string($posts[$post_id_to_use], 'comic'));
}
}