Changeset 55569 for trunk/tests/phpunit/tests/post/getPages.php
- Timestamp:
- 03/21/2023 12:47:20 PM (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/getPages.php
r54402 r55569 67 67 clean_post_cache( $pages[0]->ID ); 68 68 $this->assertNotEquals( $time1, $time2 = wp_cache_get( 'last_changed', 'posts' ) ); 69 69 get_post( $pages[0]->ID ); 70 70 $num_queries = $wpdb->num_queries; 71 71 … … 171 171 $found_ids = wp_list_pluck( $found, 'ID' ); 172 172 $this->assertSameSets( array( $posts[0] ), $found_ids ); 173 } 174 175 /** 176 * @ticket 12821 177 * @covers ::get_pages 178 */ 179 public function test_include_ignore_meta_key() { 180 $posts = self::factory()->post->create_many( 181 2, 182 array( 183 'post_type' => 'page', 184 ) 185 ); 186 187 $pages = get_pages( 188 array( 189 'include' => $posts, 190 'meta_key' => 'foo', 191 'meta_value' => 'bar', 192 ) 193 ); 194 195 $page_ids = wp_list_pluck( $pages, 'ID' ); 196 $this->assertSameSets( $posts, $page_ids ); 197 } 198 199 /** 200 * @ticket 12821 201 * @covers ::get_pages 202 */ 203 public function test_include_ignore_exclude() { 204 $includes = self::factory()->post->create_many( 205 2, 206 array( 207 'post_type' => 'page', 208 ) 209 ); 210 211 $excludes = self::factory()->post->create_many( 212 2, 213 array( 214 'post_type' => 'page', 215 ) 216 ); 217 218 $pages = get_pages( 219 array( 220 'include' => $includes, 221 'exclude' => $excludes, 222 ) 223 ); 224 225 $page_ids = wp_list_pluck( $pages, 'ID' ); 226 $this->assertSameSets( $includes, $page_ids ); 173 227 } 174 228 … … 720 774 $this->assertSame( $num_queries, $wpdb->num_queries ); 721 775 } 776 777 /** 778 * @ticket 12821 779 * @covers ::get_pages 780 */ 781 public function test_get_pages_post_type() { 782 register_post_type( 'wptests_pt', array( 'hierarchical' => true ) ); 783 $posts = self::factory()->post->create_many( 2, array( 'post_type' => 'wptests_pt' ) ); 784 $pages = get_pages( 785 array( 786 'post_type' => 'wptests_pt', 787 ) 788 ); 789 $this->assertSameSets( $posts, wp_list_pluck( $pages, 'ID' ) ); 790 } 791 792 793 /** 794 * @ticket 12821 795 * @covers ::get_pages 796 */ 797 public function test_get_pages_author() { 798 $author_1 = self::factory()->user->create( 799 array( 800 'user_login' => 'author1', 801 'role' => 'author', 802 ) 803 ); 804 $posts = self::factory()->post->create_many( 805 2, 806 array( 807 'post_type' => 'page', 808 'post_author' => $author_1, 809 ) 810 ); 811 $pages = get_pages( 812 array( 813 'authors' => $author_1, 814 ) 815 ); 816 817 $this->assertSameSets( $posts, wp_list_pluck( $pages, 'ID' ) ); 818 } 819 820 821 /** 822 * @ticket 12821 823 * @covers ::get_pages 824 */ 825 public function test_get_pages_post_status() { 826 register_post_status( 827 'foo', 828 array( 829 'public' => true, 830 ) 831 ); 832 833 $posts = self::factory()->post->create_many( 834 2, 835 array( 836 'post_type' => 'page', 837 'post_status' => 'foo', 838 ) 839 ); 840 $pages = get_pages( 841 array( 842 'post_status' => 'foo', 843 ) 844 ); 845 846 $this->assertSameSets( $posts, wp_list_pluck( $pages, 'ID' ) ); 847 } 848 849 /** 850 * @ticket 12821 851 * @covers ::get_pages 852 */ 853 public function test_get_pages_offset() { 854 $posts = self::factory()->post->create_many( 4, array( 'post_type' => 'page' ) ); 855 $pages = get_pages( 856 array( 857 'offset' => 2, 858 'number' => 2, 859 ) 860 ); 861 862 $this->assertSameSets( array( $posts[2], $posts[3] ), wp_list_pluck( $pages, 'ID' ) ); 863 } 864 865 866 /** 867 * @ticket 12821 868 * @covers ::get_pages 869 */ 870 public function test_get_pages_authors() { 871 $author_1 = self::factory()->user->create( 872 array( 873 'user_login' => 'author1', 874 'role' => 'author', 875 ) 876 ); 877 $post_1 = self::factory()->post->create( 878 array( 879 'post_title' => 'Page 1', 880 'post_type' => 'page', 881 'post_author' => $author_1, 882 'post_date' => '2007-01-01 00:00:00', 883 ) 884 ); 885 886 $author_2 = self::factory()->user->create( 887 array( 888 'user_login' => 'author2', 889 'role' => 'author', 890 ) 891 ); 892 $post_2 = self::factory()->post->create( 893 array( 894 'post_title' => 'Page 2', 895 'post_type' => 'page', 896 'post_author' => $author_2, 897 'post_date' => '2007-01-01 00:00:00', 898 ) 899 ); 900 $pages = get_pages( 901 array( 902 'authors' => "{$author_1}, {$author_2}", 903 ) 904 ); 905 906 $this->assertSameSets( array( $post_1, $post_2 ), wp_list_pluck( $pages, 'ID' ) ); 907 } 908 909 /** 910 * @ticket 12821 911 * @covers ::get_pages 912 */ 913 public function test_get_pages_authors_names() { 914 $author_1 = self::factory()->user->create( 915 array( 916 'user_login' => 'author1', 917 'role' => 'author', 918 ) 919 ); 920 $post_1 = self::factory()->post->create( 921 array( 922 'post_title' => 'Page 1', 923 'post_type' => 'page', 924 'post_author' => $author_1, 925 'post_date' => '2007-01-01 00:00:00', 926 ) 927 ); 928 929 $author_2 = self::factory()->user->create( 930 array( 931 'user_login' => 'author2', 932 'role' => 'author', 933 ) 934 ); 935 $post_2 = self::factory()->post->create( 936 array( 937 'post_title' => 'Page 2', 938 'post_type' => 'page', 939 'post_author' => $author_2, 940 'post_date' => '2007-01-01 00:00:00', 941 ) 942 ); 943 $pages = get_pages( 944 array( 945 'authors' => 'author1, author2', 946 ) 947 ); 948 949 $this->assertSameSets( array( $post_1, $post_2 ), wp_list_pluck( $pages, 'ID' ) ); 950 } 951 952 /** 953 * @ticket 12821 954 * @covers ::get_pages 955 */ 956 public function test_orderby() { 957 global $wpdb; 958 // 'rand' is a valid value. 959 get_pages( array( 'sort_column' => 'rand' ) ); 960 $this->assertStringContainsString( 'ORDER BY RAND()', $wpdb->last_query, 'Check order is random' ); 961 962 // This isn't allowed. 963 get_pages( array( 'sort_order' => 'rand' ) ); 964 $this->assertStringContainsString( 'ORDER BY', $wpdb->last_query, 'Check orderby is present' ); 965 $this->assertStringNotContainsString( 'RAND()', $wpdb->last_query, 'Check order is random is not present' ); 966 $this->assertStringContainsString( 'DESC', $wpdb->last_query, 'Check DESC is random is not present' ); 967 968 // 'none' is a valid value. 969 get_pages( array( 'sort_column' => 'none' ) ); 970 $this->assertStringNotContainsString( 'ORDER BY', $wpdb->last_query, 'Check orderby is not present' ); 971 $this->assertStringNotContainsString( 'DESC', $wpdb->last_query, 'Check DESC is not present' ); 972 $this->assertStringNotContainsString( 'ASC', $wpdb->last_query, 'Check ASC is not present' ); 973 974 // False is a valid value. 975 get_pages( array( 'sort_column' => false ) ); 976 $this->assertStringContainsString( 'ORDER BY', $wpdb->last_query, 'Check orderby is present if sort_column equal false is passed.' ); 977 978 // Empty array() is a valid value. 979 get_pages( array( 'sort_column' => array() ) ); 980 $this->assertStringContainsString( 'ORDER BY', $wpdb->last_query, 'Check orderby is present if sort_column equals an empty array is passed.' ); 981 } 982 983 /** 984 * @ticket 12821 985 * @covers ::get_pages 986 */ 987 public function test_order() { 988 global $wpdb; 989 990 get_pages( 991 array( 992 'sort_column' => 'post_type', 993 ) 994 ); 995 $this->assertStringContainsString( 996 "ORDER BY $wpdb->posts.post_type ASC", 997 $wpdb->last_query, 998 'Check order is post type' 999 ); 1000 1001 get_pages( 1002 array( 1003 'sort_column' => 'title', 1004 'sort_order' => 'foo', 1005 ) 1006 ); 1007 $this->assertStringContainsString( 1008 "ORDER BY $wpdb->posts.post_title DESC", 1009 $wpdb->last_query, 1010 'Check order is default' 1011 ); 1012 1013 get_pages( 1014 array( 1015 'sort_order' => 'asc', 1016 'sort_column' => 'date', 1017 ) 1018 ); 1019 $this->assertStringContainsString( 1020 "ORDER BY $wpdb->posts.post_date ASC", 1021 $wpdb->last_query, 1022 'Check order is post date' 1023 ); 1024 } 722 1025 }
Note: See TracChangeset
for help on using the changeset viewer.