working on tag building

This commit is contained in:
John Bintz 2010-01-27 22:05:29 -05:00
parent 6f5a5dc396
commit 424382906e
3 changed files with 55 additions and 11 deletions

View File

@ -1,6 +1,7 @@
<?php
require_once('ComicPressDBInterface.inc');
require_once('ComicPress.inc');
class ComicPressStoryline {
var $_structure;

View File

@ -42,6 +42,10 @@ class ComicPressTagBuilder {
case 'last':
$this->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;

View File

@ -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);
}
}
}