Changeset 42343 for trunk/tests/phpunit/tests/post/listPages.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/listPages.php
r39363 r42343 31 31 $wpdb->query( 'TRUNCATE ' . $wpdb->prefix . 'posts' ); 32 32 $this->time = time(); 33 $post_date = date( 'Y-m-d H:i:s', $this->time );34 $pages = array();33 $post_date = date( 'Y-m-d H:i:s', $this->time ); 34 $pages = array(); 35 35 self::factory()->user->create(); 36 $pages[] = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 1', 'post_date' => $post_date ) ); 37 $pages[] = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 2', 'post_date' => $post_date ) ); 38 $pages[] = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 3', 'post_author' => '2', 'post_date' => $post_date ) ); 36 $pages[] = self::factory()->post->create( 37 array( 38 'post_type' => 'page', 39 'post_title' => 'Parent 1', 40 'post_date' => $post_date, 41 ) 42 ); 43 $pages[] = self::factory()->post->create( 44 array( 45 'post_type' => 'page', 46 'post_title' => 'Parent 2', 47 'post_date' => $post_date, 48 ) 49 ); 50 $pages[] = self::factory()->post->create( 51 array( 52 'post_type' => 'page', 53 'post_title' => 'Parent 3', 54 'post_author' => '2', 55 'post_date' => $post_date, 56 ) 57 ); 39 58 40 59 foreach ( $pages as $page ) { 41 $this->pages[$page] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', 'post_title' => 'Child 1', 'post_date' => $post_date ) ); 42 $this->pages[$page] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', 'post_title' => 'Child 2', 'post_date' => $post_date ) ); 43 $this->pages[$page] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', 'post_title' => 'Child 3', 'post_date' => $post_date ) ); 60 $this->pages[ $page ] = self::factory()->post->create( 61 array( 62 'post_parent' => $page, 63 'post_type' => 'page', 64 'post_title' => 'Child 1', 65 'post_date' => $post_date, 66 ) 67 ); 68 $this->pages[ $page ] = self::factory()->post->create( 69 array( 70 'post_parent' => $page, 71 'post_type' => 'page', 72 'post_title' => 'Child 2', 73 'post_date' => $post_date, 74 ) 75 ); 76 $this->pages[ $page ] = self::factory()->post->create( 77 array( 78 'post_parent' => $page, 79 'post_type' => 'page', 80 'post_title' => 'Child 3', 81 'post_date' => $post_date, 82 ) 83 ); 44 84 } 45 85 } 46 86 47 87 function test_wp_list_pages_default() { 48 $args = array(49 'echo' => false 88 $args = array( 89 'echo' => false, 50 90 ); 51 91 $expected['default'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a> … … 71 111 </li> 72 112 </ul></li>'; 73 $actual = wp_list_pages( $args );113 $actual = wp_list_pages( $args ); 74 114 $this->AssertEquals( $expected['default'], $actual ); 75 115 } 76 116 77 117 function test_wp_list_pages_depth() { 78 $args = array(79 'echo' 80 'depth' => 1 118 $args = array( 119 'echo' => false, 120 'depth' => 1, 81 121 ); 82 122 $expected['depth'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a></li> … … 84 124 <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a></li> 85 125 </ul></li>'; 86 $actual = wp_list_pages( $args );126 $actual = wp_list_pages( $args ); 87 127 $this->AssertEquals( $expected['depth'], $actual ); 88 128 } 89 129 90 130 function test_wp_list_pages_show_date() { 91 $args = array(92 'echo' => false,93 'depth' => 1,94 'show_date' => true 95 ); 96 $date = date( get_option( 'date_format' ), $this->time );131 $args = array( 132 'echo' => false, 133 'depth' => 1, 134 'show_date' => true, 135 ); 136 $date = date( get_option( 'date_format' ), $this->time ); 97 137 $expected['show_date'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a> ' . $date . '</li> 98 138 <li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a> ' . $date . '</li> 99 139 <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a> ' . $date . '</li> 100 140 </ul></li>'; 101 $actual = wp_list_pages( $args );141 $actual = wp_list_pages( $args ); 102 142 $this->AssertEquals( $expected['show_date'], $actual ); 103 143 } 104 144 105 145 function test_wp_list_pages_date_format() { 106 $args = array(107 'echo' => false,108 'show_date' => true,109 'date_format' => 'l, F j, Y' 110 ); 111 $date = date( $args['date_format'], $this->time );146 $args = array( 147 'echo' => false, 148 'show_date' => true, 149 'date_format' => 'l, F j, Y', 150 ); 151 $date = date( $args['date_format'], $this->time ); 112 152 $expected['date_format'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a> ' . $date . ' 113 153 <ul class=\'children\'> … … 132 172 </li> 133 173 </ul></li>'; 134 $actual = wp_list_pages( $args );174 $actual = wp_list_pages( $args ); 135 175 $this->AssertEquals( $expected['date_format'], $actual ); 136 176 } 137 177 138 178 function test_wp_list_pages_child_of() { 139 $args = array(140 'echo' => false,141 'child_of' => 2 179 $args = array( 180 'echo' => false, 181 'child_of' => 2, 142 182 ); 143 183 $expected['child_of'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-7"><a href="' . get_permalink( 7 ) . '">Child 1</a></li> … … 145 185 <li class="page_item page-item-9"><a href="' . get_permalink( 9 ) . '">Child 3</a></li> 146 186 </ul></li>'; 147 $actual = wp_list_pages( $args );187 $actual = wp_list_pages( $args ); 148 188 $this->AssertEquals( $expected['child_of'], $actual ); 149 189 } 150 190 151 191 function test_wp_list_pages_exclude() { 152 $args = array(153 'echo' => false,154 'exclude' => '2, 2' 192 $args = array( 193 'echo' => false, 194 'exclude' => '2, 2', 155 195 ); 156 196 $expected['exclude'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a> … … 172 212 <li class="page_item page-item-9"><a href="' . get_permalink( 9 ) . '">Child 3</a></li> 173 213 </ul></li>'; 174 $actual = wp_list_pages( $args );214 $actual = wp_list_pages( $args ); 175 215 $this->AssertEquals( $expected['exclude'], $actual ); 176 216 } 177 217 178 218 function test_wp_list_pages_title_li() { 179 $args = array(180 'echo' => false,181 'depth' => 1,182 'title_li' => 'PageTitle' 219 $args = array( 220 'echo' => false, 221 'depth' => 1, 222 'title_li' => 'PageTitle', 183 223 ); 184 224 $expected['title_li'] = '<li class="pagenav">PageTitle<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a></li> … … 186 226 <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a></li> 187 227 </ul></li>'; 188 $actual = wp_list_pages( $args );228 $actual = wp_list_pages( $args ); 189 229 $this->AssertEquals( $expected['title_li'], $actual ); 190 230 } 191 231 192 232 function test_wp_list_pages_echo() { 193 $args = array(194 'echo' => true,195 'depth' => 1 233 $args = array( 234 'echo' => true, 235 'depth' => 1, 196 236 ); 197 237 $expected['echo'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a></li> … … 206 246 207 247 function test_wp_list_pages_authors() { 208 $args = array(209 'echo' => false,248 $args = array( 249 'echo' => false, 210 250 'authors' => '2', 211 251 ); 212 $expected['authors'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-3"><a href="' . get_permalink( 3 ) . '">Parent 3</a></li>213 </ul></li>'; 214 $actual = wp_list_pages( $args );252 $expected['authors'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-3"><a href="' . get_permalink( 3 ) . '">Parent 3</a></li> 253 </ul></li>'; 254 $actual = wp_list_pages( $args ); 215 255 $this->AssertEquals( $expected['authors'], $actual ); 216 256 } 217 257 218 258 function test_wp_list_pages_number() { 219 $args = array(220 'echo' => false,259 $args = array( 260 'echo' => false, 221 261 'number' => 1, 222 262 ); 223 263 $expected['number'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-4"><a href="' . get_permalink( 4 ) . '">Child 1</a></li> 224 264 </ul></li>'; 225 $actual = wp_list_pages( $args );265 $actual = wp_list_pages( $args ); 226 266 $this->AssertEquals( $expected['number'], $actual ); 227 267 } 228 268 229 269 function test_wp_list_pages_sort_column() { 230 $args = array(231 'echo' => false,270 $args = array( 271 'echo' => false, 232 272 'sort_column' => 'post_author', 233 'sort_order' => 'DESC'273 'sort_order' => 'DESC', 234 274 ); 235 275 $expected['sort_column'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a> … … 255 295 </li> 256 296 </ul></li>'; 257 $actual = wp_list_pages( $args );297 $actual = wp_list_pages( $args ); 258 298 $this->AssertEquals( $expected['sort_column'], $actual ); 259 299 } 260 300 261 301 function test_wp_list_pages_link_before() { 262 $args = array(263 'echo' => false,264 'link_before' => 'BEFORE' 302 $args = array( 303 'echo' => false, 304 'link_before' => 'BEFORE', 265 305 ); 266 306 $expected['link_before'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">BEFOREParent 1</a> … … 286 326 </li> 287 327 </ul></li>'; 288 $actual = wp_list_pages( $args );328 $actual = wp_list_pages( $args ); 289 329 $this->AssertEquals( $expected['link_before'], $actual ); 290 330 } 291 331 292 332 function test_wp_list_pages_link_after() { 293 $args = array(294 'echo' => false,295 'link_after' => 'AFTER' 333 $args = array( 334 'echo' => false, 335 'link_after' => 'AFTER', 296 336 ); 297 337 $expected['link_after'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1AFTER</a> … … 317 357 </li> 318 358 </ul></li>'; 319 $actual = wp_list_pages( $args );359 $actual = wp_list_pages( $args ); 320 360 $this->AssertEquals( $expected['link_after'], $actual ); 321 361 } … … 323 363 324 364 function test_wp_list_pages_include() { 325 $args = array(326 'echo' => false,327 'include' => '1,3' 365 $args = array( 366 'echo' => false, 367 'include' => '1,3', 328 368 ); 329 369 $expected['include'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1"><a href="' . get_permalink( 1 ) . '">Parent 1</a></li> 330 370 <li class="page_item page-item-3"><a href="' . get_permalink( 3 ) . '">Parent 3</a></li> 331 371 </ul></li>'; 332 $actual = wp_list_pages( $args );372 $actual = wp_list_pages( $args ); 333 373 $this->AssertEquals( $expected['include'], $actual ); 334 374 } 335 375 336 376 function test_wp_list_pages_exclude_tree() { 337 $args = array(338 'echo' => false,339 'exclude_tree' => '2, 3' 377 $args = array( 378 'echo' => false, 379 'exclude_tree' => '2, 3', 340 380 ); 341 381 $expected['exclude'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a> … … 347 387 </li> 348 388 </ul></li>'; 349 $actual = wp_list_pages( $args );389 $actual = wp_list_pages( $args ); 350 390 $this->AssertEquals( $expected['exclude'], $actual ); 351 391 } 352 392 353 393 function test_wp_list_pages_discarded_whitespace() { 354 $args = array(355 'echo' => false,394 $args = array( 395 'echo' => false, 356 396 'item_spacing' => 'discard', 357 397 ); 358 398 $expected['default'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a><ul class=\'children\'><li class="page_item page-item-4"><a href="' . get_permalink( 4 ) . '">Child 1</a></li><li class="page_item page-item-5"><a href="' . get_permalink( 5 ) . '">Child 2</a></li><li class="page_item page-item-6"><a href="' . get_permalink( 6 ) . '">Child 3</a></li></ul></li><li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a><ul class=\'children\'><li class="page_item page-item-7"><a href="' . get_permalink( 7 ) . '">Child 1</a></li><li class="page_item page-item-8"><a href="' . get_permalink( 8 ) . '">Child 2</a></li><li class="page_item page-item-9"><a href="' . get_permalink( 9 ) . '">Child 3</a></li></ul></li><li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a><ul class=\'children\'><li class="page_item page-item-10"><a href="' . get_permalink( 10 ) . '">Child 1</a></li><li class="page_item page-item-11"><a href="' . get_permalink( 11 ) . '">Child 2</a></li><li class="page_item page-item-12"><a href="' . get_permalink( 12 ) . '">Child 3</a></li></ul></li></ul></li>'; 359 $actual = wp_list_pages( $args );399 $actual = wp_list_pages( $args ); 360 400 $this->AssertEquals( $expected['default'], $actual ); 361 401 }
Note: See TracChangeset
for help on using the changeset viewer.