create categories

This commit is contained in:
John Bintz 2009-11-22 18:32:52 -05:00
parent fe4f6a867b
commit 33eeae55c8
2 changed files with 27 additions and 0 deletions

View File

@ -32,4 +32,14 @@ class PostFixtures {
} }
return compact('posts', 'categories'); 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;
}
} }

View File

@ -106,4 +106,21 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
function testProcessData($data, $expected_output) { function testProcessData($data, $expected_output) {
$this->assertEquals($expected_output, $this->pf->process_data($data)); $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));
}
} }