| 137 | /* |
| 138 | * @ticket 15667 |
| 139 | */ |
| 140 | function test_get_pages_exclude_with_children() { |
| 141 | |
| 142 | $page_1 = $this->factory->post->create( array( 'post_type' => 'page' ) ); |
| 143 | $page_1_child = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) ); |
| 144 | $page_2 = $this->factory->post->create( array( 'post_type' => 'page' ) ); |
| 145 | $page_2_child = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_2 ) ); |
| 146 | |
| 147 | // If hierarchical is false get_pages returns the children even though the parents are excluded |
| 148 | $pages = get_pages( 'hierarchical=0&exclude=' . implode( ',', array( $page_1, $page_2 ) ) ); |
| 149 | $this->assertEqualSets( array( $page_1_child, $page_2_child ), wp_list_pluck( $pages, 'ID' ) ); |
| 150 | |
| 151 | // If hierarchical is true get_pages doesn't return the children if the parents are excluded |
| 152 | $pages = get_pages( 'hierarchical=1&exclude=' . implode( ',', array( $page_1, $page_2 ) ) ); |
| 153 | $this->assertEmpty( $pages ); |
| 154 | |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | * @ticket 15667 |
| 159 | */ |
| 160 | function test_get_pages_exclude_tree() { |
| 161 | |
| 162 | $page_1 = $this->factory->post->create( array( 'post_type' => 'page' ) ); |
| 163 | $page_1_child = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) ); |
| 164 | $page_2 = $this->factory->post->create( array( 'post_type' => 'page' ) ); |
| 165 | $page_2_child = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_2 ) ); |
| 166 | |
| 167 | // exclude_tree always excludes the children regardless of what hierarchical is set to |
| 168 | $pages = get_pages( 'hierarchical=0&exclude_tree=' . $page_1 ); |
| 169 | $this->assertEqualSets( array( $page_2, $page_2_child ), wp_list_pluck( $pages, 'ID' ) ); |
| 170 | $pages = get_pages( 'hierarchical=1&exclude_tree=' . $page_1 ); |
| 171 | $this->assertEqualSets( array( $page_2, $page_2_child ), wp_list_pluck( $pages, 'ID' ) ); |
| 172 | |
| 173 | // You can only pass a single ID to exclude_tree |
| 174 | $pages = get_pages( 'exclude_tree=' . implode( ',', array( $page_1, $page_2 ) ) ); |
| 175 | $this->assertEqualSets( array( $page_2, $page_2_child ), wp_list_pluck( $pages, 'ID' ) ); |
| 176 | } |
| 177 | |