Ticket #22074: 22074.2.diff
File 22074.2.diff, 4.8 KB (added by , 12 years ago) |
---|
-
tests/phpunit/tests/post.php
19 19 wp_set_current_user( $this->old_current_user ); 20 20 parent::tearDown(); 21 21 } 22 22 23 23 // helper function: return the timestamp(s) of cron jobs for the specified hook and post 24 24 function _next_schedule_for_post($hook, $id) { 25 25 return wp_next_scheduled('publish_future_post', array(0=>intval($id))); 26 26 } 27 27 28 28 // helper function, unsets current user globally 29 29 function _unset_current_user() { 30 30 global $current_user, $user_ID; 31 31 32 32 $current_user = $user_ID = null; 33 33 } 34 34 35 35 // test simple valid behavior: insert and get a post 36 36 function test_vb_insert_get_delete() { 37 37 register_post_type( 'cpt', array( 'taxonomies' => array( 'post_tag', 'ctax' ) ) ); … … 707 707 */ 708 708 function test_insert_programmatic_sanitized() { 709 709 $this->_unset_current_user(); 710 710 711 711 register_taxonomy( 'test_tax', 'post' ); 712 712 713 713 $title = rand_str(); 714 714 $post_data = array( 715 715 'post_author' => $this->author_id, … … 722 722 ); 723 723 $insert_post_id = wp_insert_post( $post_data, true, true ); 724 724 $this->assertTrue( ( is_int($insert_post_id) && $insert_post_id > 0 ) ); 725 725 726 726 $post = get_post( $insert_post_id ); 727 727 $this->assertEquals( $post->post_author, $this->author_id ); 728 728 $this->assertEquals( $post->post_title, $title ); … … 733 733 */ 734 734 function test_insert_programmatic_without_current_user_success() { 735 735 $this->_unset_current_user(); 736 736 737 737 register_taxonomy( 'test_tax', 'post' ); 738 738 739 739 $title = rand_str(); 740 740 $post_data = array( 741 741 'post_author' => $this->author_id, … … 748 748 ); 749 749 // with sanitize set to false 750 750 $insert_post_id = wp_insert_post( $post_data, true, false ); 751 751 752 752 $post = get_post( $insert_post_id ); 753 753 $this->assertEquals( $post->post_author, $this->author_id ); 754 754 $this->assertEquals( $post->post_title, $title ); 755 755 756 756 $terms = wp_get_object_terms( $insert_post_id, 'test_tax' ); 757 757 $this->assertTrue( ( is_array( $terms ) && count( $terms ) == 3 ) ); 758 758 } … … 762 762 */ 763 763 function test_insert_programmatic_without_current_user_fail() { 764 764 $this->_unset_current_user(); 765 765 766 766 register_taxonomy( 'test_tax', 'post' ); 767 767 768 768 $title = rand_str(); 769 769 $post_data = array( 770 770 // post_author not set … … 798 798 _unregister_post_type( $post_type ); 799 799 $this->assertEquals( new stdClass, wp_count_posts( $post_type, 'readable' ) ); 800 800 } 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 } 801 826 } -
src/wp-includes/post.php
3671 3671 $cache = array(); 3672 3672 3673 3673 $inclusions = ''; 3674 if ( ! empty($include) ) {3674 if ( ! empty( $include ) ) { 3675 3675 $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include 3676 3676 $parent = -1; 3677 3677 $exclude = ''; … … 3679 3679 $meta_value = ''; 3680 3680 $hierarchical = false; 3681 3681 $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 ) ) . ')'; 3690 3684 } 3691 if (!empty($inclusions))3692 $inclusions .= ')';3693 3685 3694 3686 $exclusions = ''; 3695 if ( ! empty($exclude) ) {3687 if ( ! empty( $exclude ) ) { 3696 3688 $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 ) ) . ')'; 3705 3691 } 3706 if (!empty($exclusions))3707 $exclusions .= ')';3708 3692 3709 3693 $author_query = ''; 3710 3694 if (!empty($authors)) {