Fix a failing unit test: an XML-RPC unit test for getPosts with filters was failing. The cause of the failure: a set of posts was created with create_many() and then paginated results were requested. The paginated results were meant to equal the original resultset when diff'd after all pages were joined. create_many() was assigning the same timestamp to all posts, so the LIMIT clause in the generated SQL was not operating as expected. I replaced the create_many() call with a create() loop that increments time by 1 each time. Unit test now passes.

git-svn-id: https://develop.svn.wordpress.org/trunk@26087 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2013-11-11 17:45:36 +00:00
parent 315681a8ed
commit 0fdff310fd
1 changed files with 8 additions and 5 deletions

View File

@ -51,9 +51,14 @@ class Tests_XMLRPC_wp_getPosts extends WP_XMLRPC_UnitTestCase {
'public' => true
));
$post_ids = array();
$num_posts = 17;
$post_ids = $this->factory->post->create_many( $num_posts, array( 'post_type' => $cpt_name ) );
foreach ( range( 1, $num_posts ) as $i ) {
$post_ids[] = $this->factory->post->create( array(
'post_type' => $cpt_name,
'post_date' => date( 'Y-m-d H:i:s', time() + $i )
) );
}
// get them all
$filter = array( 'post_type' => $cpt_name, 'number' => $num_posts + 10 );
$results = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter ) );
@ -66,9 +71,7 @@ class Tests_XMLRPC_wp_getPosts extends WP_XMLRPC_UnitTestCase {
$filter['offset'] = 0;
do {
$presults = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter ) );
foreach( $presults as $post ) {
$posts_found[] = $post['post_id'];
}
$posts_found = array_merge( $posts_found, wp_list_pluck( $presults, 'post_id' ) );
$filter['offset'] += $filter['number'];
} while ( count( $presults ) > 0 );
// verify that $post_ids matches $posts_found