allow for parent/child categories

This commit is contained in:
John Bintz 2009-11-23 07:23:26 -05:00
parent 5b9a966c0e
commit df5c47e2d3
2 changed files with 20 additions and 3 deletions

View File

@ -129,7 +129,13 @@ class PostFixtures {
$category_ids_by_slug = array(); $category_ids_by_slug = array();
if (is_array($categories)) { if (is_array($categories)) {
foreach ($categories as $category) { foreach ($categories as $category) {
$category_ids_by_slug[$category] = wp_insert_category(array('cat_name' => $category, 'slug' => $category)); $nodes = explode('/', $category);
$parent = 0;
$joined_nodes = array();
foreach ($nodes as $node) {
$joined_nodes[] = $node;
$parent = $category_ids_by_slug[implode('/', $joined_nodes)] = wp_insert_category(array('cat_name' => $node, 'slug' => $node, 'category_parent' => $parent));
}
} }
} }
return $category_ids_by_slug; return $category_ids_by_slug;

View File

@ -111,7 +111,8 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
return array( return array(
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)),
); );
} }
@ -164,6 +165,16 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
'test' => 'test2' 'test' => 'test2'
)) ))
), ),
array(
array(
array(
'post_title' => 'test',
'categories' => array('test', 'test2/test3')
)
),
array(1),
array(1 => array(1,3))
),
); );
} }
@ -174,7 +185,7 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
update_option('default_category', 1); update_option('default_category', 1);
wp_insert_category(array('slug' => 'test')); wp_insert_category(array('slug' => 'test'));
$this->assertEquals($expected_post_ids, $this->pf->create_posts($posts, array('test' => 1, 'test2' => 2))); $this->assertEquals($expected_post_ids, $this->pf->create_posts($posts, array('test' => 1, 'test2' => 2, 'test2/test3' => 3)));
if (is_array($expected_post_categories)) { if (is_array($expected_post_categories)) {
foreach ($expected_post_categories as $post_id => $categories) { foreach ($expected_post_categories as $post_id => $categories) {