complete code coverage tests
This commit is contained in:
parent
08aaf6eb69
commit
8c9d8c02d6
@ -19,8 +19,9 @@ class ComicPressNavigation {
|
||||
|
||||
if (($result = wp_cache_get($cache_key, 'comicpress')) !== false) {
|
||||
foreach ($result as $key => $post_id) {
|
||||
$nev[$key] = get_post($post_id);
|
||||
$nav[$key] = get_post($post_id);
|
||||
}
|
||||
return $nav;
|
||||
}
|
||||
|
||||
// global previous/next
|
||||
|
@ -46,15 +46,27 @@ class ComicPressStoryline {
|
||||
}
|
||||
}
|
||||
|
||||
function _create_structure_key($input) {
|
||||
$key = 'storyline-structure-';
|
||||
if (is_string($input)) { return $key . $input; }
|
||||
if (is_array($input)) {
|
||||
$fixed_parts = array();
|
||||
foreach ($input as $i) { if (is_string($i)) { $fixed_parts[] = $i; } }
|
||||
if (!empty($fixed_parts)) { return $key . implode(',', $fixed_parts); }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a searchable structure from a node list.
|
||||
* @param array $structure The structure to process.
|
||||
* @return boolean True if the structure was valid.
|
||||
*/
|
||||
function create_structure($structure) {
|
||||
$key = null;
|
||||
$key = $this->_create_structure_key($structure);
|
||||
|
||||
if ($key !== false) {
|
||||
if (is_string($structure)) {
|
||||
$key = $structure;
|
||||
$structure = explode(',', $structure);
|
||||
} else {
|
||||
if (is_array($structure)) {
|
||||
@ -62,13 +74,10 @@ class ComicPressStoryline {
|
||||
foreach ($structure as $s) {
|
||||
if (!is_array($s)) { $fixed_structure[] = $s; }
|
||||
}
|
||||
$key = implode(',', $fixed_structure);
|
||||
$structure = $fixed_structure;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_null($key)) {
|
||||
$key = "storyline-structure-${key}";
|
||||
|
||||
if (($result = wp_cache_get($key, 'comicpress')) !== false) {
|
||||
$this->_structure = $result;
|
||||
} else {
|
||||
@ -142,9 +151,12 @@ class ComicPressStoryline {
|
||||
return false;
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
function parent($id) { return $this->_get_field('parent', $id); }
|
||||
function previous($id) { return $this->_get_field('previous', $id); }
|
||||
function next($id) { return $this->_get_field('next', $id); }
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
function valid($id) {
|
||||
if (isset($this->_structure[$id])) {
|
||||
return array_keys($this->_structure[$id]);
|
||||
@ -168,7 +180,9 @@ class ComicPressStoryline {
|
||||
}
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreStart
|
||||
} while ($has_adjacent);
|
||||
// @codeCoverageIgnoreEnd
|
||||
return $all_adjacent;
|
||||
}
|
||||
return false;
|
||||
@ -243,9 +257,11 @@ class ComicPressStoryline {
|
||||
/**
|
||||
* Get a flattened category node list.
|
||||
*/
|
||||
// @codeCoverageIgnoreStart
|
||||
function get_category_flattened($parent = null) {
|
||||
return $this->flatten_simple_storyline($this->get_category_simple_structure($parent));
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
/**
|
||||
* Merge a flat simple storyline into a tree.
|
||||
@ -285,7 +301,6 @@ class ComicPressStoryline {
|
||||
* Integrates a bunch of other things.
|
||||
*/
|
||||
function normalize($flattened_storyline = null, $set = true) {
|
||||
$comicpress = ComicPress::get_instance();
|
||||
if (is_null($flattened_storyline)) {
|
||||
$flattened_storyline = $this->get_flattened_storyline();
|
||||
}
|
||||
@ -418,7 +433,9 @@ class ComicPressStoryline {
|
||||
}
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreStart
|
||||
} while ($found_children);
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $children;
|
||||
}
|
||||
|
@ -17,8 +17,18 @@ class ComicPressNavigationTest extends PHPUnit_Framework_TestCase {
|
||||
$this->assertTrue($this->nav->get_post_nav(false) === false);
|
||||
}
|
||||
|
||||
function testGetPostNavPostHasNoID() {
|
||||
$this->assertTrue($this->nav->get_post_nav((object)array()) === false);
|
||||
}
|
||||
|
||||
function testGetPostNavFromCache() {
|
||||
$this->markTestIncomplete();
|
||||
wp_cache_set('navigation-1', array('test' => 2), 'comicpress');
|
||||
|
||||
$post_2 = (object)array('ID' => 2);
|
||||
|
||||
wp_insert_post((array)$post_2);
|
||||
|
||||
$this->assertEquals(array('test' => $post_2), $this->nav->get_post_nav((object)array('ID' => 1)));
|
||||
}
|
||||
|
||||
function testGetPostNav() {
|
||||
|
@ -14,23 +14,19 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
|
||||
function providerTestCreateStorylineStructure() {
|
||||
return array(
|
||||
array(
|
||||
false,
|
||||
false,
|
||||
false
|
||||
),
|
||||
array(
|
||||
array('0'),
|
||||
false,
|
||||
false
|
||||
),
|
||||
array(
|
||||
array('1'),
|
||||
false,
|
||||
false
|
||||
),
|
||||
array(
|
||||
array(array(0,1)),
|
||||
false,
|
||||
false
|
||||
),
|
||||
array(
|
||||
@ -41,6 +37,10 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
|
||||
array('0/1', '0/1/2'),
|
||||
array('1' => array('next' => 2, 'level' => 1), '2' => array('parent' => 1, 'previous' => 1, 'level' => 2))
|
||||
),
|
||||
array(
|
||||
array('0/1', false),
|
||||
false
|
||||
),
|
||||
array(
|
||||
array('0/1', '0/1/2', '0/1/3'),
|
||||
array(
|
||||
@ -97,13 +97,29 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
|
||||
* @group cache
|
||||
*/
|
||||
function testCreateStorylineStructureFromCache($input, $expected_structure) {
|
||||
if (is_string($input)) {
|
||||
wp_cache_set("storyline-structure-${input}", $expected_structure, 'comicpress');
|
||||
}
|
||||
$key = $this->css->_create_structure_key($input);
|
||||
if ($key !== false) {
|
||||
wp_cache_set($key, $expected_structure, 'comicpress');
|
||||
|
||||
$this->assertEquals(is_array($expected_structure), $this->css->create_structure($input));
|
||||
$this->assertEquals($expected_structure, $this->css->_structure);
|
||||
}
|
||||
}
|
||||
|
||||
function providerTestCreateStructureKey() {
|
||||
return array(
|
||||
array(false, false),
|
||||
array('blah', 'storyline-structure-blah'),
|
||||
array(array('test', 'test2'), 'storyline-structure-test,test2')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestCreateStructureKey
|
||||
*/
|
||||
function testCreateStructureKey($input, $expected_key) {
|
||||
$this->assertTrue($expected_key === $this->css->_create_structure_key($input));
|
||||
}
|
||||
|
||||
function providerTestGetFields() {
|
||||
return array(
|
||||
@ -511,11 +527,11 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
|
||||
return array(
|
||||
array(
|
||||
null,
|
||||
array(1,2,3,4,5,6,7)
|
||||
array(1,2,3,4,5,6,8,7)
|
||||
),
|
||||
array(
|
||||
array(),
|
||||
array(1,2,3,4,5,6,7)
|
||||
array(1,2,3,4,5,6,8,7)
|
||||
),
|
||||
array(
|
||||
array('child_of' => 1),
|
||||
@ -529,6 +545,14 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
|
||||
array('child_of' => 1, 'only' => 7),
|
||||
array(1,2,3,7)
|
||||
),
|
||||
array(
|
||||
array('child_of' => 1, '!only' => 2),
|
||||
array(1, 3)
|
||||
),
|
||||
array(
|
||||
array('child_of' => 4),
|
||||
array(4,5,6,8)
|
||||
),
|
||||
array(
|
||||
array('level' => 1),
|
||||
array(1,4,7)
|
||||
@ -554,7 +578,7 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
|
||||
function testBuildFromRestrictions($restrictions, $expected_categories) {
|
||||
global $post;
|
||||
|
||||
$this->css->set_flattened_storyline('0/1,0/1/2,0/1/3,0/4,0/4/5,0/4/6,0/7');
|
||||
$this->css->set_flattened_storyline('0/1,0/1/2,0/1/3,0/4,0/4/5,0/4/6,0/4/6/8,0/7');
|
||||
|
||||
wp_set_post_categories(1, array(3));
|
||||
$post = (object)array('ID' => 1);
|
||||
@ -562,6 +586,10 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
|
||||
$this->assertEquals($expected_categories, $this->css->build_from_restrictions($restrictions));
|
||||
}
|
||||
|
||||
function testFindChildrenEmpty() {
|
||||
$this->assertTrue(false === $this->css->_find_children(null));
|
||||
}
|
||||
|
||||
function providerTestAllAdjacent() {
|
||||
return array(
|
||||
array(3, 'previous', array(2, 1)),
|
||||
@ -584,6 +612,51 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
$this->assertEquals($expected_result, $this->css->all_adjacent($start, $direction));
|
||||
}
|
||||
|
||||
function providerTestNormalize() {
|
||||
return array(
|
||||
array(null, false),
|
||||
array(true, false),
|
||||
array(null, true),
|
||||
array(true, true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestNormalize
|
||||
*/
|
||||
function testNormalize($flattened_storyline, $do_set) {
|
||||
$css = $this->getMock('ComicPressStoryline', array('get_flattened_storyline', 'get_category_flattened', 'normalize_flattened_storyline', 'set_flattened_storyline'));
|
||||
$css->expects(is_null($flattened_storyline) ? $this->once() : $this->never())->method('get_flattened_storyline');
|
||||
$css->expects($do_set ? $this->once() : $this->never())->method('set_flattened_storyline');
|
||||
|
||||
$css->normalize($flattened_storyline, $do_set);
|
||||
}
|
||||
|
||||
function testExclude() {
|
||||
$css = $this->getMock('ComicPressStoryline', array('_find_blah'));
|
||||
$css->expects($this->once())->method('_find_blah')->with(1)->will($this->returnValue(array(1,2,3)));
|
||||
$css->_category_search = array(1,2,3,4,5,6);
|
||||
$css->_exclude('_find_blah', 1);
|
||||
$this->assertEquals(array(4,5,6), $css->_category_search);
|
||||
}
|
||||
|
||||
function providerTestEnsurePostID() {
|
||||
return array(
|
||||
array(null, null),
|
||||
array((object)array('test' => 'blah'), null),
|
||||
array((object)array('ID' => 1), 1),
|
||||
array("1", 1),
|
||||
array("1a", null),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestEnsurePostID
|
||||
*/
|
||||
function testEnsurePostID($thing, $expected_result) {
|
||||
$this->assertEquals($expected_result, $this->css->_ensure_post_id($thing));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user