From 6b0953f91b3a65650e28f0a04cb6448598055000 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 7 Nov 2009 16:36:57 -0500 Subject: [PATCH] comic path cascading working --- classes/ComicPress.inc | 12 ++++++++++++ test/ComicPressTest.php | 19 ++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc index 3f9a385..28aef09 100644 --- a/classes/ComicPress.inc +++ b/classes/ComicPress.inc @@ -125,6 +125,18 @@ class ComicPress { } return false; } + + function category_search($categories, $path) { + $path = trailingslashit($path); + $all_categories = array_reverse($categories); + $all_paths = array(); + while (count($all_categories) > 0) { + $target = $path . implode('/', $all_categories); + if (is_dir($target)) { $all_paths[] = $target; } + array_pop($all_categories); + } + return array_reverse($all_paths); + } } ?> \ No newline at end of file diff --git a/test/ComicPressTest.php b/test/ComicPressTest.php index 674f461..0eae06e 100644 --- a/test/ComicPressTest.php +++ b/test/ComicPressTest.php @@ -48,7 +48,19 @@ class ComicPressTest extends PHPUnit_Framework_TestCase { function providerTestCategorySearch() { return array( array( - + array('comic'), array(vfsStream::url('root/style/comic')) + ), + array( + array('chapter-1', 'comic'), array(vfsStream::url('root/style/comic'), vfsStream::url('root/style/comic/chapter-1')) + ), + array( + array('part-1', 'chapter-1', 'comic'), array(vfsStream::url('root/style/comic'), vfsStream::url('root/style/comic/chapter-1'), vfsStream::url('root/style/comic/chapter-1/part-1')) + ), + array( + array('comic', 'chapter-1'), array() + ), + array( + array(), array() ) ); } @@ -56,9 +68,10 @@ class ComicPressTest extends PHPUnit_Framework_TestCase { /** * @dataProvider providerTestCategorySearch */ - function testCategorySearch() { - mkdir(vfsStream::url('root/style/site/comic/chapter-1/part-1'), 0777, true); + function testCategorySearch($categories, $found_path) { + mkdir(vfsStream::url('root/style/comic/chapter-1/part-1'), 0777, true); + $this->assertEquals($found_path, $this->cp->category_search($categories, vfsStream::url('root/style'))); } }