2009-07-07 02:45:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once('PHPUnit/Framework.php');
|
2009-10-18 21:05:10 +00:00
|
|
|
require_once('MockPress/mockpress.php');
|
2009-11-07 17:18:53 +00:00
|
|
|
require_once('ComicPress.inc');
|
2009-11-07 18:14:33 +00:00
|
|
|
require_once('vfsStream/vfsStream.php');
|
2009-07-08 23:54:56 +00:00
|
|
|
|
|
|
|
class ComicPressTest extends PHPUnit_Framework_TestCase {
|
|
|
|
function setUp() {
|
|
|
|
_reset_wp();
|
|
|
|
$this->cp = new ComicPress();
|
2009-07-29 02:38:20 +00:00
|
|
|
|
2009-11-07 18:14:33 +00:00
|
|
|
vfsStreamWrapper::register();
|
|
|
|
vfsStreamWrapper::setRoot(new vfsStreamDirectory('root'));
|
2009-07-29 02:38:20 +00:00
|
|
|
}
|
2009-11-07 18:14:33 +00:00
|
|
|
|
2009-11-07 18:47:08 +00:00
|
|
|
function providerTestCategorySearch() {
|
|
|
|
return array(
|
|
|
|
array(
|
2009-11-07 21:36:57 +00:00
|
|
|
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()
|
2009-11-07 18:47:08 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTestCategorySearch
|
|
|
|
*/
|
2009-11-07 21:36:57 +00:00
|
|
|
function testCategorySearch($categories, $found_path) {
|
|
|
|
mkdir(vfsStream::url('root/style/comic/chapter-1/part-1'), 0777, true);
|
2009-11-07 18:47:08 +00:00
|
|
|
|
2009-11-07 21:36:57 +00:00
|
|
|
$this->assertEquals($found_path, $this->cp->category_search($categories, vfsStream::url('root/style')));
|
2009-11-07 18:47:08 +00:00
|
|
|
}
|
2009-11-07 22:00:14 +00:00
|
|
|
|
|
|
|
function providerTestFindFile() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
array(), array(), false,
|
|
|
|
),
|
|
|
|
array(
|
2009-11-07 22:05:38 +00:00
|
|
|
array('root/parent/partials/index.inc'),
|
|
|
|
array(),
|
|
|
|
vfsStream::url('root/parent/partials/index.inc')
|
2009-11-07 22:00:14 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'root/parent/partials/index.inc',
|
|
|
|
'root/child/partials/index.inc'
|
|
|
|
),
|
|
|
|
array(),
|
|
|
|
vfsStream::url('root/child/partials/index.inc')
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'root/child/partials/index.inc',
|
|
|
|
'root/child/partials/comic/index.inc'
|
|
|
|
),
|
|
|
|
array('comic'),
|
|
|
|
vfsStream::url('root/child/partials/comic/index.inc')
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'root/child/partials/index.inc',
|
|
|
|
'root/child/partials/comic/index.inc'
|
|
|
|
),
|
|
|
|
array('chapter-1', 'comic'),
|
|
|
|
vfsStream::url('root/child/partials/comic/index.inc')
|
2009-11-07 22:13:13 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'root/child/partials/index.inc',
|
|
|
|
'root/child/partials/comic/index.inc'
|
|
|
|
),
|
|
|
|
null,
|
|
|
|
vfsStream::url('root/child/partials/comic/index.inc')
|
2009-11-07 22:00:14 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTestFindFile
|
|
|
|
*/
|
|
|
|
function testFindFile($files_to_setup, $post_categories, $expected_path_result) {
|
2009-11-07 22:13:13 +00:00
|
|
|
global $post;
|
|
|
|
|
2009-11-07 22:00:14 +00:00
|
|
|
mkdir(vfsStream::url('root/parent/partials/comic/chapter-1'), 0777, true);
|
|
|
|
mkdir(vfsStream::url('root/child/partials/comic/chapter-1'), 0777, true);
|
|
|
|
|
|
|
|
foreach ($files_to_setup as $path) {
|
|
|
|
file_put_contents(vfsStream::url($path), "test");
|
|
|
|
}
|
|
|
|
|
|
|
|
_set_template_directory(vfsStream::url('root/parent'));
|
|
|
|
_set_stylesheet_directory(vfsStream::url('root/child'));
|
|
|
|
|
2009-11-07 22:13:13 +00:00
|
|
|
$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));
|
|
|
|
|
2009-11-07 22:00:14 +00:00
|
|
|
$this->assertEquals($expected_path_result, $this->cp->find_file('index.inc', 'partials', $post_categories));
|
|
|
|
}
|
2009-07-07 02:45:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|