diff --git a/classes/ComicPressStoryline.inc b/classes/ComicPressStoryline.inc new file mode 100644 index 0000000..a9dcfe1 --- /dev/null +++ b/classes/ComicPressStoryline.inc @@ -0,0 +1,63 @@ + 1) { + if ($parts[0] == '0') { $valid = true; } + } + if (!$valid) { + $is_valid = false; break; + } else { + $data = array(); + $leaf = end($parts); + + if (count($parts) > 2) { + $parent = $parts[count($parts) - 2]; + + if (!isset($adjacents_by_parent[$parent])) { + $adjacents_by_parent[$parent] = array(); + } + $adjacents_by_parent[$parent][] = $leaf; + + $data['parent'] = $parent; + } + + $new_structure[$leaf] = $data; + } + } else { + $is_valid = false; break; + } + } + if ($is_valid) { + foreach ($adjacents_by_parent as $parent => $adjacents) { + for ($i = 0; $i < count($adjacents); ++$i) { + foreach (array('previous' => -1, 'next' => 1) as $type => $dir) { + if (isset($adjacents[$i + $dir])) { + $new_structure[$adjacents[$i]][$type] = $adjacents[$i + $dir]; + } + } + } + } + + $this->_structure = $new_structure; + } + } + return is_array($this->_structure); + } +} + +?> \ No newline at end of file diff --git a/classes/ComicPressStorylineCategory.inc b/classes/ComicPressStorylineCategory.inc new file mode 100644 index 0000000..500c9fc --- /dev/null +++ b/classes/ComicPressStorylineCategory.inc @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/test/ComicPressComicPostTest.php b/test/ComicPressComicPostTest.php index da35d04..e876e07 100644 --- a/test/ComicPressComicPostTest.php +++ b/test/ComicPressComicPostTest.php @@ -1,7 +1,7 @@ \ No newline at end of file diff --git a/test/ComicPressStorylineTest.php b/test/ComicPressStorylineTest.php new file mode 100644 index 0000000..0d3e5ac --- /dev/null +++ b/test/ComicPressStorylineTest.php @@ -0,0 +1,84 @@ +css = new ComicPressStoryline(); + } + + function providerTestCreateStorylineStructure() { + return array( + array( + false, + false + ), + array( + array('0'), + false + ), + array( + array('1'), + false + ), + array( + array(array(0,1)), + false + ), + array( + array('0/1'), + array('1' => array()) + ), + array( + array('0/1', '0/1/2'), + array('1' => array(), '2' => array('parent' => 1)) + ), + array( + array('0/1', '0/1/2', '0/1/3'), + array( + '1' => array(), + '2' => array('parent' => 1, 'next' => 3), + '3' => array('parent' => 1, 'previous' => 2), + ) + ), + array( + array('0/1', '0/1/2', '0/1/2/3', '0/1/2/4', '0/1/5'), + array( + '1' => array(), + '2' => array('parent' => 1, 'next' => 5), + '3' => array('parent' => 2, 'next' => 4), + '4' => array('parent' => 2, 'previous' => 3), + '5' => array('parent' => 1, 'previous' => 2), + ) + ), + array( + array('0/1', '0/1/2', '0/1/2/3', '0/1/2/4', '0/1/5', '0/1/5/6', '0/1/5/7', '0/1/5/8', '0/1/9'), + array( + '1' => array(), + '2' => array('parent' => 1, 'next' => 5), + '3' => array('parent' => 2, 'next' => 4), + '4' => array('parent' => 2, 'previous' => 3), + '5' => array('parent' => 1, 'previous' => 2, 'next' => 9), + '6' => array('parent' => 5, 'next' => 7), + '7' => array('parent' => 5, 'previous' => 6, 'next' => 8), + '8' => array('parent' => 5, 'previous' => 7), + '9' => array('parent' => 1, 'previous' => 5), + ) + ), + ); + } + + /** + * @dataProvider providerTestCreateStorylineStructure + */ + function testCreateStorylineStructure($input, $expected_structure) { + $this->assertEquals(is_array($expected_structure), $this->css->create_structure($input)); + $this->assertEquals($expected_structure, $this->css->_structure); + } +} + +?> \ No newline at end of file diff --git a/test/ComicPressTest.php b/test/ComicPressTest.php index e75e6e9..6deae7c 100644 --- a/test/ComicPressTest.php +++ b/test/ComicPressTest.php @@ -1,7 +1,7 @@