Changeset 42402 for trunk/tests/phpunit/tests/post/listPages.php
- Timestamp:
- 12/15/2017 11:15:00 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/listPages.php
r42382 r42402 1 1 <?php 2 2 3 /** 4 * @group post 5 */ 3 6 class Tests_List_Pages extends WP_UnitTestCase { 4 var $pages; 5 6 protected $time = null; 7 8 /* 9 $defaults = array( 10 'depth' => 0, 11 'show_date' => '', 12 'date_format' => get_option('date_format'), 13 'child_of' => 0, 14 'exclude' => '', 15 'title_li' => __('Pages'), 16 'echo' => 1, 17 'authors' => '', 18 'sort_column' => 'menu_order, post_title', 19 'link_before' => '', 20 'link_after' => '', 21 'walker' => '', 22 'item_spacing' => 'preserve', 23 'include' => '', 24 'post_type' => 'page', 25 'post_status' => 'publish', 26 ); 27 */ 28 function setUp() { 29 parent::setUp(); 30 global $wpdb; 31 $wpdb->query( 'TRUNCATE ' . $wpdb->prefix . 'posts' ); 32 $this->time = time(); 33 $post_date = date( 'Y-m-d H:i:s', $this->time ); 34 $pages = array(); 35 self::factory()->user->create(); 36 $pages[] = self::factory()->post->create( 7 /** 8 * Author user id. 9 * 10 * @var int 11 */ 12 public static $author; 13 14 /** 15 * Parent page id. 16 * 17 * @var int 18 */ 19 public static $parent_1; 20 21 /** 22 * Parent page id. 23 * 24 * @var int 25 */ 26 public static $parent_2; 27 28 /** 29 * Parent page id. 30 * 31 * @var int 32 */ 33 public static $parent_3; 34 35 /** 36 * Child page ids. 37 * 38 * @var array 39 */ 40 public static $children = array(); 41 42 /** 43 * Current timestamp cache, so that it is consistent across posts. 44 * 45 * @var int 46 */ 47 public static $time; 48 49 public static function wpSetupBeforeClass() { 50 self::$time = time(); 51 52 $post_date = date( 'Y-m-d H:i:s', self::$time ); 53 54 self::$parent_1 = self::factory()->post->create( 37 55 array( 38 56 'post_type' => 'page', … … 41 59 ) 42 60 ); 43 $pages[] = self::factory()->post->create( 61 62 self::$author = self::factory()->user->create( array( 'role' => 'author' ) ); 63 64 self::$parent_2 = self::factory()->post->create( 44 65 array( 45 66 'post_type' => 'page', … … 48 69 ) 49 70 ); 50 $pages[] = self::factory()->post->create( 71 72 self::$parent_3 = self::factory()->post->create( 51 73 array( 74 'post_author' => self::$author, 52 75 'post_type' => 'page', 53 76 'post_title' => 'Parent 3', 54 'post_author' => '2',55 77 'post_date' => $post_date, 56 78 ) 57 79 ); 58 80 59 foreach ( $pagesas $page ) {60 $this->pages[ $page] = self::factory()->post->create(81 foreach ( array( self::$parent_1, self::$parent_2, self::$parent_3 ) as $page ) { 82 self::$children[ $page ][] = self::factory()->post->create( 61 83 array( 62 84 'post_parent' => $page, … … 66 88 ) 67 89 ); 68 $this->pages[ $page] = self::factory()->post->create(90 self::$children[ $page ][] = self::factory()->post->create( 69 91 array( 70 92 'post_parent' => $page, … … 74 96 ) 75 97 ); 76 $this->pages[ $page] = self::factory()->post->create(98 self::$children[ $page ][] = self::factory()->post->create( 77 99 array( 78 100 'post_parent' => $page, … … 86 108 87 109 function test_wp_list_pages_default() { 88 $args 110 $args = array( 89 111 'echo' => false, 90 112 ); 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> 92 <ul class=\'children\'> 93 <li class="page_item page-item-4"><a href="' . get_permalink( 4 ) . '">Child 1</a></li> 94 <li class="page_item page-item-5"><a href="' . get_permalink( 5 ) . '">Child 2</a></li> 95 <li class="page_item page-item-6"><a href="' . get_permalink( 6 ) . '">Child 3</a></li> 96 </ul> 97 </li> 98 <li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a> 99 <ul class=\'children\'> 100 <li class="page_item page-item-7"><a href="' . get_permalink( 7 ) . '">Child 1</a></li> 101 <li class="page_item page-item-8"><a href="' . get_permalink( 8 ) . '">Child 2</a></li> 102 <li class="page_item page-item-9"><a href="' . get_permalink( 9 ) . '">Child 3</a></li> 103 </ul> 104 </li> 105 <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a> 106 <ul class=\'children\'> 107 <li class="page_item page-item-10"><a href="' . get_permalink( 10 ) . '">Child 1</a></li> 108 <li class="page_item page-item-11"><a href="' . get_permalink( 11 ) . '">Child 2</a></li> 109 <li class="page_item page-item-12"><a href="' . get_permalink( 12 ) . '">Child 3</a></li> 110 </ul> 111 </li> 112 </ul></li>'; 113 $actual = wp_list_pages( $args ); 114 $this->AssertEquals( $expected['default'], $actual ); 113 114 $expected = '<li class="pagenav">Pages<ul><li class="page_item page-item-' . self::$parent_1 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_1 ) . '">Parent 1</a> 115 <ul class=\'children\'> 116 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][0] ) . '">Child 1</a></li> 117 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][1] ) . '">Child 2</a></li> 118 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][2] ) . '">Child 3</a></li> 119 </ul> 120 </li> 121 <li class="page_item page-item-' . self::$parent_2 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_2 ) . '">Parent 2</a> 122 <ul class=\'children\'> 123 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][0] ) . '">Child 1</a></li> 124 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][1] ) . '">Child 2</a></li> 125 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][2] ) . '">Child 3</a></li> 126 </ul> 127 </li> 128 <li class="page_item page-item-' . self::$parent_3 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_3 ) . '">Parent 3</a> 129 <ul class=\'children\'> 130 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][0] ) . '">Child 1</a></li> 131 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][1] ) . '">Child 2</a></li> 132 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][2] ) . '">Child 3</a></li> 133 </ul> 134 </li> 135 </ul></li>'; 136 137 $this->AssertEquals( $expected, wp_list_pages( $args ) ); 115 138 } 116 139 117 140 function test_wp_list_pages_depth() { 118 $args 141 $args = array( 119 142 'echo' => false, 120 143 'depth' => 1, 121 144 ); 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> 123 <li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a></li> 124 <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a></li> 125 </ul></li>'; 126 $actual = wp_list_pages( $args ); 127 $this->AssertEquals( $expected['depth'], $actual ); 145 146 $expected = '<li class="pagenav">Pages<ul><li class="page_item page-item-' . self::$parent_1 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_1 ) . '">Parent 1</a></li> 147 <li class="page_item page-item-' . self::$parent_2 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_2 ) . '">Parent 2</a></li> 148 <li class="page_item page-item-' . self::$parent_3 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_3 ) . '">Parent 3</a></li> 149 </ul></li>'; 150 151 $this->AssertEquals( $expected, wp_list_pages( $args ) ); 128 152 } 129 153 130 154 function test_wp_list_pages_show_date() { 131 $args 155 $args = array( 132 156 'echo' => false, 133 157 'depth' => 1, 134 158 'show_date' => true, 135 159 ); 136 $date = date( get_option( 'date_format' ), $this->time ); 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> 138 <li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a> ' . $date . '</li> 139 <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a> ' . $date . '</li> 140 </ul></li>'; 141 $actual = wp_list_pages( $args ); 142 $this->AssertEquals( $expected['show_date'], $actual ); 160 $date = date( get_option( 'date_format' ), self::$time ); 161 162 $expected = '<li class="pagenav">Pages<ul><li class="page_item page-item-' . self::$parent_1 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_1 ) . '">Parent 1</a> ' . $date . '</li> 163 <li class="page_item page-item-' . self::$parent_2 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_2 ) . '">Parent 2</a> ' . $date . '</li> 164 <li class="page_item page-item-' . self::$parent_3 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_3 ) . '">Parent 3</a> ' . $date . '</li> 165 </ul></li>'; 166 167 $this->AssertEquals( $expected, wp_list_pages( $args ) ); 143 168 } 144 169 145 170 function test_wp_list_pages_date_format() { 146 $args 171 $args = array( 147 172 'echo' => false, 148 173 'show_date' => true, 149 174 'date_format' => 'l, F j, Y', 150 175 ); 151 $date = date( $args['date_format'], $this->time ); 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 . ' 153 <ul class=\'children\'> 154 <li class="page_item page-item-4"><a href="' . get_permalink( 4 ) . '">Child 1</a> ' . $date . '</li> 155 <li class="page_item page-item-5"><a href="' . get_permalink( 5 ) . '">Child 2</a> ' . $date . '</li> 156 <li class="page_item page-item-6"><a href="' . get_permalink( 6 ) . '">Child 3</a> ' . $date . '</li> 157 </ul> 158 </li> 159 <li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a> ' . $date . ' 160 <ul class=\'children\'> 161 <li class="page_item page-item-7"><a href="' . get_permalink( 7 ) . '">Child 1</a> ' . $date . '</li> 162 <li class="page_item page-item-8"><a href="' . get_permalink( 8 ) . '">Child 2</a> ' . $date . '</li> 163 <li class="page_item page-item-9"><a href="' . get_permalink( 9 ) . '">Child 3</a> ' . $date . '</li> 164 </ul> 165 </li> 166 <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a> ' . $date . ' 167 <ul class=\'children\'> 168 <li class="page_item page-item-10"><a href="' . get_permalink( 10 ) . '">Child 1</a> ' . $date . '</li> 169 <li class="page_item page-item-11"><a href="' . get_permalink( 11 ) . '">Child 2</a> ' . $date . '</li> 170 <li class="page_item page-item-12"><a href="' . get_permalink( 12 ) . '">Child 3</a> ' . $date . '</li> 171 </ul> 172 </li> 173 </ul></li>'; 174 $actual = wp_list_pages( $args ); 175 $this->AssertEquals( $expected['date_format'], $actual ); 176 $date = date( $args['date_format'], self::$time ); 177 178 $expected = '<li class="pagenav">Pages<ul><li class="page_item page-item-' . self::$parent_1 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_1 ) . '">Parent 1</a> ' . $date . ' 179 <ul class=\'children\'> 180 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][0] ) . '">Child 1</a> ' . $date . '</li> 181 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][1] ) . '">Child 2</a> ' . $date . '</li> 182 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][2] ) . '">Child 3</a> ' . $date . '</li> 183 </ul> 184 </li> 185 <li class="page_item page-item-' . self::$parent_2 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_2 ) . '">Parent 2</a> ' . $date . ' 186 <ul class=\'children\'> 187 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][0] ) . '">Child 1</a> ' . $date . '</li> 188 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][1] ) . '">Child 2</a> ' . $date . '</li> 189 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][2] ) . '">Child 3</a> ' . $date . '</li> 190 </ul> 191 </li> 192 <li class="page_item page-item-' . self::$parent_3 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_3 ) . '">Parent 3</a> ' . $date . ' 193 <ul class=\'children\'> 194 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][0] ) . '">Child 1</a> ' . $date . '</li> 195 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][1] ) . '">Child 2</a> ' . $date . '</li> 196 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][2] ) . '">Child 3</a> ' . $date . '</li> 197 </ul> 198 </li> 199 </ul></li>'; 200 201 $this->AssertEquals( $expected, wp_list_pages( $args ) ); 176 202 } 177 203 178 204 function test_wp_list_pages_child_of() { 179 $args 205 $args = array( 180 206 'echo' => false, 181 'child_of' => 2, 182 ); 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> 184 <li class="page_item page-item-8"><a href="' . get_permalink( 8 ) . '">Child 2</a></li> 185 <li class="page_item page-item-9"><a href="' . get_permalink( 9 ) . '">Child 3</a></li> 186 </ul></li>'; 187 $actual = wp_list_pages( $args ); 188 $this->AssertEquals( $expected['child_of'], $actual ); 207 'child_of' => self::$parent_2, 208 ); 209 210 $expected = '<li class="pagenav">Pages<ul><li class="page_item page-item-' . self::$children[ self::$parent_2 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][0] ) . '">Child 1</a></li> 211 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][1] ) . '">Child 2</a></li> 212 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][2] ) . '">Child 3</a></li> 213 </ul></li>'; 214 215 $this->AssertEquals( $expected, wp_list_pages( $args ) ); 189 216 } 190 217 191 218 function test_wp_list_pages_exclude() { 192 $args 219 $args = array( 193 220 'echo' => false, 194 'exclude' => '2, 2', 195 ); 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> 197 <ul class=\'children\'> 198 <li class="page_item page-item-4"><a href="' . get_permalink( 4 ) . '">Child 1</a></li> 199 <li class="page_item page-item-5"><a href="' . get_permalink( 5 ) . '">Child 2</a></li> 200 <li class="page_item page-item-6"><a href="' . get_permalink( 6 ) . '">Child 3</a></li> 201 </ul> 202 </li> 203 <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a> 204 <ul class=\'children\'> 205 <li class="page_item page-item-10"><a href="' . get_permalink( 10 ) . '">Child 1</a></li> 206 <li class="page_item page-item-11"><a href="' . get_permalink( 11 ) . '">Child 2</a></li> 207 <li class="page_item page-item-12"><a href="' . get_permalink( 12 ) . '">Child 3</a></li> 208 </ul> 209 </li> 210 <li class="page_item page-item-7"><a href="' . get_permalink( 7 ) . '">Child 1</a></li> 211 <li class="page_item page-item-8"><a href="' . get_permalink( 8 ) . '">Child 2</a></li> 212 <li class="page_item page-item-9"><a href="' . get_permalink( 9 ) . '">Child 3</a></li> 213 </ul></li>'; 214 $actual = wp_list_pages( $args ); 215 $this->AssertEquals( $expected['exclude'], $actual ); 221 'exclude' => self::$parent_2, 222 ); 223 224 $expected = '<li class="pagenav">Pages<ul><li class="page_item page-item-' . self::$parent_1 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_1 ) . '">Parent 1</a> 225 <ul class=\'children\'> 226 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][0] ) . '">Child 1</a></li> 227 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][1] ) . '">Child 2</a></li> 228 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][2] ) . '">Child 3</a></li> 229 </ul> 230 </li> 231 <li class="page_item page-item-' . self::$parent_3 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_3 ) . '">Parent 3</a> 232 <ul class=\'children\'> 233 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][0] ) . '">Child 1</a></li> 234 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][1] ) . '">Child 2</a></li> 235 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][2] ) . '">Child 3</a></li> 236 </ul> 237 </li> 238 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][0] ) . '">Child 1</a></li> 239 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][1] ) . '">Child 2</a></li> 240 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][2] ) . '">Child 3</a></li> 241 </ul></li>'; 242 243 $this->AssertEquals( $expected, wp_list_pages( $args ) ); 216 244 } 217 245 218 246 function test_wp_list_pages_title_li() { 219 $args 247 $args = array( 220 248 'echo' => false, 221 249 'depth' => 1, 222 250 'title_li' => 'PageTitle', 223 251 ); 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> 225 <li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a></li> 226 <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a></li> 227 </ul></li>'; 228 $actual = wp_list_pages( $args ); 229 $this->AssertEquals( $expected['title_li'], $actual ); 252 253 $expected = '<li class="pagenav">PageTitle<ul><li class="page_item page-item-' . self::$parent_1 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_1 ) . '">Parent 1</a></li> 254 <li class="page_item page-item-' . self::$parent_2 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_2 ) . '">Parent 2</a></li> 255 <li class="page_item page-item-' . self::$parent_3 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_3 ) . '">Parent 3</a></li> 256 </ul></li>'; 257 258 $this->AssertEquals( $expected, wp_list_pages( $args ) ); 230 259 } 231 260 232 261 function test_wp_list_pages_echo() { 233 $args 262 $args = array( 234 263 'echo' => true, 235 264 'depth' => 1, 236 265 ); 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> 238 <li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a></li> 239 <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a></li> 240 </ul></li>'; 241 $this->expectOutputString( $expected['echo'] ); 266 267 $expected = '<li class="pagenav">Pages<ul><li class="page_item page-item-' . self::$parent_1 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_1 ) . '">Parent 1</a></li> 268 <li class="page_item page-item-' . self::$parent_2 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_2 ) . '">Parent 2</a></li> 269 <li class="page_item page-item-' . self::$parent_3 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_3 ) . '">Parent 3</a></li> 270 </ul></li>'; 271 $this->expectOutputString( $expected ); 242 272 wp_list_pages( $args ); 243 273 } 244 274 245 275 function test_wp_list_pages_authors() { 246 $args 276 $args = array( 247 277 'echo' => false, 248 'authors' => '2', 249 ); 250 $expected['authors'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-3"><a href="' . get_permalink( 3 ) . '">Parent 3</a></li> 251 </ul></li>'; 252 $actual = wp_list_pages( $args ); 253 $this->AssertEquals( $expected['authors'], $actual ); 278 'authors' => self::$author, 279 ); 280 281 $expected = '<li class="pagenav">Pages<ul><li class="page_item page-item-' . self::$parent_3 . '"><a href="' . get_permalink( self::$parent_3 ) . '">Parent 3</a></li> 282 </ul></li>'; 283 284 $this->AssertEquals( $expected, wp_list_pages( $args ) ); 254 285 } 255 286 256 287 function test_wp_list_pages_number() { 257 $args 288 $args = array( 258 289 'echo' => false, 259 290 'number' => 1, 260 291 ); 261 $expected['number'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-4"><a href="' . get_permalink( 4 ) . '">Child 1</a></li> 262 </ul></li>'; 263 $actual = wp_list_pages( $args ); 264 $this->AssertEquals( $expected['number'], $actual ); 292 293 $expected = '<li class="pagenav">Pages<ul><li class="page_item page-item-' . self::$children[ self::$parent_1 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][0] ) . '">Child 1</a></li> 294 </ul></li>'; 295 296 $this->AssertEquals( $expected, wp_list_pages( $args ) ); 265 297 } 266 298 267 299 function test_wp_list_pages_sort_column() { 268 $args 300 $args = array( 269 301 'echo' => false, 270 302 'sort_column' => 'post_author', 271 303 'sort_order' => 'DESC', 272 304 ); 273 $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> 274 <ul class=\'children\'> 275 <li class="page_item page-item-10"><a href="' . get_permalink( 10 ) . '">Child 1</a></li> 276 <li class="page_item page-item-11"><a href="' . get_permalink( 11 ) . '">Child 2</a></li> 277 <li class="page_item page-item-12"><a href="' . get_permalink( 12 ) . '">Child 3</a></li> 278 </ul> 279 </li> 280 <li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a> 281 <ul class=\'children\'> 282 <li class="page_item page-item-4"><a href="' . get_permalink( 4 ) . '">Child 1</a></li> 283 <li class="page_item page-item-5"><a href="' . get_permalink( 5 ) . '">Child 2</a></li> 284 <li class="page_item page-item-6"><a href="' . get_permalink( 6 ) . '">Child 3</a></li> 285 </ul> 286 </li> 287 <li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a> 288 <ul class=\'children\'> 289 <li class="page_item page-item-7"><a href="' . get_permalink( 7 ) . '">Child 1</a></li> 290 <li class="page_item page-item-8"><a href="' . get_permalink( 8 ) . '">Child 2</a></li> 291 <li class="page_item page-item-9"><a href="' . get_permalink( 9 ) . '">Child 3</a></li> 292 </ul> 293 </li> 294 </ul></li>'; 295 $actual = wp_list_pages( $args ); 296 $this->AssertEquals( $expected['sort_column'], $actual ); 305 306 $expected = '<li class="pagenav">Pages<ul><li class="page_item page-item-' . self::$parent_3 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_3 ) . '">Parent 3</a> 307 <ul class=\'children\'> 308 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][0] ) . '">Child 1</a></li> 309 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][1] ) . '">Child 2</a></li> 310 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][2] ) . '">Child 3</a></li> 311 </ul> 312 </li> 313 <li class="page_item page-item-' . self::$parent_1 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_1 ) . '">Parent 1</a> 314 <ul class=\'children\'> 315 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][0] ) . '">Child 1</a></li> 316 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][1] ) . '">Child 2</a></li> 317 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][2] ) . '">Child 3</a></li> 318 </ul> 319 </li> 320 <li class="page_item page-item-' . self::$parent_2 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_2 ) . '">Parent 2</a> 321 <ul class=\'children\'> 322 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][0] ) . '">Child 1</a></li> 323 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][1] ) . '">Child 2</a></li> 324 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][2] ) . '">Child 3</a></li> 325 </ul> 326 </li> 327 </ul></li>'; 328 329 $this->AssertEquals( $expected, wp_list_pages( $args ) ); 297 330 } 298 331 299 332 function test_wp_list_pages_link_before() { 300 $args 333 $args = array( 301 334 'echo' => false, 302 335 'link_before' => 'BEFORE', 303 336 ); 304 $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> 305 <ul class=\'children\'> 306 <li class="page_item page-item-4"><a href="' . get_permalink( 4 ) . '">BEFOREChild 1</a></li> 307 <li class="page_item page-item-5"><a href="' . get_permalink( 5 ) . '">BEFOREChild 2</a></li> 308 <li class="page_item page-item-6"><a href="' . get_permalink( 6 ) . '">BEFOREChild 3</a></li> 309 </ul> 310 </li> 311 <li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">BEFOREParent 2</a> 312 <ul class=\'children\'> 313 <li class="page_item page-item-7"><a href="' . get_permalink( 7 ) . '">BEFOREChild 1</a></li> 314 <li class="page_item page-item-8"><a href="' . get_permalink( 8 ) . '">BEFOREChild 2</a></li> 315 <li class="page_item page-item-9"><a href="' . get_permalink( 9 ) . '">BEFOREChild 3</a></li> 316 </ul> 317 </li> 318 <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">BEFOREParent 3</a> 319 <ul class=\'children\'> 320 <li class="page_item page-item-10"><a href="' . get_permalink( 10 ) . '">BEFOREChild 1</a></li> 321 <li class="page_item page-item-11"><a href="' . get_permalink( 11 ) . '">BEFOREChild 2</a></li> 322 <li class="page_item page-item-12"><a href="' . get_permalink( 12 ) . '">BEFOREChild 3</a></li> 323 </ul> 324 </li> 325 </ul></li>'; 326 $actual = wp_list_pages( $args ); 327 $this->AssertEquals( $expected['link_before'], $actual ); 337 338 $expected = '<li class="pagenav">Pages<ul><li class="page_item page-item-' . self::$parent_1 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_1 ) . '">BEFOREParent 1</a> 339 <ul class=\'children\'> 340 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][0] ) . '">BEFOREChild 1</a></li> 341 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][1] ) . '">BEFOREChild 2</a></li> 342 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][2] ) . '">BEFOREChild 3</a></li> 343 </ul> 344 </li> 345 <li class="page_item page-item-' . self::$parent_2 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_2 ) . '">BEFOREParent 2</a> 346 <ul class=\'children\'> 347 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][0] ) . '">BEFOREChild 1</a></li> 348 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][1] ) . '">BEFOREChild 2</a></li> 349 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][2] ) . '">BEFOREChild 3</a></li> 350 </ul> 351 </li> 352 <li class="page_item page-item-' . self::$parent_3 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_3 ) . '">BEFOREParent 3</a> 353 <ul class=\'children\'> 354 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][0] ) . '">BEFOREChild 1</a></li> 355 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][1] ) . '">BEFOREChild 2</a></li> 356 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][2] ) . '">BEFOREChild 3</a></li> 357 </ul> 358 </li> 359 </ul></li>'; 360 361 $this->AssertEquals( $expected, wp_list_pages( $args ) ); 328 362 } 329 363 330 364 function test_wp_list_pages_link_after() { 331 $args 365 $args = array( 332 366 'echo' => false, 333 367 'link_after' => 'AFTER', 334 368 ); 335 $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> 336 <ul class=\'children\'> 337 <li class="page_item page-item-4"><a href="' . get_permalink( 4 ) . '">Child 1AFTER</a></li> 338 <li class="page_item page-item-5"><a href="' . get_permalink( 5 ) . '">Child 2AFTER</a></li> 339 <li class="page_item page-item-6"><a href="' . get_permalink( 6 ) . '">Child 3AFTER</a></li> 340 </ul> 341 </li> 342 <li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2AFTER</a> 343 <ul class=\'children\'> 344 <li class="page_item page-item-7"><a href="' . get_permalink( 7 ) . '">Child 1AFTER</a></li> 345 <li class="page_item page-item-8"><a href="' . get_permalink( 8 ) . '">Child 2AFTER</a></li> 346 <li class="page_item page-item-9"><a href="' . get_permalink( 9 ) . '">Child 3AFTER</a></li> 347 </ul> 348 </li> 349 <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3AFTER</a> 350 <ul class=\'children\'> 351 <li class="page_item page-item-10"><a href="' . get_permalink( 10 ) . '">Child 1AFTER</a></li> 352 <li class="page_item page-item-11"><a href="' . get_permalink( 11 ) . '">Child 2AFTER</a></li> 353 <li class="page_item page-item-12"><a href="' . get_permalink( 12 ) . '">Child 3AFTER</a></li> 354 </ul> 355 </li> 356 </ul></li>'; 357 $actual = wp_list_pages( $args ); 358 $this->AssertEquals( $expected['link_after'], $actual ); 369 370 $expected = '<li class="pagenav">Pages<ul><li class="page_item page-item-' . self::$parent_1 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_1 ) . '">Parent 1AFTER</a> 371 <ul class=\'children\'> 372 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][0] ) . '">Child 1AFTER</a></li> 373 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][1] ) . '">Child 2AFTER</a></li> 374 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][2] ) . '">Child 3AFTER</a></li> 375 </ul> 376 </li> 377 <li class="page_item page-item-' . self::$parent_2 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_2 ) . '">Parent 2AFTER</a> 378 <ul class=\'children\'> 379 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][0] ) . '">Child 1AFTER</a></li> 380 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][1] ) . '">Child 2AFTER</a></li> 381 <li class="page_item page-item-' . self::$children[ self::$parent_2 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][2] ) . '">Child 3AFTER</a></li> 382 </ul> 383 </li> 384 <li class="page_item page-item-' . self::$parent_3 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_3 ) . '">Parent 3AFTER</a> 385 <ul class=\'children\'> 386 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][0] ) . '">Child 1AFTER</a></li> 387 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][1] ) . '">Child 2AFTER</a></li> 388 <li class="page_item page-item-' . self::$children[ self::$parent_3 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][2] ) . '">Child 3AFTER</a></li> 389 </ul> 390 </li> 391 </ul></li>'; 392 393 $this->AssertEquals( $expected, wp_list_pages( $args ) ); 359 394 } 360 395 361 396 362 397 function test_wp_list_pages_include() { 363 $args 398 $args = array( 364 399 'echo' => false, 365 'include' => '1,3', 366 ); 367 $expected['include'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1"><a href="' . get_permalink( 1 ) . '">Parent 1</a></li> 368 <li class="page_item page-item-3"><a href="' . get_permalink( 3 ) . '">Parent 3</a></li> 369 </ul></li>'; 370 $actual = wp_list_pages( $args ); 371 $this->AssertEquals( $expected['include'], $actual ); 400 'include' => self::$parent_1 . ',' . self::$parent_3, 401 ); 402 403 $expected = '<li class="pagenav">Pages<ul><li class="page_item page-item-' . self::$parent_1 . '"><a href="' . get_permalink( self::$parent_1 ) . '">Parent 1</a></li> 404 <li class="page_item page-item-' . self::$parent_3 . '"><a href="' . get_permalink( self::$parent_3 ) . '">Parent 3</a></li> 405 </ul></li>'; 406 407 $this->AssertEquals( $expected, wp_list_pages( $args ) ); 372 408 } 373 409 374 410 function test_wp_list_pages_exclude_tree() { 375 $args 411 $args = array( 376 412 'echo' => false, 377 'exclude_tree' => '2, 3', 378 ); 379 $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> 380 <ul class=\'children\'> 381 <li class="page_item page-item-4"><a href="' . get_permalink( 4 ) . '">Child 1</a></li> 382 <li class="page_item page-item-5"><a href="' . get_permalink( 5 ) . '">Child 2</a></li> 383 <li class="page_item page-item-6"><a href="' . get_permalink( 6 ) . '">Child 3</a></li> 384 </ul> 385 </li> 386 </ul></li>'; 387 $actual = wp_list_pages( $args ); 388 $this->AssertEquals( $expected['exclude'], $actual ); 413 'exclude_tree' => self::$parent_2 . ',' . self::$parent_3, 414 ); 415 416 $expected = '<li class="pagenav">Pages<ul><li class="page_item page-item-' . self::$parent_1 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_1 ) . '">Parent 1</a> 417 <ul class=\'children\'> 418 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][0] ) . '">Child 1</a></li> 419 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][1] ) . '">Child 2</a></li> 420 <li class="page_item page-item-' . self::$children[ self::$parent_1 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][2] ) . '">Child 3</a></li> 421 </ul> 422 </li> 423 </ul></li>'; 424 425 $this->AssertEquals( $expected, wp_list_pages( $args ) ); 389 426 } 390 427 391 428 function test_wp_list_pages_discarded_whitespace() { 392 $args 429 $args = array( 393 430 'echo' => false, 394 431 'item_spacing' => 'discard', 395 432 ); 396 $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>'; 397 $actual = wp_list_pages( $args ); 398 $this->AssertEquals( $expected['default'], $actual ); 433 434 $expected = '<li class="pagenav">Pages<ul><li class="page_item page-item-' . self::$parent_1 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_1 ) . '">Parent 1</a><ul class=\'children\'><li class="page_item page-item-' . self::$children[ self::$parent_1 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][0] ) . '">Child 1</a></li><li class="page_item page-item-' . self::$children[ self::$parent_1 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][1] ) . '">Child 2</a></li><li class="page_item page-item-' . self::$children[ self::$parent_1 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_1 ][2] ) . '">Child 3</a></li></ul></li><li class="page_item page-item-' . self::$parent_2 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_2 ) . '">Parent 2</a><ul class=\'children\'><li class="page_item page-item-' . self::$children[ self::$parent_2 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][0] ) . '">Child 1</a></li><li class="page_item page-item-' . self::$children[ self::$parent_2 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][1] ) . '">Child 2</a></li><li class="page_item page-item-' . self::$children[ self::$parent_2 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_2 ][2] ) . '">Child 3</a></li></ul></li><li class="page_item page-item-' . self::$parent_3 . ' page_item_has_children"><a href="' . get_permalink( self::$parent_3 ) . '">Parent 3</a><ul class=\'children\'><li class="page_item page-item-' . self::$children[ self::$parent_3 ][0] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][0] ) . '">Child 1</a></li><li class="page_item page-item-' . self::$children[ self::$parent_3 ][1] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][1] ) . '">Child 2</a></li><li class="page_item page-item-' . self::$children[ self::$parent_3 ][2] . '"><a href="' . get_permalink( self::$children[ self::$parent_3 ][2] ) . '">Child 3</a></li></ul></li></ul></li>'; 435 436 $this->AssertEquals( $expected, wp_list_pages( $args ) ); 399 437 } 400 438 }
Note: See TracChangeset
for help on using the changeset viewer.