Changeset 42343 for trunk/tests/phpunit/tests/general/paginateLinks.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/general/paginateLinks.php
r41371 r42343 12 12 13 13 function test_defaults() { 14 $page2 = get_pagenum_link( 2 );15 $page3 = get_pagenum_link( 3 );14 $page2 = get_pagenum_link( 2 ); 15 $page3 = get_pagenum_link( 3 ); 16 16 $page50 = get_pagenum_link( 50 ); 17 17 18 $expected = <<<EXPECTED18 $expected = <<<EXPECTED 19 19 <span aria-current='page' class='page-numbers current'>1</span> 20 20 <a class='page-numbers' href='$page2'>2</a> … … 30 30 31 31 function test_format() { 32 $page2 = home_url( '/page/2/' );33 $page3 = home_url( '/page/3/' );32 $page2 = home_url( '/page/2/' ); 33 $page3 = home_url( '/page/3/' ); 34 34 $page50 = home_url( '/page/50/' ); 35 35 36 $expected = <<<EXPECTED36 $expected = <<<EXPECTED 37 37 <span aria-current='page' class='page-numbers current'>1</span> 38 38 <a class='page-numbers' href='$page2'>2</a> … … 43 43 EXPECTED; 44 44 45 $links = paginate_links( array( 'total' => 50, 'format' => 'page/%#%/' ) ); 45 $links = paginate_links( 46 array( 47 'total' => 50, 48 'format' => 'page/%#%/', 49 ) 50 ); 46 51 $this->assertEquals( $expected, $links ); 47 52 } 48 53 49 54 function test_prev_next_false() { 50 $home = home_url( '/' );51 $page3 = get_pagenum_link( 3 );52 $page4 = get_pagenum_link( 4 );55 $home = home_url( '/' ); 56 $page3 = get_pagenum_link( 3 ); 57 $page4 = get_pagenum_link( 4 ); 53 58 $page50 = get_pagenum_link( 50 ); 54 59 55 $expected = <<<EXPECTED60 $expected = <<<EXPECTED 56 61 <a class='page-numbers' href='$home'>1</a> 57 62 <span aria-current='page' class='page-numbers current'>2</span> … … 62 67 EXPECTED; 63 68 64 $links = paginate_links( array( 'total' => 50, 'prev_next' => false, 'current' => 2 ) ); 69 $links = paginate_links( 70 array( 71 'total' => 50, 72 'prev_next' => false, 73 'current' => 2, 74 ) 75 ); 65 76 $this->assertEquals( $expected, $links ); 66 77 } 67 78 68 79 function test_prev_next_true() { 69 $home = home_url( '/' );70 $page3 = get_pagenum_link( 3 );71 $page4 = get_pagenum_link( 4 );80 $home = home_url( '/' ); 81 $page3 = get_pagenum_link( 3 ); 82 $page4 = get_pagenum_link( 4 ); 72 83 $page50 = get_pagenum_link( 50 ); 73 84 74 $expected = <<<EXPECTED85 $expected = <<<EXPECTED 75 86 <a class="prev page-numbers" href="$home">« Previous</a> 76 87 <a class='page-numbers' href='$home'>1</a> … … 83 94 EXPECTED; 84 95 85 $links = paginate_links( array( 'total' => 50, 'prev_next' => true, 'current' => 2 ) ); 96 $links = paginate_links( 97 array( 98 'total' => 50, 99 'prev_next' => true, 100 'current' => 2, 101 ) 102 ); 86 103 $this->assertEquals( $expected, $links ); 87 104 } … … 97 114 $this->i18n_count = 0; 98 115 add_filter( 'number_format_i18n', array( $this, 'increment_i18n_count' ) ); 99 paginate_links( array( 100 'total' => 100, 101 'current' => 50, 102 'show_all' => false, 103 'prev_next' => true, 104 'end_size' => 1, 105 'mid_size' => 1, 106 ) ); 116 paginate_links( 117 array( 118 'total' => 100, 119 'current' => 50, 120 'show_all' => false, 121 'prev_next' => true, 122 'end_size' => 1, 123 'mid_size' => 1, 124 ) 125 ); 107 126 // The links should be: 108 127 // < Previous 1 ... 49 50 51 ... 100 Next > … … 117 136 118 137 // Current page: 2 119 $links = paginate_links( array( 120 'current' => 2, 121 'total' => 5, 122 'end_size' => 1, 123 'mid_size' => 1, 124 'type' => 'array', 125 ) ); 138 $links = paginate_links( 139 array( 140 'current' => 2, 141 'total' => 5, 142 'end_size' => 1, 143 'mid_size' => 1, 144 'type' => 'array', 145 ) 146 ); 126 147 127 148 $expected_attributes = array( 128 149 array( 129 150 'href' => home_url( '/' ), 130 'class' => 'prev page-numbers' 151 'class' => 'prev page-numbers', 131 152 ), 132 153 array( 133 154 'href' => home_url( '/' ), 134 'class' => 'page-numbers' 135 ) 136 ); 137 138 $document = new DOMDocument();155 'class' => 'page-numbers', 156 ), 157 ); 158 159 $document = new DOMDocument(); 139 160 $document->preserveWhiteSpace = false; 140 161 … … 142 163 foreach ( $expected_attributes as $link_idx => $attributes ) { 143 164 144 $document->loadHTML( $links[ $link_idx] );165 $document->loadHTML( $links[ $link_idx ] ); 145 166 $tag = $document->getElementsByTagName( 'a' )->item( 0 ); 146 167 … … 155 176 156 177 // Current page: 1 157 $links = paginate_links( array( 158 'current' => 1, 159 'total' => 5, 160 'end_size' => 1, 161 'mid_size' => 1, 162 'type' => 'array', 163 ) ); 178 $links = paginate_links( 179 array( 180 'current' => 1, 181 'total' => 5, 182 'end_size' => 1, 183 'mid_size' => 1, 184 'type' => 'array', 185 ) 186 ); 164 187 165 188 $document->loadHTML( $links[0] ); … … 179 202 180 203 function add_query_arg( $url ) { 181 return add_query_arg( array( 182 'foo' => 'bar', 183 's' => 'search+term', 184 ), $url ); 204 return add_query_arg( 205 array( 206 'foo' => 'bar', 207 's' => 'search+term', 208 ), $url 209 ); 185 210 } 186 211 … … 190 215 function test_paginate_links_query_args() { 191 216 add_filter( 'get_pagenum_link', array( $this, 'add_query_arg' ) ); 192 $links = paginate_links( array( 193 'current' => 2, 194 'total' => 5, 195 'end_size' => 1, 196 'mid_size' => 1, 197 'type' => 'array', 198 ) ); 217 $links = paginate_links( 218 array( 219 'current' => 2, 220 'total' => 5, 221 'end_size' => 1, 222 'mid_size' => 1, 223 'type' => 'array', 224 ) 225 ); 199 226 remove_filter( 'get_pagenum_link', array( $this, 'add_query_arg' ) ); 200 227 201 $document = new DOMDocument();228 $document = new DOMDocument(); 202 229 $document->preserveWhiteSpace = false; 203 230 … … 226 253 function test_paginate_links_with_custom_query_args() { 227 254 add_filter( 'get_pagenum_link', array( $this, 'add_query_arg' ) ); 228 $links = paginate_links( array( 229 'current' => 2, 230 'total' => 5, 231 'end_size' => 1, 232 'mid_size' => 1, 233 'type' => 'array', 234 'add_args' => array( 235 'baz' => 'qux', 236 ), 237 ) ); 255 $links = paginate_links( 256 array( 257 'current' => 2, 258 'total' => 5, 259 'end_size' => 1, 260 'mid_size' => 1, 261 'type' => 'array', 262 'add_args' => array( 263 'baz' => 'qux', 264 ), 265 ) 266 ); 238 267 remove_filter( 'get_pagenum_link', array( $this, 'add_query_arg' ) ); 239 268 240 $document = new DOMDocument();269 $document = new DOMDocument(); 241 270 $document->preserveWhiteSpace = false; 242 271 … … 264 293 public function test_paginate_links_should_allow_non_default_format_without_add_args() { 265 294 // Fake the query params. 266 $request_uri = $_SERVER['REQUEST_URI'];295 $request_uri = $_SERVER['REQUEST_URI']; 267 296 $_SERVER['REQUEST_URI'] = add_query_arg( 'foo', 3, home_url() ); 268 297 269 $links = paginate_links( array( 270 'base' => add_query_arg( 'foo', '%#%' ), 271 'format' => '', 272 'total' => 5, 273 'current' => 3, 274 'type' => 'array', 275 ) ); 298 $links = paginate_links( 299 array( 300 'base' => add_query_arg( 'foo', '%#%' ), 301 'format' => '', 302 'total' => 5, 303 'current' => 3, 304 'type' => 'array', 305 ) 306 ); 276 307 277 308 $this->assertContains( '?foo=1', $links[1] ); … … 288 319 public function test_paginate_links_should_allow_add_args_to_be_bool_false() { 289 320 // Fake the query params. 290 $request_uri = $_SERVER['REQUEST_URI'];321 $request_uri = $_SERVER['REQUEST_URI']; 291 322 $_SERVER['REQUEST_URI'] = add_query_arg( 'foo', 3, home_url() ); 292 323 293 $links = paginate_links( array( 294 'add_args' => false, 295 'base' => add_query_arg( 'foo', '%#%' ), 296 'format' => '', 297 'total' => 5, 298 'current' => 3, 299 'type' => 'array', 300 ) ); 324 $links = paginate_links( 325 array( 326 'add_args' => false, 327 'base' => add_query_arg( 'foo', '%#%' ), 328 'format' => '', 329 'total' => 5, 330 'current' => 3, 331 'type' => 'array', 332 ) 333 ); 301 334 302 335 $this->assertContains( "<span aria-current='page' class='page-numbers current'>3</span>", $links ); … … 308 341 public function test_custom_base_query_arg_should_be_stripped_from_current_url_before_generating_pag_links() { 309 342 // Fake the current URL: example.com?foo 310 $request_uri = $_SERVER['REQUEST_URI'];343 $request_uri = $_SERVER['REQUEST_URI']; 311 344 $_SERVER['REQUEST_URI'] = add_query_arg( 'foo', '', $request_uri ); 312 345 313 $links = paginate_links( array( 314 'base' => add_query_arg( 'foo', '%_%', home_url() ), 315 'format' => '%#%', 316 'total' => 5, 317 'current' => 1, 318 'type' => 'array', 319 ) ); 346 $links = paginate_links( 347 array( 348 'base' => add_query_arg( 'foo', '%_%', home_url() ), 349 'format' => '%#%', 350 'total' => 5, 351 'current' => 1, 352 'type' => 'array', 353 ) 354 ); 320 355 321 356 $page_2_url = home_url() . '?foo=2';
Note: See TracChangeset
for help on using the changeset viewer.