From 424382906ea13007a7af366f0a921d91016b2c3e Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 27 Jan 2010 22:05:29 -0500 Subject: [PATCH] working on tag building --- classes/ComicPressStoryline.inc | 1 + classes/ComicPressTagBuilder.inc | 4 ++ test/ComicPressTagBuilderTest.php | 61 +++++++++++++++++++++++++------ 3 files changed, 55 insertions(+), 11 deletions(-) diff --git a/classes/ComicPressStoryline.inc b/classes/ComicPressStoryline.inc index 7a3c1b9..2c66dac 100644 --- a/classes/ComicPressStoryline.inc +++ b/classes/ComicPressStoryline.inc @@ -1,6 +1,7 @@ post = call_user_func(array($this->dbi, "get_${method}_post"), $this->storyline->build_from_restrictions($this->restrictions), $this->parent_post); break; + case 'in': + if (!isset($arguments[0])) { throw new Exception('Need to specify a category'); } + $this->restrictions[] = array('child_of', $arguments[0]); + break; } return $this; diff --git a/test/ComicPressTagBuilderTest.php b/test/ComicPressTagBuilderTest.php index f0aa493..ccdaedc 100644 --- a/test/ComicPressTagBuilderTest.php +++ b/test/ComicPressTagBuilderTest.php @@ -10,12 +10,50 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase { _reset_wp(); } + function testNewFactory() { + $core = new ComicPressTagBuilderFactory(); + } + function providerTestBuilder() { return array( array( - array('next'), + array( + array('next') + ), array('get_next_post', array(1,2,3,4,5), 'current-post') - ) + ), + array( + array( + array('previous'), + ), + array('get_previous_post', array(1,2,3,4,5), 'current-post') + ), + array( + array( + array('first'), + ), + array('get_first_post', array(1,2,3,4,5), 'current-post') + ), + array( + array( + array('last'), + ), + array('get_last_post', array(1,2,3,4,5), 'current-post') + ), + array( + array( + array('in', 'category-1'), + array('last') + ), + array('get_last_post', array(1), 'current-post') + ), + array( + array( + array('in', 2), + array('first') + ), + array('get_first_post', array(2,3,4), 'current-post') + ), ); } @@ -23,7 +61,7 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase { * @dataProvider providerTestBuilder */ function testStorylineBuilder($instructions, $expected_dbi_call) { - global $post; + global $post, $wp_test_expectations; $post = 'current-post'; $method = array_shift($expected_dbi_call); @@ -38,17 +76,18 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase { $storyline->set_flattened_storyline('0/1,0/2,0/2/3,0/2/4,0/5'); foreach (array( - array('cat_ID' => 1, 'cat_name' => 'Test 1', 'category_nicename' => 'category-1', 'category_parent' => 0), - array('cat_ID' => 2, 'cat_name' => 'Test 2', 'category_nicename' => 'category-2', 'category_parent' => 0), - array('cat_ID' => 3, 'cat_name' => 'Test 3', 'category_nicename' => 'category-3', 'category_parent' => 2), - array('cat_ID' => 4, 'cat_name' => 'Test 4', 'category_nicename' => 'category-4', 'category_parent' => 2), - array('cat_ID' => 5, 'cat_name' => 'Test 5', 'category_nicename' => 'category-5', 'category_parent' => 0), - ) as $category) { - wp_insert_category($category); + 1 => array('cat_name' => 'Test 1', 'category_nicename' => 'category-1', 'category_parent' => 0), + 2 => array('cat_name' => 'Test 2', 'category_nicename' => 'category-2', 'category_parent' => 0), + 3 => array('cat_name' => 'Test 3', 'category_nicename' => 'category-3', 'category_parent' => 2), + 4 => array('cat_name' => 'Test 4', 'category_nicename' => 'category-4', 'category_parent' => 2), + 5 => array('cat_name' => 'Test 5', 'category_nicename' => 'category-5', 'category_parent' => 0), + ) as $id => $category) { + add_category($id, (object)$category); } foreach ($instructions as $instruction) { - $core = $core->{$instruction}(); + $method = array_shift($instruction); + $core = call_user_func_array(array($core, $method), $instruction); } } }