Make WordPress Core

Ticket #22074: 22074.2.diff

File 22074.2.diff, 4.8 KB (added by wonderboymusic, 12 years ago)
  • tests/phpunit/tests/post.php

     
    1919                wp_set_current_user( $this->old_current_user );
    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() {
    3737                register_post_type( 'cpt', array( 'taxonomies' => array( 'post_tag', 'ctax' ) ) );
     
    707707         */
    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(
    715715                        'post_author' => $this->author_id,
     
    722722                );
    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 );
    728728                $this->assertEquals( $post->post_title, $title );
     
    733733         */
    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(
    741741                        'post_author' => $this->author_id,
     
    748748                );
    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 ) );
    758758        }
     
    762762         */
    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(
    770770                        // post_author not set
     
    798798                _unregister_post_type( $post_type );
    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}
  • src/wp-includes/post.php

     
    36713671                $cache = array();
    36723672
    36733673        $inclusions = '';
    3674         if ( !empty($include) ) {
     3674        if ( ! empty( $include ) ) {
    36753675                $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include
    36763676                $parent = -1;
    36773677                $exclude = '';
     
    36793679                $meta_value = '';
    36803680                $hierarchical = false;
    36813681                $incpages = wp_parse_id_list( $include );
    3682                 if ( ! empty( $incpages ) ) {
    3683                         foreach ( $incpages as $incpage ) {
    3684                                 if (empty($inclusions))
    3685                                         $inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage);
    3686                                 else
    3687                                         $inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage);
    3688                         }
    3689                 }
     3682                if ( ! empty( $incpages ) )
     3683                        $inclusions = ' AND ID IN (' . implode( ',', array_map( 'intval', $incpages ) ) .  ')';
    36903684        }
    3691         if (!empty($inclusions))
    3692                 $inclusions .= ')';
    36933685
    36943686        $exclusions = '';
    3695         if ( !empty($exclude) ) {
     3687        if ( ! empty( $exclude ) ) {
    36963688                $expages = wp_parse_id_list( $exclude );
    3697                 if ( ! empty( $expages ) ) {
    3698                         foreach ( $expages as $expage ) {
    3699                                 if (empty($exclusions))
    3700                                         $exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage);
    3701                                 else
    3702                                         $exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage);
    3703                         }
    3704                 }
     3689                if ( ! empty( $expages ) )
     3690                        $exclusions = ' AND ID NOT IN (' . implode( ',', array_map( 'intval', $expages ) ) .  ')';
    37053691        }
    3706         if (!empty($exclusions))
    3707                 $exclusions .= ')';
    37083692
    37093693        $author_query = '';
    37103694        if (!empty($authors)) {