setting up functions tests and cleaning up code coverage

This commit is contained in:
John Bintz 2009-11-15 10:18:42 -05:00
parent 39c0bce9f5
commit 1cafcc9e3b
2 changed files with 89 additions and 7 deletions

View File

@ -4,6 +4,8 @@
add_action('init', '__comicpress_init');
add_action('template_redirect', '__comicpress_template_redirect', 100);
// @codeCoverageIgnoreStart
function __comicpress_init() {
global $comicpress, $wp_query;
@ -57,6 +59,8 @@ function finish_comicpress() {
include(F('application.php', ''));
}
// @codeCoverageIgnoreEnd
/**
* Protect global $post and $wp_query.
*/
@ -89,12 +93,7 @@ function Unprotect() {
$__post = $__wp_query = null;
}
function R($which, $restrictions = null, $override_post = null) {
global $post;
$post_to_use = !is_null($override_post) ? $override_post : $post;
$storyline = new ComicPressStoryline();
function __prep_R($restrictions, $post_to_use) {
if (is_string($restrictions)) {
switch ($restrictions) {
case 'from_post':
@ -119,7 +118,18 @@ function R($which, $restrictions = null, $override_post = null) {
$restrictions = $new_restrictions;
}
$categories = $storyline->build_from_restrictions($restrictions);
return $restrictions;
}
// @codeCoverageIgnoreStart
function R($which, $restrictions = null, $override_post = null) {
global $post;
$post_to_use = !is_null($override_post) ? $override_post : $post;
$storyline = new ComicPressStoryline();
$categories = $storyline->build_from_restrictions(__prep_R($restrictions));
$dbi = ComicPressDBInterface::get_instance();
@ -150,6 +160,8 @@ function RT($which, $restrictions = null, $override_post = null) {
return $post;
}
// @codeCoverageIgnoreEnd
function M($override_post = null) {
global $post, $__attachments;
$post_to_use = !is_null($override_post) ? $override_post : $post;

View File

@ -40,4 +40,74 @@ class FunctionsTest extends PHPUnit_Framework_TestCase {
'test-1' => array('enabled' => true, 'children' => array('rss' => 'test-2'))
), get_post_meta($post_to_test->ID, 'image-ordering', true));
}
function testProtect() {
global $post, $wp_query, $__post, $__wp_query;
$__post = null;
$__wp_query = null;
$post = "test";
$wp_query = "test2";
Protect();
$this->assertEquals($post, $__post);
$this->assertEquals($wp_query, $__wp_query);
}
function testRestore() {
global $post, $__post;
$post = 'not';
$__post = 'test';
Restore();
$this->assertEquals($__post, $post);
}
function testUnprotect() {
global $post, $__post, $wp_query, $__wp_query;
$__post = $__wp_query = 'test';
$post = $wp_query = 'not';
Unprotect();
$this->assertEquals('test', $post);
$this->assertEquals('test', $wp_query);
$this->assertTrue(is_null($__post));
$this->assertTrue(is_null($__wp_query));
}
function providerTestPrepR() {
$post = (object)array('ID' => 1);
return array(
array(
array(), array()
),
array(
'from_post', array('from_post' => $post)
),
array(
array('test' => 'test'), array('test' => 'test')
),
array(
array('test' => '__post'), array('test' => $post)
),
array(
array('test' => array('test')), array('test' => array('test'))
),
);
}
/**
* @dataProvider providerTestPrepR
*/
function testPrepR($restrictions, $expected_result) {
$this->assertEquals($expected_result, __prep_R($restrictions, (object)array('ID' => 1)));
}
}