diff --git a/classes/PostFixtures.inc b/classes/PostFixtures.inc index a706b55..9fd72a8 100644 --- a/classes/PostFixtures.inc +++ b/classes/PostFixtures.inc @@ -9,4 +9,10 @@ class PostFixtures { } return false; } + + function remove_all_posts() { + if (is_array($posts = get_posts('nopaging=1'))) { + foreach ($posts as $post) { wp_delete_post($post->ID); } + } + } } diff --git a/test/PostFixturesTest.php b/test/PostFixturesTest.php index 9b90d6f..87dff55 100644 --- a/test/PostFixturesTest.php +++ b/test/PostFixturesTest.php @@ -29,4 +29,27 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase { function testParseJSON($input, $expected_output) { $this->assertEquals($expected_output, $this->pf->parse_json($input)); } + + function testRemoveAllPosts() { + global $wp_test_expectations; + + $posts = array(); + + for ($i = 0; $i < 5; ++$i) { + $post = (object)array('ID' => $i); + wp_insert_post($post); + $posts[] = $post; + update_post_meta($i, md5(rand()), md5(rand())); + } + + _set_up_get_posts_response('nopaging=1', $posts); + + $this->assertEquals(5, count($wp_test_expectations['posts'])); + $this->assertEquals(5, count($wp_test_expectations['post_meta'])); + + $this->pf->remove_all_posts(); + + $this->assertEquals(0, count($wp_test_expectations['posts'])); + $this->assertEquals(0, count($wp_test_expectations['post_meta'])); + } }