From 33eeae55c84d85bd4861f2a7906381902387ec7f Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 22 Nov 2009 18:32:52 -0500 Subject: [PATCH] create categories --- classes/PostFixtures.inc | 10 ++++++++++ test/PostFixturesTest.php | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/classes/PostFixtures.inc b/classes/PostFixtures.inc index 0c5a486..fce6eb3 100644 --- a/classes/PostFixtures.inc +++ b/classes/PostFixtures.inc @@ -32,4 +32,14 @@ class PostFixtures { } return compact('posts', 'categories'); } + + function create_categories($categories) { + $category_ids_by_slug = array(); + if (is_array($categories)) { + foreach ($categories as $category) { + $category_ids_by_slug[$category] = wp_insert_category(array('slug' => $category)); + } + } + return $category_ids_by_slug; + } } diff --git a/test/PostFixturesTest.php b/test/PostFixturesTest.php index 69f9b6a..eb6ba5d 100644 --- a/test/PostFixturesTest.php +++ b/test/PostFixturesTest.php @@ -106,4 +106,21 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase { function testProcessData($data, $expected_output) { $this->assertEquals($expected_output, $this->pf->process_data($data)); } + + function providerTestCreateCategories() { + return array( + array(false, array()), + array(array(), array()), + array(array('test'), array('test' => 1)) + ); + } + + /** + * @dataProvider providerTestCreateCategories + */ + function testCreateCategories($input, $expected_output) { + global $wp_test_expectations; + + $this->assertEquals($expected_output, $this->pf->create_categories($input)); + } }