works w/o specifying post

This commit is contained in:
John Bintz 2009-11-07 17:13:13 -05:00
parent 23be631fba
commit ca3299a01e
2 changed files with 24 additions and 0 deletions

View File

@ -1,5 +1,7 @@
<?php <?php
require_once(dirname(__FILE__) . '/ComicPressComicPost.inc');
/** /**
* The core functions of ComicPress. * The core functions of ComicPress.
*/ */
@ -135,6 +137,12 @@ class ComicPress {
* @return string|boolean The path to the file, for false if not found. * @return string|boolean The path to the file, for false if not found.
*/ */
function find_file($name, $path, $categories = null) { function find_file($name, $path, $categories = null) {
global $post;
if (!is_array($categories)) {
$comic_post = new ComicPressComicPost($post);
$categories = $comic_post->find_parents();
}
foreach (array(get_stylesheet_directory(), get_template_directory()) as $dir) { foreach (array(get_stylesheet_directory(), get_template_directory()) as $dir) {
$dir = trailingslashit($dir) . $path; $dir = trailingslashit($dir) . $path;
$dirs_to_search = $this->category_search($categories, $dir); $dirs_to_search = $this->category_search($categories, $dir);

View File

@ -76,6 +76,14 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
), ),
array('chapter-1', 'comic'), array('chapter-1', 'comic'),
vfsStream::url('root/child/partials/comic/index.inc') vfsStream::url('root/child/partials/comic/index.inc')
),
array(
array(
'root/child/partials/index.inc',
'root/child/partials/comic/index.inc'
),
null,
vfsStream::url('root/child/partials/comic/index.inc')
) )
); );
} }
@ -84,6 +92,8 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
* @dataProvider providerTestFindFile * @dataProvider providerTestFindFile
*/ */
function testFindFile($files_to_setup, $post_categories, $expected_path_result) { function testFindFile($files_to_setup, $post_categories, $expected_path_result) {
global $post;
mkdir(vfsStream::url('root/parent/partials/comic/chapter-1'), 0777, true); mkdir(vfsStream::url('root/parent/partials/comic/chapter-1'), 0777, true);
mkdir(vfsStream::url('root/child/partials/comic/chapter-1'), 0777, true); mkdir(vfsStream::url('root/child/partials/comic/chapter-1'), 0777, true);
@ -94,6 +104,12 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
_set_template_directory(vfsStream::url('root/parent')); _set_template_directory(vfsStream::url('root/parent'));
_set_stylesheet_directory(vfsStream::url('root/child')); _set_stylesheet_directory(vfsStream::url('root/child'));
$post = (object)array('ID' => 1);
wp_set_post_categories(1, array(2));
add_category(1, (object)array('slug' => 'comic', 'parent' => 0));
add_category(2, (object)array('slug' => 'chapter-1', 'parent' => 1));
$this->assertEquals($expected_path_result, $this->cp->find_file('index.inc', 'partials', $post_categories)); $this->assertEquals($expected_path_result, $this->cp->find_file('index.inc', 'partials', $post_categories));
} }
} }