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