finally remove functions.inc

This commit is contained in:
John Bintz 2010-02-04 22:36:51 -05:00
parent ce6912c24e
commit a209b4a184
5 changed files with 96 additions and 118 deletions

View File

@ -2,7 +2,6 @@
require_once('ComicPressStoryline.inc');
// TODO Loop preservation
class ComicPressTagBuilderFactory {
private $storyline, $dbi;
@ -45,6 +44,45 @@ class ComicPressTagBuilderFactory {
$comicpress = ComicPress::get_instance();
return $comicpress->find_file($name, $path, $categories);
}
/**
* Protect global $post and $wp_query.
* @param object $use_this_post If provided, after saving the current post, set up this post for template tag use.
*/
function protect($use_this_post = null) {
global $post, $wp_query;
$this->_post = $post;
$this->_wp_query = $wp_query;
if (!is_null($use_this_post)) {
$post = $use_this_post;
setup_postdata($post);
}
}
/**
* Temporarily restore the global $post variable and set it up for use.
*/
function restore() {
global $post;
$post = $this->_post;
setup_postdata($post);
}
/**
* Restore global $post and $wp_query.
*/
function unprotect() {
global $post, $wp_query;
$post = $this->_post;
$wp_query = $this->_wp_query;
unset($this->_post);
unset($this->_wp_query);
}
}
class ComicPressTagBuilder {

View File

@ -32,7 +32,7 @@ add_action('init', '__comicpress_init');
function __comicpress_init() {
$classes_search = array(
'/', '/classes/', '/classes/backends/'
'/classes/', '/classes/backends/'
);
foreach ($classes_search as $path) {

View File

@ -1,51 +0,0 @@
<?php
foreach (array(
'Protect' => 0,
'Restore' => 0,
'Unprotect' => 0,
) as $function => $param_count) {
if ($param_count == 0) {
add_action("comicpress-${function}", $function, 10);
} else {
add_filter("comicpress-${function}", $function, 10, $param_count);
}
}
/**
* Protect global $post and $wp_query.
* @param object $use_this_post If provided, after saving the current post, set up this post for template tag use.
*/
function Protect($use_this_post = null) {
global $post, $wp_query, $__post, $__wp_query;
$__post = $post;
$__wp_query = $wp_query;
if (!is_null($use_this_post)) {
$post = $use_this_post;
setup_postdata($post);
}
}
/**
* Temporarily restore the global $post variable and set it up for use.
*/
function Restore() {
global $post, $__post;
$post = $__post;
setup_postdata($post);
}
/**
* Restore global $post and $wp_query.
*/
function Unprotect() {
global $post, $wp_query, $__post, $__wp_query;
$post = $__post;
$wp_query = $__wp_query;
$__post = $__wp_query = null;
}

View File

@ -507,8 +507,7 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase {
}
function testFindFilePassthru() {
$dbi = $this->getMock('ComicPressDBInterface');
$core = new ComicPressTagBuilderFactory($dbi);
$core = new ComicPressTagBuilderFactory();
$comicpress = $this->getMock('ComicPress', array('find_file'));
$comicpress->expects($this->once())
@ -522,4 +521,59 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase {
ComicPress::get_instance(true);
}
function providerTestProtect() {
return array(
array(null, 'test'),
array('test3', 'test3')
);
}
/**
* @dataProvider providerTestProtect
*/
function testProtect($post_to_use, $expected_post) {
global $post, $wp_query;
$post = "test";
$wp_query = "test2";
$core = new ComicPressTagBuilderFactory();
$core->protect($post_to_use);
$this->assertEquals($core->_post, 'test');
$this->assertEquals($expected_post, $post);
$this->assertEquals($wp_query, $core->_wp_query);
}
function testRestore() {
global $post;
$core = new ComicPressTagBuilderFactory();
$post = 'not';
$core->_post = 'test';
$core->restore();
$this->assertEquals($core->_post, $post);
}
function testUnprotect() {
global $post, $wp_query;
$core = new ComicPressTagBuilderFactory();
$core->_post = $core->_wp_query = 'test';
$post = $wp_query = 'not';
$core->unprotect();
$this->assertEquals('test', $post);
$this->assertEquals('test', $wp_query);
$this->assertTrue(!isset($core->_post));
$this->assertTrue(!isset($core->_wp_query));
}
}

View File

@ -1,63 +0,0 @@
<?php
require_once('PHPUnit/Framework.php');
require_once('MockPress/mockpress.php');
require_once(dirname(__FILE__) . '/../functions.inc');
class FunctionsTest extends PHPUnit_Framework_TestCase {
function setUp() {
_reset_wp();
}
function providerTestProtect() {
return array(
array(null, 'test'),
array('test3', 'test3')
);
}
/**
* @dataProvider providerTestProtect
*/
function testProtect($post_to_use, $expected_post) {
global $post, $wp_query, $__post, $__wp_query;
$__post = null;
$__wp_query = null;
$post = "test";
$wp_query = "test2";
Protect($post_to_use);
$this->assertEquals($__post, 'test');
$this->assertEquals($expected_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));
}
}