Make WordPress Core


Ignore:
Timestamp:
08/29/2013 06:48:29 PM (11 years ago)
Author:
wonderboymusic
Message:

Improve the include / exclude SQL generation in get_pages() by using IN and NOT IN where applicable. Adds unit tests for include / exclude.

Fixes #22074.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post.php

    r25002 r25168  
    2020        parent::tearDown();
    2121    }
    22    
     22
    2323    // helper function: return the timestamp(s) of cron jobs for the specified hook and post
    2424    function _next_schedule_for_post($hook, $id) {
    2525        return wp_next_scheduled('publish_future_post', array(0=>intval($id)));
    2626    }
    27    
     27
    2828    // helper function, unsets current user globally
    2929    function _unset_current_user() {
    3030        global $current_user, $user_ID;
    31        
     31
    3232        $current_user = $user_ID = null;
    3333    }
    34    
     34
    3535    // test simple valid behavior: insert and get a post
    3636    function test_vb_insert_get_delete() {
     
    708708    function test_insert_programmatic_sanitized() {
    709709        $this->_unset_current_user();
    710        
     710
    711711        register_taxonomy( 'test_tax', 'post' );
    712        
     712
    713713        $title = rand_str();
    714714        $post_data = array(
     
    723723        $insert_post_id = wp_insert_post( $post_data, true, true );
    724724        $this->assertTrue( ( is_int($insert_post_id) && $insert_post_id > 0 ) );
    725        
     725
    726726        $post = get_post( $insert_post_id );
    727727        $this->assertEquals( $post->post_author, $this->author_id );
     
    734734    function test_insert_programmatic_without_current_user_success() {
    735735        $this->_unset_current_user();
    736        
     736
    737737        register_taxonomy( 'test_tax', 'post' );
    738        
     738
    739739        $title = rand_str();
    740740        $post_data = array(
     
    749749        // with sanitize set to false
    750750        $insert_post_id = wp_insert_post( $post_data, true, false );
    751        
     751
    752752        $post = get_post( $insert_post_id );
    753753        $this->assertEquals( $post->post_author, $this->author_id );
    754754        $this->assertEquals( $post->post_title, $title );
    755        
     755
    756756        $terms = wp_get_object_terms( $insert_post_id, 'test_tax' );
    757757        $this->assertTrue( ( is_array( $terms ) && count( $terms ) == 3 ) );
     
    763763    function test_insert_programmatic_without_current_user_fail() {
    764764        $this->_unset_current_user();
    765        
     765
    766766        register_taxonomy( 'test_tax', 'post' );
    767        
     767
    768768        $title = rand_str();
    769769        $post_data = array(
     
    799799        $this->assertEquals( new stdClass, wp_count_posts( $post_type, 'readable' ) );
    800800    }
     801
     802    /**
     803     * @ticket 22074
     804     */
     805    function test_get_pages_include_exclude() {
     806        $page_ids = array();
     807
     808        foreach ( range( 1, 20 ) as $i )
     809            $page_ids[] = $this->factory->post->create( array( 'post_type' => 'page' ) );
     810
     811        $inc = array_slice( $page_ids, 0, 10 );
     812        sort( $inc );
     813        $exc = array_slice( $page_ids, 10 );
     814        sort( $exc );
     815
     816        $include = get_pages( array( 'include' => $inc ) );
     817        $inc_result = wp_list_pluck( $include, 'ID' );
     818        sort( $inc_result );
     819        $this->assertEquals( $inc, $inc_result );
     820
     821        $exclude = get_pages( array( 'exclude' => $exc ) );
     822        $exc_result = wp_list_pluck( $exclude, 'ID' );
     823        sort( $exc_result );
     824        $this->assertEquals( $inc, $exc_result );
     825    }
    801826}
Note: See TracChangeset for help on using the changeset viewer.