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-07-08 23:54:56 +00:00
|
|
|
|
|
|
|
class ComicPressTest extends PHPUnit_Framework_TestCase {
|
|
|
|
function setUp() {
|
2009-07-19 23:08:58 +00:00
|
|
|
global $post;
|
|
|
|
|
2009-07-08 23:54:56 +00:00
|
|
|
_reset_wp();
|
2009-07-19 23:08:58 +00:00
|
|
|
unset($post);
|
2009-07-08 23:54:56 +00:00
|
|
|
$this->cp = new ComicPress();
|
|
|
|
}
|
2009-07-09 02:38:43 +00:00
|
|
|
|
2009-07-23 19:12:13 +00:00
|
|
|
function providerTestGetLayoutChoices() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
array(),
|
|
|
|
array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'layout.php' => <<<FILE
|
|
|
|
Test
|
|
|
|
FILE
|
|
|
|
),
|
|
|
|
array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'layout.php' => <<<FILE
|
|
|
|
/*
|
|
|
|
Layout Name: Test
|
2009-07-23 21:13:53 +00:00
|
|
|
Sidebars: left,right
|
2009-07-23 19:12:13 +00:00
|
|
|
*/
|
|
|
|
FILE
|
|
|
|
),
|
2009-07-23 21:13:53 +00:00
|
|
|
array('layout.php' => array(
|
|
|
|
'Layout Name' => 'Test',
|
|
|
|
'Sidebars' => 'left,right',
|
|
|
|
))
|
2009-07-23 19:12:13 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTestGetLayoutChoices
|
|
|
|
*/
|
|
|
|
function testGetLayoutChoices($files, $expected_results) {
|
|
|
|
$cp = $this->getMock('ComicPress', array('_glob', '_file_get_contents'));
|
|
|
|
|
|
|
|
_set_template_directory('/test');
|
|
|
|
|
|
|
|
$file_names = array();
|
|
|
|
foreach (array_keys($files) as $file) { $file_names[] = '/test/layouts/' . $file; }
|
|
|
|
|
|
|
|
$cp->expects($this->once())->method('_glob')->with('/test/layouts/*')->will($this->returnValue($file_names));
|
|
|
|
foreach ($files as $file => $contents) {
|
|
|
|
$cp->expects($this->once())->method('_file_get_contents')->with('/test/layouts/' . $file)->will($this->returnValue($contents));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEquals($expected_results, $cp->get_layout_choices());
|
|
|
|
}
|
2009-07-29 02:38:20 +00:00
|
|
|
|
|
|
|
function providerTestGetSortedPostCategories() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
array(1),
|
|
|
|
array('0/1'),
|
|
|
|
array(1)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array(2, 1),
|
|
|
|
array('0/1', '0/1/2'),
|
|
|
|
array(1, 2)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array(2, 1),
|
|
|
|
array('0/1', '0/1/3', '0/1/2'),
|
|
|
|
array(1, 2)
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTestGetSortedPostCategories
|
|
|
|
*/
|
|
|
|
function testGetSortedPostCategories($post_categories, $category_tree, $expected_sort_order) {
|
|
|
|
$this->cp->category_tree = $category_tree;
|
|
|
|
|
|
|
|
wp_set_post_categories(1, $post_categories);
|
|
|
|
|
|
|
|
$this->assertEquals($expected_sort_order, $this->cp->get_sorted_post_categories((object)array('ID' => 1)));
|
|
|
|
}
|
2009-07-30 00:07:56 +00:00
|
|
|
|
|
|
|
function testSetupMulticomicPartialPaths() {
|
|
|
|
$cp = $this->getMock('ComicPress', array('_is_dir'));
|
|
|
|
|
|
|
|
wp_set_post_categories(1, array('2', '3'));
|
|
|
|
|
|
|
|
add_category('2', (object)array('slug' => 'test-one'));
|
|
|
|
add_category('3', (object)array('slug' => 'test-two'));
|
|
|
|
|
|
|
|
$cp->expects($this->at(0))->method('_is_dir')->with('/subthemes/test-one')->will($this->returnValue(true));
|
|
|
|
$cp->expects($this->at(1))->method('_is_dir')->with('/subthemes/test-two')->will($this->returnValue(false));
|
|
|
|
|
|
|
|
$cp->setup_multicomic_partial_paths(1);
|
|
|
|
|
|
|
|
$this->assertEquals(array('/subthemes/test-one'), $cp->partial_paths);
|
|
|
|
}
|
2009-08-06 02:29:54 +00:00
|
|
|
|
|
|
|
function providerTestGetOverridePartials() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
array('partials'),
|
|
|
|
array('index'),
|
|
|
|
array('partials/index'),
|
|
|
|
array('partials/index', true)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array('partials'),
|
|
|
|
array('index'),
|
|
|
|
array('partials/single'),
|
|
|
|
false
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTestGetOverridePartials
|
|
|
|
*/
|
|
|
|
function testGetOverridePartials($partial_paths, $requested_partials, $override_partials, $expected_result) {
|
|
|
|
$this->cp->partial_paths = $partial_paths;
|
|
|
|
foreach ($override_partials as $partial) {
|
|
|
|
$this->cp->comicpress_options['override_partials'][$partial] = true;
|
|
|
|
}
|
|
|
|
$this->assertEquals($expected_result, $this->cp->get_options_partial($requested_partials));
|
|
|
|
}
|
2009-07-07 02:45:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|