272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | 275 | * @ticket 14477 |
276 | 276 | */ |
277 | 277 | function test_get_pages_interrupted_hierarchy() { |
278 | 278 | $page1 = $this->factory->post->create( array( 'post_type' => 'page' ) ); |
279 | 279 | $page2 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page1 ) ); |
280 | 280 | add_post_meta( $page2, 'color', 'red' ); |
281 | 281 | $page3 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page2 ) ); |
282 | 282 | add_post_meta( $page3, 'color', 'blue' ); |
283 | 283 | |
284 | 284 | $pages = get_pages( array( 'child_of' => $page1, 'meta_key' => 'color', 'meta_value' => 'blue' ) ); |
285 | 285 | $this->assertEqualSets( array( $page3 ), wp_list_pluck( $pages, 'ID' ) ); |
286 | 286 | } |
| 287 | |
| 288 | /** |
| 289 | * @group 14477 |
| 290 | */ |
| 291 | function test_get_pages_broken_childs() { |
| 292 | /* |
| 293 | - A $parent_one |
| 294 | - B $parent_two |
| 295 | + BA $child_one |
| 296 | + BAA $grandchild_one |
| 297 | + BAAA $great_grandchild_one |
| 298 | + BAAB $great_grandchild_two |
| 299 | + BB $child_two |
| 300 | */ |
| 301 | |
| 302 | $parent_one = $this->factory->post->create( array( 'post_type' => 'page' ) ); |
| 303 | $parent_two = $this->factory->post->create( array( 'post_type' => 'page' ) ); |
| 304 | $child_one = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $parent_two ) ); |
| 305 | $grandchild_one = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $child_one ) ); |
| 306 | $great_grandchild_one = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $grandchild_one ) ); |
| 307 | $great_grandchild_two = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $grandchild_one ) ); |
| 308 | $child_two = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $parent_two ) ); |
| 309 | |
| 310 | $pages = get_pages( array( |
| 311 | 'child_of' => $parent_two, |
| 312 | ) ); |
| 313 | |
| 314 | $page_ids = wp_list_pluck( $pages, 'ID' ); |
| 315 | |
| 316 | // The expected structure, confirmed against 4.0 |
| 317 | $expected = array( |
| 318 | $child_one, |
| 319 | $grandchild_one, |
| 320 | $great_grandchild_one, |
| 321 | $great_grandchild_two, |
| 322 | $child_two |
| 323 | ); |
| 324 | |
| 325 | // The invalid output which 4.1 creates |
| 326 | $four_one_output = array( |
| 327 | $child_one, |
| 328 | $grandchild_one, |
| 329 | $great_grandchild_one, |
| 330 | $great_grandchild_two, |
| 331 | |
| 332 | $grandchild_one, |
| 333 | $great_grandchild_one, |
| 334 | $great_grandchild_two, |
| 335 | |
| 336 | $great_grandchild_one, |
| 337 | $great_grandchild_two, |
| 338 | $child_two |
| 339 | ); |
| 340 | |
| 341 | // Not assertEqualsSets, we want this EXACT set and order, no duplicates |
| 342 | //$this->assertEquals( $four_one_output, $page_ids ); |
| 343 | $this->assertEquals( $expected, $page_ids ); |
| 344 | |
| 345 | } |
| 346 | |