WordPress.org

Make WordPress Core

Changeset 26087


Ignore:
Timestamp:
11/11/2013 05:45:36 PM (7 years ago)
Author:
wonderboymusic
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/xmlrpc/wp/getPosts.php

    r25002 r26087  
    5252        ));
    5353
     54        $post_ids = array();
    5455        $num_posts = 17;
    55         $post_ids = $this->factory->post->create_many( $num_posts, array( 'post_type' => $cpt_name ) );
    56 
     56        foreach ( range( 1, $num_posts ) as $i ) {
     57            $post_ids[] = $this->factory->post->create( array(
     58                'post_type' => $cpt_name,
     59                'post_date' => date( 'Y-m-d H:i:s', time() + $i )
     60            ) );
     61        }
    5762        // get them all
    5863        $filter = array( 'post_type' => $cpt_name, 'number' => $num_posts + 10 );
     
    6772        do {
    6873            $presults = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter ) );
    69             foreach( $presults as $post ) {
    70                 $posts_found[] = $post['post_id'];
    71             }
     74            $posts_found = array_merge( $posts_found, wp_list_pluck( $presults, 'post_id' ) );
    7275            $filter['offset'] += $filter['number'];
    7376        } while ( count( $presults ) > 0 );
Note: See TracChangeset for help on using the changeset viewer.