| | 812 | |
| | 813 | /** |
| | 814 | * @ticket 24674 |
| | 815 | */ |
| | 816 | public function test_is_page_with_page_id_zero_and_random_page_slug() { |
| | 817 | $post_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); |
| | 818 | $this->go_to( "/?page_id=$post_id" ); |
| | 819 | |
| | 820 | // override post ID to 0 temporarily for testing |
| | 821 | $_id = $GLOBALS['wp_query']->post->ID; |
| | 822 | $GLOBALS['wp_query']->post->ID = 0; |
| | 823 | |
| | 824 | $post = get_queried_object(); |
| | 825 | $q = $GLOBALS['wp_query']; |
| | 826 | |
| | 827 | $this->assertTrue( $q->is_page() ); |
| | 828 | $this->assertFalse( $q->is_page( 'sample-page' ) ); |
| | 829 | $this->assertFalse( $q->is_page( 'random-page-slug' ) ); |
| | 830 | |
| | 831 | // revert $wp_query global change |
| | 832 | $GLOBALS['wp_query']->post->ID = $_id; |
| | 833 | } |
| | 834 | |
| | 835 | /** |
| | 836 | * @ticket 24674 |
| | 837 | */ |
| | 838 | public function test_is_page_with_page_slug_that_begins_with_a_number_that_clashes_with_a_page_ID() { |
| | 839 | $p1 = $this->factory->post->create( array( 'post_type' => 'page' ) ); |
| | 840 | |
| | 841 | $p2_name = $p1 . '-page'; |
| | 842 | $p2 = $this->factory->post->create( array( |
| | 843 | 'post_type' => 'page', |
| | 844 | 'post_name' => $p2_name, |
| | 845 | ) ); |
| | 846 | |
| | 847 | $this->go_to( "/?page_id=$p1" ); |
| | 848 | |
| | 849 | $q = $GLOBALS['wp_query']; |
| | 850 | |
| | 851 | $this->assertTrue( $q->is_page() ); |
| | 852 | $this->assertTrue( $q->is_page( $p1 ) ); |
| | 853 | $this->assertFalse( $q->is_page( $p2_name ) ); |
| | 854 | $this->assertFalse( $q->is_page( $p2 ) ); |
| | 855 | } |