diff --git a/Makefile b/Makefile index ba9b5ee..2ba64c9 100644 --- a/Makefile +++ b/Makefile @@ -8,4 +8,4 @@ ifdef comicpress28 endif test: - taskset -c 1 phpunit --syntax-check --coverage-html coverage test \ No newline at end of file + phpunit --syntax-check --coverage-html coverage test \ No newline at end of file diff --git a/classes/ComicPressStoryline.inc b/classes/ComicPressStoryline.inc index 5b79db6..e689d37 100644 --- a/classes/ComicPressStoryline.inc +++ b/classes/ComicPressStoryline.inc @@ -11,15 +11,18 @@ class ComicPressStoryline { return $this; } + function _class_exists($class) { return class_exists($class); } + /** * Get the flattened storyline from options. */ function get_flattened_storyline() { - if (class_exists('ComicPress')) { + if ($this->_class_exists('ComicPress')) { $comicpress = &ComicPress::get_instance(); if (isset($comicpress->comicpress_options['storyline_order'])) { return $comicpress->comicpress_options['storyline_order']; } + } else { return get_option("comicpress-storyline-category-order"); } @@ -30,7 +33,7 @@ class ComicPressStoryline { * Set the global storyline as a flattened storyline. */ function set_flattened_storyline($storyline) { - if (class_exists('ComicPress')) { + if ($this->_class_exists('ComicPress')) { $comicpress = &ComicPress::get_instance(); $comicpress->comicpress_options['storyline_order'] = $storyline; $comicpress->save(); diff --git a/test/ComicPressStorylineTest.php b/test/ComicPressStorylineTest.php index 2abe07c..7b5b93b 100644 --- a/test/ComicPressStorylineTest.php +++ b/test/ComicPressStorylineTest.php @@ -106,6 +106,22 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase { } } + function testGetFlattenedStorylineNoComicPress() { + $css = $this->getMock('ComicPressStoryline', array('_class_exists')); + $css->expects($this->once())->method('_class_exists')->will($this->returnValue(false)); + + update_option('comicpress-storyline-category-order', 'test'); + + $this->assertEquals('test', $css->get_flattened_storyline()); + } + + function testGetFlattenedStorylineNoComicPressStorylineOrder() { + $comicpress = ComicPress::get_instance(); + unset($comicpress->comicpress_options['storyline_order']); + + $this->assertEquals(false, $this->css->get_flattened_storyline()); + } + function providerTestCreateStructureKey() { return array( array(false, false), @@ -701,6 +717,15 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase { $this->assertEquals($expected_id, $this->css->_ensure_category_ids($string)); } + function testEnsureCategoryIDsBadGrouping() { + $comicpress = ComicPress::get_instance(); + $comicpress->comicpress_options['category_groupings'] = array( + 'comic' => 1, + ); + + $this->assertEquals(array(1), $this->css->_ensure_category_ids('comic')); + } + function providerTestNormalizeCategoryGroupings() { return array( array( @@ -713,6 +738,11 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase { array(1), array('test' => array(1)) ), + array( + array('test' => array(3)), + array(1), + array() + ), ); }