| 125 | |
| 126 | /** |
| 127 | * @ticket 31355 |
| 128 | */ |
| 129 | public function test_pages_dont_404_when_queried_post_id_is_modified() { |
| 130 | $post_id = $this->factory->post->create( array( 'post_title' => 'A Test Page', 'post_type' => 'page' ) ); |
| 131 | |
| 132 | add_action( 'parse_query', array( $this, 'filter_parse_query_to_modify_queried_post_id' ) ); |
| 133 | |
| 134 | $url = get_permalink( $post_id ); |
| 135 | $this->go_to( $url ); |
| 136 | |
| 137 | remove_action( 'parse_query', array( $this, 'filter_parse_query_to_modify_queried_post_id' ) ); |
| 138 | |
| 139 | $this->assertFalse( $GLOBALS['wp_query']->is_404() ); |
| 140 | $this->assertEquals( $post_id, $GLOBALS['wp_query']->post->ID ); |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * @ticket 31355 |
| 145 | */ |
| 146 | public function test_custom_hierarchical_post_types_404_when_queried_post_id_is_modified() { |
| 147 | global $wp_rewrite; |
| 148 | |
| 149 | register_post_type( 'guide', array( 'name' => 'Guide', 'public' => true, 'hierarchical' => true ) ); |
| 150 | $wp_rewrite->flush_rules(); |
| 151 | $post_id = $this->factory->post->create( array( 'post_title' => 'A Test Guide', 'post_type' => 'guide' ) ); |
| 152 | |
| 153 | add_action( 'parse_query', array( $this, 'filter_parse_query_to_modify_queried_post_id' ) ); |
| 154 | |
| 155 | $url = get_permalink( $post_id ); |
| 156 | $this->go_to( $url ); |
| 157 | |
| 158 | remove_action( 'parse_query', array( $this, 'filter_parse_query_to_modify_queried_post_id' ) ); |
| 159 | |
| 160 | $this->assertFalse( $GLOBALS['wp_query']->is_404() ); |
| 161 | $this->assertEquals( $post_id, $GLOBALS['wp_query']->post->ID ); |
| 162 | } |
| 163 | |
| 164 | public function filter_parse_query_to_modify_queried_post_id( $query ) { |
| 165 | $post = get_queried_object(); |
| 166 | } |