code coverage for F()
This commit is contained in:
parent
c3f7032de3
commit
28d631c1ba
|
@ -35,10 +35,14 @@ class ComicPress {
|
||||||
|
|
||||||
var $backends = array();
|
var $backends = array();
|
||||||
|
|
||||||
function &get_instance() {
|
function &get_instance($force = false) {
|
||||||
static $instance;
|
static $instance;
|
||||||
|
|
||||||
if (!$instance) {
|
if (is_object($force)) {
|
||||||
|
$instance = array($force);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$instance || ($force === true)) {
|
||||||
$instance = array(new ComicPress());
|
$instance = array(new ComicPress());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ foreach (array(
|
||||||
|
|
||||||
// Global template functions for ComicPress
|
// Global template functions for ComicPress
|
||||||
|
|
||||||
// @codeCoverageIgnoreStart
|
|
||||||
function F($name, $path, $override_post = null) {
|
function F($name, $path, $override_post = null) {
|
||||||
global $post;
|
global $post;
|
||||||
|
|
||||||
|
@ -32,7 +31,6 @@ function F($name, $path, $override_post = null) {
|
||||||
$comicpress = ComicPress::get_instance();
|
$comicpress = ComicPress::get_instance();
|
||||||
return $comicpress->find_file($name, $path, $comic_post->find_parents());
|
return $comicpress->find_file($name, $path, $comic_post->find_parents());
|
||||||
}
|
}
|
||||||
// @codeCoverageIgnoreEnd
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Protect global $post and $wp_query.
|
* Protect global $post and $wp_query.
|
||||||
|
|
|
@ -258,4 +258,35 @@ class FunctionsTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
$this->assertEquals($expected_result, In_R());
|
$this->assertEquals($expected_result, In_R());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function providerTestF() {
|
||||||
|
return array(
|
||||||
|
array(null, array(1 => 'one')),
|
||||||
|
array((object)array('ID' => 2), array(2 => 'two'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerTestF
|
||||||
|
*/
|
||||||
|
function testF($post_to_use, $expected_parents) {
|
||||||
|
global $post;
|
||||||
|
|
||||||
|
$post = (object)array('ID' => 1);
|
||||||
|
|
||||||
|
add_category(1, (object)array('slug' => 'one'));
|
||||||
|
add_category(2, (object)array('slug' => 'two'));
|
||||||
|
|
||||||
|
wp_set_post_categories(1, array(1));
|
||||||
|
wp_set_post_categories(2, array(2));
|
||||||
|
|
||||||
|
$comicpress = $this->getMock('ComicPress', array('find_file'));
|
||||||
|
$comicpress->expects($this->once())->method('find_file')->with('name', 'path', $expected_parents)->will($this->returnValue('done'));
|
||||||
|
|
||||||
|
ComicPress::get_instance($comicpress);
|
||||||
|
|
||||||
|
$this->assertEquals('done', F('name', 'path', $post_to_use));
|
||||||
|
|
||||||
|
ComicPress::get_instance(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue