From 7afe5f7f834510f561c724957c2b4ba138ef071c Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 24 Nov 2009 18:49:32 -0500 Subject: [PATCH] backend filesystem code coveragae --- Makefile | 5 ++++- .../backends/ComicPressBackendFilesystem.inc | 14 +++++++++++-- .../ComicPressBackendFilesystemTest.php | 20 ++++++++++++++++--- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 81d204b..ba9b5ee 100644 --- a/Makefile +++ b/Makefile @@ -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 \ No newline at end of file diff --git a/classes/backends/ComicPressBackendFilesystem.inc b/classes/backends/ComicPressBackendFilesystem.inc index 457a887..f65e07a 100644 --- a/classes/backends/ComicPressBackendFilesystem.inc +++ b/classes/backends/ComicPressBackendFilesystem.inc @@ -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); diff --git a/test/backends/ComicPressBackendFilesystemTest.php b/test/backends/ComicPressBackendFilesystemTest.php index 05696b9..527908e 100644 --- a/test/backends/ComicPressBackendFilesystemTest.php +++ b/test/backends/ComicPressBackendFilesystemTest.php @@ -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')); } } \ No newline at end of file