From f391a933bd251a0366f6e636755b095a228f35cf Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 12 Feb 2010 18:47:48 -0500 Subject: [PATCH] fix for adding categories of multiple levels --- classes/FixtureBuilder.inc | 6 ++++-- test/FixtureBuilderTest.php | 13 +++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/classes/FixtureBuilder.inc b/classes/FixtureBuilder.inc index a7c5653..aecf687 100644 --- a/classes/FixtureBuilder.inc +++ b/classes/FixtureBuilder.inc @@ -131,10 +131,12 @@ class FixtureBuilder { $category_ids = array(); if (isset($obj['post']['categories'])) { $category_ids_by_slug = array(); + $category_ids = array(); foreach ($obj['post']['categories'] as $category) { - $category_ids_by_slug = array_merge($category_ids_by_slug, PostFixtures::create_category($category)); + $created_categories = PostFixtures::create_category($category); + $category_ids[] = array_pop(array_values($created_categories)); + $category_ids_by_slug = array_merge($category_ids_by_slug, $created_categories); } - $category_ids = array_values($category_ids_by_slug); PostFixtures::set_post_categories($post_id, $category_ids); } diff --git a/test/FixtureBuilderTest.php b/test/FixtureBuilderTest.php index 1399461..711efd4 100644 --- a/test/FixtureBuilderTest.php +++ b/test/FixtureBuilderTest.php @@ -132,7 +132,7 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase { ), array( 'categories', - array('test') + array('test/test2') ), array( 'metadata', @@ -163,7 +163,8 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase { ) ), 'categories' => array( - 1 => 'test' + 1 => 'test', + 2 => 'test2' ), 'tags' => array( 1 => array('tag1', 'tag2') @@ -172,6 +173,9 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase { 1 => array( 'test' => 'test2' ) + ), + 'post_categories' => array( + 1 => array(2) ) ) ), @@ -208,6 +212,11 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase { } } break; + case 'post_categories': + foreach ($info as $post_id => $expected_categories) { + $this->assertEquals($expected_categories, wp_get_post_categories($post_id)); + } + break; } }