make sure no path works
This commit is contained in:
parent
fbdacf3322
commit
0cad4b0d53
|
@ -136,7 +136,7 @@ class ComicPress {
|
||||||
* @param attay $categories The child -> root category slugs to search within the specified path. If not provided, retrieve from current post.
|
* @param attay $categories The child -> root category slugs to search within the specified path. If not provided, retrieve from current post.
|
||||||
* @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;
|
global $post;
|
||||||
if (!is_array($categories)) {
|
if (!is_array($categories)) {
|
||||||
$comic_post = new ComicPressComicPost($post);
|
$comic_post = new ComicPressComicPost($post);
|
||||||
|
|
|
@ -46,26 +46,35 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
|
||||||
function providerTestFindFile() {
|
function providerTestFindFile() {
|
||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
array(), array(), false,
|
array(), 'partials', array(), false,
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
array('root/parent/partials/index.inc'),
|
array('root/parent/partials/index.inc'),
|
||||||
|
'partials',
|
||||||
array(),
|
array(),
|
||||||
vfsStream::url('root/parent/partials/index.inc')
|
vfsStream::url('root/parent/partials/index.inc')
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
array('root/parent/index.inc'),
|
||||||
|
'',
|
||||||
|
array(),
|
||||||
|
vfsStream::url('root/parent/index.inc')
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
'root/parent/partials/index.inc',
|
'root/parent/partials/index.inc',
|
||||||
'root/child/partials/index.inc'
|
'root/child/partials/index.inc'
|
||||||
),
|
),
|
||||||
array(),
|
'partials',
|
||||||
|
array(),
|
||||||
vfsStream::url('root/child/partials/index.inc')
|
vfsStream::url('root/child/partials/index.inc')
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
'root/child/partials/index.inc',
|
'root/child/partials/index.inc',
|
||||||
'root/child/partials/comic/index.inc'
|
'root/child/partials/comic/index.inc'
|
||||||
),
|
),
|
||||||
|
'partials',
|
||||||
array('comic'),
|
array('comic'),
|
||||||
vfsStream::url('root/child/partials/comic/index.inc')
|
vfsStream::url('root/child/partials/comic/index.inc')
|
||||||
),
|
),
|
||||||
|
@ -73,7 +82,8 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
|
||||||
array(
|
array(
|
||||||
'root/child/partials/index.inc',
|
'root/child/partials/index.inc',
|
||||||
'root/child/partials/comic/index.inc'
|
'root/child/partials/comic/index.inc'
|
||||||
),
|
),
|
||||||
|
'partials',
|
||||||
array('chapter-1', 'comic'),
|
array('chapter-1', 'comic'),
|
||||||
vfsStream::url('root/child/partials/comic/index.inc')
|
vfsStream::url('root/child/partials/comic/index.inc')
|
||||||
),
|
),
|
||||||
|
@ -82,6 +92,7 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
|
||||||
'root/child/partials/index.inc',
|
'root/child/partials/index.inc',
|
||||||
'root/child/partials/comic/index.inc'
|
'root/child/partials/comic/index.inc'
|
||||||
),
|
),
|
||||||
|
'partials',
|
||||||
null,
|
null,
|
||||||
vfsStream::url('root/child/partials/comic/index.inc')
|
vfsStream::url('root/child/partials/comic/index.inc')
|
||||||
)
|
)
|
||||||
|
@ -91,7 +102,7 @@ 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, $search_path, $post_categories, $expected_path_result) {
|
||||||
global $post;
|
global $post;
|
||||||
|
|
||||||
mkdir(vfsStream::url('root/parent/partials/comic/chapter-1'), 0777, true);
|
mkdir(vfsStream::url('root/parent/partials/comic/chapter-1'), 0777, true);
|
||||||
|
@ -110,7 +121,7 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
|
||||||
add_category(1, (object)array('slug' => 'comic', 'parent' => 0));
|
add_category(1, (object)array('slug' => 'comic', 'parent' => 0));
|
||||||
add_category(2, (object)array('slug' => 'chapter-1', 'parent' => 1));
|
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', $search_path, $post_categories));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue