allow for parent/child categories
This commit is contained in:
parent
5b9a966c0e
commit
df5c47e2d3
@ -129,7 +129,13 @@ class PostFixtures {
|
||||
$category_ids_by_slug = array();
|
||||
if (is_array($categories)) {
|
||||
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;
|
||||
|
@ -111,7 +111,8 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
|
||||
return array(
|
||||
array(false, 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'
|
||||
))
|
||||
),
|
||||
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);
|
||||
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)) {
|
||||
foreach ($expected_post_categories as $post_id => $categories) {
|
||||
|
Loading…
Reference in New Issue
Block a user