| 724 | /** |
| 725 | * @ticket 48556 |
| 726 | */ |
| 727 | public function test_query_posts_perm_readable_mutliple_post_types_with_private_posts() { |
| 728 | $current_user = get_current_user_id(); |
| 729 | wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); |
| 730 | |
| 731 | $public_post = $this->factory->post->create( array( 'post_title' => 'Test Post' ) ); |
| 732 | $private_post = $this->factory->post->create( array( 'post_title' => 'Test Post', 'post_status' => 'private' ) ); |
| 733 | |
| 734 | $public_page = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'Test Page' ) ); |
| 735 | $private_page = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'Test Page', 'post_status' => 'private' ) ); |
| 736 | |
| 737 | $q = new WP_Query( |
| 738 | array( |
| 739 | 'post_type' => ['post', 'page'] |
| 740 | ) |
| 741 | ); |
| 742 | |
| 743 | $this->assertEquals(4, $q->found_posts); |
| 744 | |
| 745 | wp_set_current_user( $current_user ); |
| 746 | |
| 747 | } |
| 748 | |
| 749 | /** |
| 750 | * @ticket 48556 |
| 751 | */ |
| 752 | public function test_query_posts_perm_readable_mutliple_post_types_with_private_posts_cpt_any() { |
| 753 | $current_user = get_current_user_id(); |
| 754 | wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); |
| 755 | |
| 756 | $public_post = $this->factory->post->create( array( 'post_title' => 'Test Post' ) ); |
| 757 | $private_post = $this->factory->post->create( array( 'post_title' => 'Test Post', 'post_status' => 'private' ) ); |
| 758 | |
| 759 | $public_page = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'Test Page' ) ); |
| 760 | $private_page = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'Test Page', 'post_status' => 'private' ) ); |
| 761 | |
| 762 | $q = new WP_Query( |
| 763 | array( |
| 764 | 'post_type' => 'any' |
| 765 | ) |
| 766 | ); |
| 767 | |
| 768 | $this->assertEquals(4, $q->found_posts); |
| 769 | |
| 770 | wp_set_current_user( $current_user ); |
| 771 | |
| 772 | } |
| 773 | |
| 774 | /** |
| 775 | * @ticket 48556 |
| 776 | */ |
| 777 | public function test_query_posts_perm_readable_mutliple_post_types_with_private_posts_user_permissions() { |
| 778 | global $current_user; |
| 779 | $current_user_id = get_current_user_id(); |
| 780 | |
| 781 | $public_post = $this->factory->post->create( array( 'post_title' => 'Test Post' ) ); |
| 782 | $private_post = $this->factory->post->create( array( 'post_title' => 'Test Post', 'post_status' => 'private' ) ); |
| 783 | |
| 784 | $public_page = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'Test Page' ) ); |
| 785 | $private_page = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'Test Page', 'post_status' => 'private' ) ); |
| 786 | |
| 787 | $subscriber = self::factory()->user->create( array( 'role' => 'subscriber' ) ); |
| 788 | $subscriber_user = get_userdata($subscriber); |
| 789 | |
| 790 | wp_set_current_user( $subscriber ); |
| 791 | |
| 792 | $q = new WP_Query( |
| 793 | array( |
| 794 | 'post_type' => ['post', 'page'] |
| 795 | ) |
| 796 | ); |
| 797 | |
| 798 | $this->assertEquals(2, $q->found_posts); |
| 799 | |
| 800 | $subscriber_user->add_cap('read_private_posts'); |
| 801 | $current_user = $subscriber_user; // ensure new cap is considered |
| 802 | |
| 803 | $q = new WP_Query( |
| 804 | array( |
| 805 | 'post_type' => ['post', 'page'] |
| 806 | ) |
| 807 | ); |
| 808 | |
| 809 | $this->assertEquals(3, $q->found_posts); |
| 810 | |
| 811 | $subscriber_user->add_cap('read_private_pages'); |
| 812 | $current_user = $subscriber_user; // ensure new cap is considered |
| 813 | |
| 814 | $q = new WP_Query( |
| 815 | array( |
| 816 | 'post_type' => ['post', 'page'] |
| 817 | ) |
| 818 | ); |
| 819 | |
| 820 | $this->assertEquals(4, $q->found_posts); |
| 821 | |
| 822 | wp_set_current_user( $current_user_id ); |
| 823 | |
| 824 | |
| 825 | } |
| 826 | |
| 827 | /** |
| 828 | * @ticket 48556 |
| 829 | */ |
| 830 | public function test_query_posts_perm_readable_mutliple_post_types_with_private_posts_user_permissions_cpt_any() { |
| 831 | global $current_user; |
| 832 | $current_user_id = get_current_user_id(); |
| 833 | |
| 834 | $public_post = $this->factory->post->create( array( 'post_title' => 'Test Post' ) ); |
| 835 | $private_post = $this->factory->post->create( array( 'post_title' => 'Test Post', 'post_status' => 'private' ) ); |
| 836 | |
| 837 | $public_page = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'Test Page' ) ); |
| 838 | $private_page = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'Test Page', 'post_status' => 'private' ) ); |
| 839 | |
| 840 | $subscriber = self::factory()->user->create( array( 'role' => 'subscriber' ) ); |
| 841 | $subscriber_user = get_userdata($subscriber); |
| 842 | |
| 843 | wp_set_current_user( $subscriber ); |
| 844 | |
| 845 | $q = new WP_Query( |
| 846 | array( |
| 847 | 'post_type' => 'any' |
| 848 | ) |
| 849 | ); |
| 850 | |
| 851 | $this->assertEquals(2, $q->found_posts); |
| 852 | |
| 853 | $subscriber_user->add_cap('read_private_posts'); |
| 854 | $current_user = $subscriber_user; // ensure new cap is considered |
| 855 | |
| 856 | $q = new WP_Query( |
| 857 | array( |
| 858 | 'post_type' => 'any' |
| 859 | ) |
| 860 | ); |
| 861 | |
| 862 | $this->assertEquals(3, $q->found_posts); |
| 863 | |
| 864 | $subscriber_user->add_cap('read_private_pages'); |
| 865 | $current_user = $subscriber_user; // ensure new cap is considered |
| 866 | |
| 867 | $q = new WP_Query( |
| 868 | array( |
| 869 | 'post_type' => 'any' |
| 870 | ) |
| 871 | ); |
| 872 | |
| 873 | $this->assertEquals(4, $q->found_posts); |
| 874 | |
| 875 | wp_set_current_user( $current_user_id ); |
| 876 | |
| 877 | |
| 878 | } |
| 879 | |