diff --git a/.gitignore b/.gitignore index 4478ece..9d7e419 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ .settings/ coverage/ .DS_Store +*.pot + diff --git a/classes/ComicPressStoryline.inc b/classes/ComicPressStoryline.inc index 77d46a5..b92337a 100644 --- a/classes/ComicPressStoryline.inc +++ b/classes/ComicPressStoryline.inc @@ -430,15 +430,17 @@ class ComicPressStoryline { $children = array($parent); do { $found_children = false; - foreach ($this->_structure as $category_id => $info) { - if (!in_array($category_id, $children)) { - if (isset($info['parent'])) { - if (in_array($info['parent'], $children)) { - $children[] = $category_id; - $found_children = true; - } - } - } + if (is_array($this->_structure)) { + foreach ($this->_structure as $category_id => $info) { + if (!in_array($category_id, $children)) { + if (isset($info['parent'])) { + if (in_array($info['parent'], $children)) { + $children[] = $category_id; + $found_children = true; + } + } + } + } } // @codeCoverageIgnoreStart } while ($found_children); diff --git a/test/ComicPressStorylineTest.php b/test/ComicPressStorylineTest.php index f99ec1a..555d2ff 100644 --- a/test/ComicPressStorylineTest.php +++ b/test/ComicPressStorylineTest.php @@ -384,6 +384,11 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase { $this->assertEquals(array(2,3,4), $this->css->_find_children($search)); } + function testFindChildrenEmptyStructure() { + $this->css->_structure = false; + $this->assertEquals(array(2), $this->css->_find_children(2)); + } + function testFindLevelOrAbove() { $this->css->_structure = array( '1' => array('next' => 2, 'level' => 1),