comic path cascading working

This commit is contained in:
John Bintz 2009-11-07 16:36:57 -05:00
parent c078f0cc53
commit 6b0953f91b
2 changed files with 28 additions and 3 deletions

View File

@ -125,6 +125,18 @@ class ComicPress {
} }
return false; 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);
}
} }
?> ?>

View File

@ -48,7 +48,19 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
function providerTestCategorySearch() { function providerTestCategorySearch() {
return array( return array(
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 * @dataProvider providerTestCategorySearch
*/ */
function testCategorySearch() { function testCategorySearch($categories, $found_path) {
mkdir(vfsStream::url('root/style/site/comic/chapter-1/part-1'), 0777, true); 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')));
} }
} }