working on cleaning up storyline code and switching over to pear-based mockpress
This commit is contained in:
parent
29541b94a7
commit
1075712fbd
63
classes/ComicPressStoryline.inc
Normal file
63
classes/ComicPressStoryline.inc
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ComicPressStoryline {
|
||||||
|
var $_structure;
|
||||||
|
|
||||||
|
function create_structure($structure) {
|
||||||
|
$new_structure = array();
|
||||||
|
$parent = null;
|
||||||
|
$previous = null;
|
||||||
|
|
||||||
|
$adjacents_by_parent = array();
|
||||||
|
|
||||||
|
if (is_array($structure)) {
|
||||||
|
$is_valid = true;
|
||||||
|
foreach ($structure as $branch) {
|
||||||
|
if (is_string($branch)) {
|
||||||
|
$parts = explode('/', $branch);
|
||||||
|
$valid = false;
|
||||||
|
if (count($parts) > 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
7
classes/ComicPressStorylineCategory.inc
Normal file
7
classes/ComicPressStorylineCategory.inc
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ComicPressStorylineCategory {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once('PHPUnit/Framework.php');
|
require_once('PHPUnit/Framework.php');
|
||||||
require_once(dirname(__FILE__) . '/../../mockpress/mockpress.php');
|
require_once('MockPress/mockpress.php');
|
||||||
require_once(dirname(__FILE__) . '/../classes/ComicPressComicPost.inc');
|
require_once(dirname(__FILE__) . '/../classes/ComicPressComicPost.inc');
|
||||||
|
|
||||||
class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
|
class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
|
||||||
|
17
test/ComicPressStorylineCategoryTest.php
Normal file
17
test/ComicPressStorylineCategoryTest.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once('MockPress/mockpress.php');
|
||||||
|
require_once('PHPUnit/Framework.php');
|
||||||
|
require_once(dirname(__FILE__) . '/../classes/ComicPressStorylineCategory.inc');
|
||||||
|
|
||||||
|
class ComicPressStorylineCategoryTest extends PHPUnit_Framework_TestCase {
|
||||||
|
function setUp() {
|
||||||
|
_reset_wp();
|
||||||
|
}
|
||||||
|
|
||||||
|
function testGetAdjacentCategories() {
|
||||||
|
$sc = new ComicPressStorylineCategory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
84
test/ComicPressStorylineTest.php
Normal file
84
test/ComicPressStorylineTest.php
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once('MockPress/mockpress.php');
|
||||||
|
require_once('PHPUnit/Framework.php');
|
||||||
|
require_once(dirname(__FILE__) . '/../classes/ComicPressStoryline.inc');
|
||||||
|
|
||||||
|
class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
|
||||||
|
function setUp() {
|
||||||
|
_reset_wp();
|
||||||
|
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once('PHPUnit/Framework.php');
|
require_once('PHPUnit/Framework.php');
|
||||||
require_once(dirname(__FILE__) . '/../../mockpress/mockpress.php');
|
require_once('MockPress/mockpress.php');
|
||||||
require_once(dirname(__FILE__) . '/../classes/ComicPress.inc');
|
require_once(dirname(__FILE__) . '/../classes/ComicPress.inc');
|
||||||
|
|
||||||
class ComicPressTest extends PHPUnit_Framework_TestCase {
|
class ComicPressTest extends PHPUnit_Framework_TestCase {
|
||||||
|
Loading…
Reference in New Issue
Block a user