| 1 | Index: tests/post/query.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- tests/post/query.php (revision 1084) |
|---|
| 4 | +++ tests/post/query.php (working copy) |
|---|
| 5 | @@ -409,4 +409,91 @@ |
|---|
| 6 | $posts = wp_list_pluck( $posts, 'ID' ); |
|---|
| 7 | $this->assertEquals( array(), array_diff( array( $post_id, $post_id3, $post_id4, $post_id5, $post_id6 ), $posts ) ); |
|---|
| 8 | } |
|---|
| 9 | + |
|---|
| 10 | + function test_taxonomy_include_children() { |
|---|
| 11 | + $cat_a = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'Australia' ) ); |
|---|
| 12 | + $cat_b = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'Sydney', 'parent' => $cat_a ) ); |
|---|
| 13 | + $cat_c = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'East Syndney', 'parent' => $cat_b ) ); |
|---|
| 14 | + $cat_d = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'West Syndney', 'parent' => $cat_b ) ); |
|---|
| 15 | + |
|---|
| 16 | + $post_a = $this->factory->post->create( array( 'post_category' => array( $cat_a ) ) ); |
|---|
| 17 | + $post_b = $this->factory->post->create( array( 'post_category' => array( $cat_b ) ) ); |
|---|
| 18 | + $post_c = $this->factory->post->create( array( 'post_category' => array( $cat_c ) ) ); |
|---|
| 19 | + $post_d = $this->factory->post->create( array( 'post_category' => array( $cat_d ) ) ); |
|---|
| 20 | + |
|---|
| 21 | + $posts = get_posts( array( |
|---|
| 22 | + 'tax_query' => array( |
|---|
| 23 | + array( |
|---|
| 24 | + 'taxonomy' => 'category', |
|---|
| 25 | + 'field' => 'id', |
|---|
| 26 | + 'terms' => array( $cat_a ), |
|---|
| 27 | + ) |
|---|
| 28 | + ) |
|---|
| 29 | + ) ); |
|---|
| 30 | + |
|---|
| 31 | + $this->assertEquals( 4 , count( $posts ) ); |
|---|
| 32 | + |
|---|
| 33 | + $posts = get_posts( array( |
|---|
| 34 | + 'tax_query' => array( |
|---|
| 35 | + array( |
|---|
| 36 | + 'taxonomy' => 'category', |
|---|
| 37 | + 'field' => 'id', |
|---|
| 38 | + 'terms' => array( $cat_a ), |
|---|
| 39 | + 'include_children' => false |
|---|
| 40 | + ) |
|---|
| 41 | + ) |
|---|
| 42 | + ) ); |
|---|
| 43 | + |
|---|
| 44 | + $this->assertEquals( 1 , count( $posts ) ); |
|---|
| 45 | + |
|---|
| 46 | + $posts = get_posts( array( |
|---|
| 47 | + 'tax_query' => array( |
|---|
| 48 | + array( |
|---|
| 49 | + 'taxonomy' => 'category', |
|---|
| 50 | + 'field' => 'id', |
|---|
| 51 | + 'terms' => array( $cat_b ), |
|---|
| 52 | + ) |
|---|
| 53 | + ) |
|---|
| 54 | + ) ); |
|---|
| 55 | + |
|---|
| 56 | + $this->assertEquals( 3 , count( $posts ) ); |
|---|
| 57 | + |
|---|
| 58 | + $posts = get_posts( array( |
|---|
| 59 | + 'tax_query' => array( |
|---|
| 60 | + array( |
|---|
| 61 | + 'taxonomy' => 'category', |
|---|
| 62 | + 'field' => 'id', |
|---|
| 63 | + 'terms' => array( $cat_b ), |
|---|
| 64 | + 'include_children' => false |
|---|
| 65 | + ) |
|---|
| 66 | + ) |
|---|
| 67 | + ) ); |
|---|
| 68 | + |
|---|
| 69 | + $this->assertEquals( 1 , count( $posts ) ); |
|---|
| 70 | + |
|---|
| 71 | + $posts = get_posts( array( |
|---|
| 72 | + 'tax_query' => array( |
|---|
| 73 | + array( |
|---|
| 74 | + 'taxonomy' => 'category', |
|---|
| 75 | + 'field' => 'id', |
|---|
| 76 | + 'terms' => array( $cat_c ), |
|---|
| 77 | + ) |
|---|
| 78 | + ) |
|---|
| 79 | + ) ); |
|---|
| 80 | + |
|---|
| 81 | + $this->assertEquals( 1 , count( $posts ) ); |
|---|
| 82 | + |
|---|
| 83 | + $posts = get_posts( array( |
|---|
| 84 | + 'tax_query' => array( |
|---|
| 85 | + array( |
|---|
| 86 | + 'taxonomy' => 'category', |
|---|
| 87 | + 'field' => 'id', |
|---|
| 88 | + 'terms' => array( $cat_c ), |
|---|
| 89 | + 'include_children' => false |
|---|
| 90 | + ) |
|---|
| 91 | + ) |
|---|
| 92 | + ) ); |
|---|
| 93 | + |
|---|
| 94 | + $this->assertEquals( 1 , count( $posts ) ); |
|---|
| 95 | + } |
|---|
| 96 | } |
|---|