fix category generation

This commit is contained in:
John Bintz 2010-01-23 11:32:34 -05:00
parent 3ccd43983e
commit 43b073f67f
4 changed files with 28 additions and 8 deletions

View File

@ -131,6 +131,7 @@ class FixtureBuilder {
$category_ids_by_slug = array(); $category_ids_by_slug = array();
foreach ($obj['post']['categories'] as $category) { foreach ($obj['post']['categories'] as $category) {
$category_ids_by_slug = array_merge($category_ids_by_slug, PostFixtures::create_category($category)); $category_ids_by_slug = array_merge($category_ids_by_slug, PostFixtures::create_category($category));
var_dump($category_ids_by_slug);
} }
$category_ids = array_values($category_ids_by_slug); $category_ids = array_values($category_ids_by_slug);
PostFixtures::set_post_categories($post_id, $category_ids); PostFixtures::set_post_categories($post_id, $category_ids);

View File

@ -5,6 +5,7 @@
*/ */
class PostFixtures { class PostFixtures {
var $messages; var $messages;
var $created_categories = array();
/** /**
* Initialize the plugin. * Initialize the plugin.
@ -262,7 +263,15 @@ class PostFixtures {
$joined_nodes = array(); $joined_nodes = array();
foreach ($nodes as $node) { foreach ($nodes as $node) {
$joined_nodes[] = $node; $joined_nodes[] = $node;
$parent = $category_ids_by_slug[implode('/', $joined_nodes)] = wp_insert_category(array('cat_name' => $node, 'category_nicename' => $node, 'category_parent' => $parent)); $key = implode('/', $joined_nodes);
if (isset($this->created_categories[$key])) {
$parent = $this->created_categories[$key];
} else {
$parent = wp_insert_category(array('cat_name' => $node, 'category_nicename' => $node, 'category_parent' => $parent));
$this->created_categories[$key] = $parent;
}
$category_ids_by_slug[$key] = $parent;
} }
return $category_ids_by_slug; return $category_ids_by_slug;
} }

View File

@ -45,7 +45,7 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase {
array( array(
array('post', array('Post title')), array('post', array('Post title')),
array('date', array('2010-01-01')), array('date', array('2010-01-01')),
array('categories', array('test,test2')), array('categories', array('test,test2/test3')),
array('metadata', array('key', array('metadata' => 'value'))), array('metadata', array('key', array('metadata' => 'value'))),
array('post', array('Post title 2')), array('post', array('Post title 2')),
array('date', array('2010-01-02')), array('date', array('2010-01-02')),
@ -56,7 +56,7 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase {
'post_title' => 'Post title', 'post_title' => 'Post title',
'post_type' => 'post', 'post_type' => 'post',
'post_date' => '2010-01-01', 'post_date' => '2010-01-01',
'categories' => array('test', 'test2'), 'categories' => array('test', 'test2/test3'),
'metadata' => array('key' => array('metadata' => 'value')) 'metadata' => array('key' => array('metadata' => 'value'))
), ),
array( array(
@ -235,10 +235,20 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase {
$fb->finalize(); $fb->finalize();
} }
function testOption() { function providerTestOption() {
$fb = new FixtureBuilder(); return array(
$fb->option('test', 'value'); array('test', 'value', 'value'),
array('test2', false, false)
);
}
$this->assertEquals('value', get_option('test')); /**
* @dataProvider providerTestOption
*/
function testOption($key, $value, $expected_value) {
$fb = new FixtureBuilder();
$fb->option($key, $value);
$this->assertEquals($expected_value, get_option($key));
} }
} }

View File

@ -138,7 +138,7 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
array(false, array()), array(false, array()),
array(array(), array()), array(array(), array()),
array(array('test'), array('test' => 1)), array(array('test'), array('test' => 1)),
array(array('test/test2'), array('test' => 1, 'test/test2' => 2)), array(array('test/test2', 'test/test3'), array('test' => 1, 'test/test2' => 2, 'test/test3' => 3)),
); );
} }