M() function tested

This commit is contained in:
John Bintz 2009-11-14 13:01:40 -05:00
parent 9a0b40daba
commit e7732b8272
2 changed files with 52 additions and 6 deletions

View File

@ -2,6 +2,7 @@
// load all of the comic & non-comic category information
add_action('init', '__comicpress_init');
add_action('template_redirect', '__comicpress_template_redirect', 100);
function __comicpress_init() {
global $comicpress, $wp_query;
@ -34,6 +35,10 @@ function __comicpress_init() {
$comicpress_filters->init();
}
function __comicpress_template_redirect() {
ob_start();
}
function F($name, $path, $override_post = null) {
global $post;
@ -146,12 +151,13 @@ function RT($which, $restrictions = null, $override_post = null) {
}
function M($override_post = null) {
global $post, $__attachments, $__ordering;
global $post, $__attachments;
$post_to_use = !is_null($override_post) ? $override_post : $post;
$comic_post = new ComicPressComicPost($post_to_use);
$__attachments = $comic_post->get_attachments();
$__ordering = $comic_post->normalize_ordering();
$__attachments = $comic_post->get_attachments_with_children(true);
return $__attachments;
}
/**
@ -196,6 +202,3 @@ function comicpress_list_storyline_categories($args = "") {
if ($style == "list") { $output .= "</ul></li>"; }
echo $output;
}
ob_start();
?>

43
test/FunctionsTest.php Normal file
View File

@ -0,0 +1,43 @@
<?php
require_once('PHPUnit/Framework.php');
require_once('MockPress/mockpress.php');
require_once(dirname(__FILE__) . '/../functions.php');
class FunctionsTest extends PHPUnit_Framework_TestCase {
function providerTestM() {
return array(
array(null),
array((object)array('ID' => 2))
);
}
/**
* @dataProvider providerTestM
*/
function testM($post_to_use) {
global $post, $__attachments;
$post = (object)array('ID' => 1);
$backend = $this->getMock('ComicPressFakeBackend', array('generate_from_post'));
$post_to_test = (!is_null($post_to_use)) ? $post_to_use : $post;
$backend->expects($this->once())->method('generate_from_post')->with($post_to_test)->will($this->returnValue(array('test-1', 'test-2', 'test-3')));
$comicpress = ComicPress::get_instance();
$comicpress->backends = array($backend);
update_post_meta($post_to_test->ID, 'image-ordering', array(
'test-1' => array('enabled' => true, 'children' => array('rss' => 'test-2'))
));
$result = M($post_to_use);
$this->assertEquals(array('test-1' => array('rss' => 'test-2')), $result);
$this->assertEquals($result, $__attachments);
$this->assertEquals(array(
'test-1' => array('enabled' => true, 'children' => array('rss' => 'test-2'))
), get_post_meta($post_to_test->ID, 'image-ordering', true));
}
}