diff --git a/classes/PostFixtures.inc b/classes/PostFixtures.inc index 9fd72a8..cdb3233 100644 --- a/classes/PostFixtures.inc +++ b/classes/PostFixtures.inc @@ -15,4 +15,10 @@ class PostFixtures { foreach ($posts as $post) { wp_delete_post($post->ID); } } } + + function remove_all_categories() { + foreach (get_all_category_ids() as $id) { + wp_delete_category($id); + } + } } diff --git a/test/PostFixturesTest.php b/test/PostFixturesTest.php index 87dff55..3cb8788 100644 --- a/test/PostFixturesTest.php +++ b/test/PostFixturesTest.php @@ -52,4 +52,21 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase { $this->assertEquals(0, count($wp_test_expectations['posts'])); $this->assertEquals(0, count($wp_test_expectations['post_meta'])); } + + function testRemoveAllCategories() { + global $wp_test_expectations; + update_option('default_category', 0); + + for ($i = 0; $i < 5; ++$i) { + add_category($i, (object)array('slug' => 'test-' . $i)); + } + + $this->assertEquals(5, count($wp_test_expectations['categories'])); + + $this->pf->remove_all_categories(); + + $this->assertEquals(1, count($wp_test_expectations['categories'])); + $result = get_category(0); + $this->assertTrue(isset($result->term_id)); + } }