remove all posts

This commit is contained in:
John Bintz 2009-11-22 17:34:57 -05:00
parent 5ebf8b450e
commit d69d1111f2
2 changed files with 29 additions and 0 deletions

View File

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

View File

@ -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']));
}
}