From 0fdff310fdeb1fb320424a30c80e65c68ab3ef39 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 11 Nov 2013 17:45:36 +0000 Subject: [PATCH] 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 --- tests/phpunit/tests/xmlrpc/wp/getPosts.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/tests/xmlrpc/wp/getPosts.php b/tests/phpunit/tests/xmlrpc/wp/getPosts.php index c001d7a249..c15cdfb83c 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getPosts.php +++ b/tests/phpunit/tests/xmlrpc/wp/getPosts.php @@ -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