Changeset 51667
- Timestamp:
- 08/26/2021 04:29:37 PM (3 years ago)
- Location:
- trunk/tests/phpunit/tests/functions
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/functions/wpListSort.php
r51666 r51667 2 2 3 3 /** 4 * Test wp_list_sort(). 5 * 4 6 * @group functions.php 7 * @covers ::wp_list_sort 5 8 */ 6 class Tests_Functions_wpListUtil extends WP_UnitTestCase { 7 8 public function data_test_wp_list_sort() { 9 return array( 10 'single orderby ascending' => array( 11 array( 12 array( 13 'foo' => 'bar', 14 'bar' => 'baz', 15 'key' => 'foo', 16 ), 17 array( 18 'foo' => 'foo', 19 'lorem' => 'ipsum', 20 'key' => 'bar', 21 ), 22 array( 23 'foo' => 'baz', 24 'key' => 'value', 25 ), 26 ), 27 'foo', 28 'ASC', 29 array( 30 array( 31 'foo' => 'bar', 32 'bar' => 'baz', 33 'key' => 'foo', 34 ), 35 array( 36 'foo' => 'baz', 37 'key' => 'value', 38 ), 39 array( 40 'foo' => 'foo', 41 'lorem' => 'ipsum', 42 'key' => 'bar', 43 ), 44 ), 45 ), 46 'single orderby descending' => array( 47 array( 48 array( 49 'foo' => 'bar', 50 'bar' => 'baz', 51 'key' => 'foo', 52 ), 53 array( 54 'foo' => 'foo', 55 'lorem' => 'ipsum', 56 'key' => 'bar', 57 ), 58 array( 59 'foo' => 'baz', 60 'key' => 'value', 61 ), 62 ), 63 'foo', 64 'DESC', 65 array( 66 array( 67 'foo' => 'foo', 68 'lorem' => 'ipsum', 69 'key' => 'bar', 70 ), 71 array( 72 'foo' => 'baz', 73 'key' => 'value', 74 ), 75 array( 76 'foo' => 'bar', 77 'bar' => 'baz', 78 'key' => 'foo', 79 ), 80 ), 81 ), 82 'single orderby array ascending' => array( 83 array( 84 array( 85 'foo' => 'bar', 86 'bar' => 'baz', 87 'key' => 'foo', 88 ), 89 array( 90 'foo' => 'foo', 91 'lorem' => 'ipsum', 92 'key' => 'bar', 93 ), 94 array( 95 'foo' => 'baz', 96 'key' => 'value', 97 ), 98 ), 99 array( 'foo' => 'ASC' ), 100 'IGNORED', 101 array( 102 array( 103 'foo' => 'bar', 104 'bar' => 'baz', 105 'key' => 'foo', 106 ), 107 array( 108 'foo' => 'baz', 109 'key' => 'value', 110 ), 111 array( 112 'foo' => 'foo', 113 'lorem' => 'ipsum', 114 'key' => 'bar', 115 ), 116 ), 117 ), 118 'single orderby array descending' => array( 119 array( 120 array( 121 'foo' => 'bar', 122 'bar' => 'baz', 123 'key' => 'foo', 124 ), 125 array( 126 'foo' => 'foo', 127 'lorem' => 'ipsum', 128 'key' => 'bar', 129 ), 130 array( 131 'foo' => 'baz', 132 'key' => 'value', 133 ), 134 ), 135 array( 'foo' => 'DESC' ), 136 'IGNORED', 137 array( 138 array( 139 'foo' => 'foo', 140 'lorem' => 'ipsum', 141 'key' => 'bar', 142 ), 143 array( 144 'foo' => 'baz', 145 'key' => 'value', 146 ), 147 array( 148 'foo' => 'bar', 149 'bar' => 'baz', 150 'key' => 'foo', 151 ), 152 ), 153 ), 154 'multiple orderby ascending' => array( 155 array( 156 array( 157 'foo' => 'bar', 158 'bar' => 'baz', 159 'key' => 'foo', 160 ), 161 array( 162 'foo' => 'foo', 163 'lorem' => 'ipsum', 164 'key' => 'bar', 165 ), 166 array( 167 'foo' => 'foo', 168 'key' => 'key', 169 ), 170 array( 171 'foo' => 'baz', 172 'key' => 'key', 173 ), 174 array( 175 'foo' => 'bar', 176 'key' => 'value', 177 ), 178 ), 179 array( 180 'key' => 'ASC', 181 'foo' => 'ASC', 182 ), 183 'IGNORED', 184 array( 185 array( 186 'foo' => 'foo', 187 'lorem' => 'ipsum', 188 'key' => 'bar', 189 ), 190 array( 191 'foo' => 'bar', 192 'bar' => 'baz', 193 'key' => 'foo', 194 ), 195 array( 196 'foo' => 'baz', 197 'key' => 'key', 198 ), 199 array( 200 'foo' => 'foo', 201 'key' => 'key', 202 ), 203 array( 204 'foo' => 'bar', 205 'key' => 'value', 206 ), 207 ), 208 ), 209 'multiple orderby descending' => array( 210 array( 211 array( 212 'foo' => 'bar', 213 'bar' => 'baz', 214 'key' => 'foo', 215 ), 216 array( 217 'foo' => 'foo', 218 'lorem' => 'ipsum', 219 'key' => 'bar', 220 ), 221 array( 222 'foo' => 'foo', 223 'key' => 'key', 224 ), 225 array( 226 'foo' => 'baz', 227 'key' => 'key', 228 ), 229 array( 230 'foo' => 'bar', 231 'key' => 'value', 232 ), 233 ), 234 array( 235 'key' => 'DESC', 236 'foo' => 'DESC', 237 ), 238 'IGNORED', 239 array( 240 array( 241 'foo' => 'bar', 242 'key' => 'value', 243 ), 244 array( 245 'foo' => 'foo', 246 'key' => 'key', 247 ), 248 array( 249 'foo' => 'baz', 250 'key' => 'key', 251 ), 252 array( 253 'foo' => 'bar', 254 'bar' => 'baz', 255 'key' => 'foo', 256 ), 257 array( 258 'foo' => 'foo', 259 'lorem' => 'ipsum', 260 'key' => 'bar', 261 ), 262 ), 263 ), 264 'multiple orderby mixed' => array( 265 array( 266 array( 267 'foo' => 'bar', 268 'bar' => 'baz', 269 'key' => 'foo', 270 ), 271 array( 272 'foo' => 'foo', 273 'lorem' => 'ipsum', 274 'key' => 'bar', 275 ), 276 array( 277 'foo' => 'foo', 278 'key' => 'key', 279 ), 280 array( 281 'foo' => 'baz', 282 'key' => 'key', 283 ), 284 array( 285 'foo' => 'bar', 286 'key' => 'value', 287 ), 288 ), 289 array( 290 'key' => 'DESC', 291 'foo' => 'ASC', 292 ), 293 'IGNORED', 294 array( 295 array( 296 'foo' => 'bar', 297 'key' => 'value', 298 ), 299 array( 300 'foo' => 'baz', 301 'key' => 'key', 302 ), 303 array( 304 'foo' => 'foo', 305 'key' => 'key', 306 ), 307 array( 308 'foo' => 'bar', 309 'bar' => 'baz', 310 'key' => 'foo', 311 ), 312 array( 313 'foo' => 'foo', 314 'lorem' => 'ipsum', 315 'key' => 'bar', 316 ), 317 ), 318 ), 319 ); 320 } 9 class Tests_Functions_wpListSort extends WP_UnitTestCase { 321 10 322 11 /** 323 12 * @dataProvider data_test_wp_list_sort 324 *325 * @covers ::wp_list_sort326 13 * 327 14 * @param string|array $orderby Either the field name to order by or an array … … 333 20 } 334 21 335 public function data_test_wp_list_sort _preserve_keys() {22 public function data_test_wp_list_sort() { 336 23 return array( 337 24 'single orderby ascending' => array( 338 25 array( 339 'foobar' =>array(340 'foo' => 'bar', 341 'bar' => 'baz', 342 'key' => 'foo', 343 ), 344 'foofoo' =>array(345 'foo' => 'foo', 346 'lorem' => 'ipsum', 347 'key' => 'bar', 348 ), 349 'foobaz' =>array(26 array( 27 'foo' => 'bar', 28 'bar' => 'baz', 29 'key' => 'foo', 30 ), 31 array( 32 'foo' => 'foo', 33 'lorem' => 'ipsum', 34 'key' => 'bar', 35 ), 36 array( 350 37 'foo' => 'baz', 351 38 'key' => 'value', … … 355 42 'ASC', 356 43 array( 357 'foobar' =>array(358 'foo' => 'bar', 359 'bar' => 'baz', 360 'key' => 'foo', 361 ), 362 'foobaz' =>array(363 'foo' => 'baz', 364 'key' => 'value', 365 ), 366 'foofoo' =>array(44 array( 45 'foo' => 'bar', 46 'bar' => 'baz', 47 'key' => 'foo', 48 ), 49 array( 50 'foo' => 'baz', 51 'key' => 'value', 52 ), 53 array( 367 54 'foo' => 'foo', 368 55 'lorem' => 'ipsum', … … 373 60 'single orderby descending' => array( 374 61 array( 375 'foobar' =>array(376 'foo' => 'bar', 377 'bar' => 'baz', 378 'key' => 'foo', 379 ), 380 'foofoo' =>array(381 'foo' => 'foo', 382 'lorem' => 'ipsum', 383 'key' => 'bar', 384 ), 385 'foobaz' =>array(62 array( 63 'foo' => 'bar', 64 'bar' => 'baz', 65 'key' => 'foo', 66 ), 67 array( 68 'foo' => 'foo', 69 'lorem' => 'ipsum', 70 'key' => 'bar', 71 ), 72 array( 386 73 'foo' => 'baz', 387 74 'key' => 'value', … … 391 78 'DESC', 392 79 array( 393 'foofoo' =>array(394 'foo' => 'foo', 395 'lorem' => 'ipsum', 396 'key' => 'bar', 397 ), 398 'foobaz' =>array(399 'foo' => 'baz', 400 'key' => 'value', 401 ), 402 'foobar' =>array(80 array( 81 'foo' => 'foo', 82 'lorem' => 'ipsum', 83 'key' => 'bar', 84 ), 85 array( 86 'foo' => 'baz', 87 'key' => 'value', 88 ), 89 array( 403 90 'foo' => 'bar', 404 91 'bar' => 'baz', … … 409 96 'single orderby array ascending' => array( 410 97 array( 411 'foobar' =>array(412 'foo' => 'bar', 413 'bar' => 'baz', 414 'key' => 'foo', 415 ), 416 'foofoo' =>array(417 'foo' => 'foo', 418 'lorem' => 'ipsum', 419 'key' => 'bar', 420 ), 421 'foobaz' =>array(98 array( 99 'foo' => 'bar', 100 'bar' => 'baz', 101 'key' => 'foo', 102 ), 103 array( 104 'foo' => 'foo', 105 'lorem' => 'ipsum', 106 'key' => 'bar', 107 ), 108 array( 422 109 'foo' => 'baz', 423 110 'key' => 'value', … … 427 114 'IGNORED', 428 115 array( 429 'foobar' =>array(430 'foo' => 'bar', 431 'bar' => 'baz', 432 'key' => 'foo', 433 ), 434 'foobaz' =>array(435 'foo' => 'baz', 436 'key' => 'value', 437 ), 438 'foofoo' =>array(116 array( 117 'foo' => 'bar', 118 'bar' => 'baz', 119 'key' => 'foo', 120 ), 121 array( 122 'foo' => 'baz', 123 'key' => 'value', 124 ), 125 array( 439 126 'foo' => 'foo', 440 127 'lorem' => 'ipsum', … … 445 132 'single orderby array descending' => array( 446 133 array( 447 'foobar' =>array(448 'foo' => 'bar', 449 'bar' => 'baz', 450 'key' => 'foo', 451 ), 452 'foofoo' =>array(453 'foo' => 'foo', 454 'lorem' => 'ipsum', 455 'key' => 'bar', 456 ), 457 'foobaz' =>array(134 array( 135 'foo' => 'bar', 136 'bar' => 'baz', 137 'key' => 'foo', 138 ), 139 array( 140 'foo' => 'foo', 141 'lorem' => 'ipsum', 142 'key' => 'bar', 143 ), 144 array( 458 145 'foo' => 'baz', 459 146 'key' => 'value', … … 463 150 'IGNORED', 464 151 array( 465 'foofoo' =>array(466 'foo' => 'foo', 467 'lorem' => 'ipsum', 468 'key' => 'bar', 469 ), 470 'foobaz' =>array(471 'foo' => 'baz', 472 'key' => 'value', 473 ), 474 'foobar' =>array(152 array( 153 'foo' => 'foo', 154 'lorem' => 'ipsum', 155 'key' => 'bar', 156 ), 157 array( 158 'foo' => 'baz', 159 'key' => 'value', 160 ), 161 array( 475 162 'foo' => 'bar', 476 163 'bar' => 'baz', … … 481 168 'multiple orderby ascending' => array( 482 169 array( 483 'foobarfoo' =>array(484 'foo' => 'bar', 485 'bar' => 'baz', 486 'key' => 'foo', 487 ), 488 'foofoobar' =>array(489 'foo' => 'foo', 490 'lorem' => 'ipsum', 491 'key' => 'bar', 492 ), 493 'foofookey' =>array(494 'foo' => 'foo', 495 'key' => 'key', 496 ), 497 'foobazkey' =>array(498 'foo' => 'baz', 499 'key' => 'key', 500 ), 501 'foobarvalue' =>array(170 array( 171 'foo' => 'bar', 172 'bar' => 'baz', 173 'key' => 'foo', 174 ), 175 array( 176 'foo' => 'foo', 177 'lorem' => 'ipsum', 178 'key' => 'bar', 179 ), 180 array( 181 'foo' => 'foo', 182 'key' => 'key', 183 ), 184 array( 185 'foo' => 'baz', 186 'key' => 'key', 187 ), 188 array( 502 189 'foo' => 'bar', 503 190 'key' => 'value', … … 510 197 'IGNORED', 511 198 array( 512 'foofoobar' =>array(513 'foo' => 'foo', 514 'lorem' => 'ipsum', 515 'key' => 'bar', 516 ), 517 'foobarfoo' =>array(518 'foo' => 'bar', 519 'bar' => 'baz', 520 'key' => 'foo', 521 ), 522 'foobazkey' =>array(523 'foo' => 'baz', 524 'key' => 'key', 525 ), 526 'foofookey' =>array(527 'foo' => 'foo', 528 'key' => 'key', 529 ), 530 'foobarvalue' =>array(199 array( 200 'foo' => 'foo', 201 'lorem' => 'ipsum', 202 'key' => 'bar', 203 ), 204 array( 205 'foo' => 'bar', 206 'bar' => 'baz', 207 'key' => 'foo', 208 ), 209 array( 210 'foo' => 'baz', 211 'key' => 'key', 212 ), 213 array( 214 'foo' => 'foo', 215 'key' => 'key', 216 ), 217 array( 531 218 'foo' => 'bar', 532 219 'key' => 'value', … … 536 223 'multiple orderby descending' => array( 537 224 array( 538 'foobarfoo' =>array(539 'foo' => 'bar', 540 'bar' => 'baz', 541 'key' => 'foo', 542 ), 543 'foofoobar' =>array(544 'foo' => 'foo', 545 'lorem' => 'ipsum', 546 'key' => 'bar', 547 ), 548 'foofookey' =>array(549 'foo' => 'foo', 550 'key' => 'key', 551 ), 552 'foobazkey' =>array(553 'foo' => 'baz', 554 'key' => 'key', 555 ), 556 'foobarvalue' =>array(225 array( 226 'foo' => 'bar', 227 'bar' => 'baz', 228 'key' => 'foo', 229 ), 230 array( 231 'foo' => 'foo', 232 'lorem' => 'ipsum', 233 'key' => 'bar', 234 ), 235 array( 236 'foo' => 'foo', 237 'key' => 'key', 238 ), 239 array( 240 'foo' => 'baz', 241 'key' => 'key', 242 ), 243 array( 557 244 'foo' => 'bar', 558 245 'key' => 'value', … … 565 252 'IGNORED', 566 253 array( 567 'foobarvalue' =>array(568 'foo' => 'bar', 569 'key' => 'value', 570 ), 571 'foofookey' =>array(572 'foo' => 'foo', 573 'key' => 'key', 574 ), 575 'foobazkey' =>array(576 'foo' => 'baz', 577 'key' => 'key', 578 ), 579 'foobarfoo' =>array(580 'foo' => 'bar', 581 'bar' => 'baz', 582 'key' => 'foo', 583 ), 584 'foofoobar' =>array(254 array( 255 'foo' => 'bar', 256 'key' => 'value', 257 ), 258 array( 259 'foo' => 'foo', 260 'key' => 'key', 261 ), 262 array( 263 'foo' => 'baz', 264 'key' => 'key', 265 ), 266 array( 267 'foo' => 'bar', 268 'bar' => 'baz', 269 'key' => 'foo', 270 ), 271 array( 585 272 'foo' => 'foo', 586 273 'lorem' => 'ipsum', … … 591 278 'multiple orderby mixed' => array( 592 279 array( 593 'foobarfoo' =>array(594 'foo' => 'bar', 595 'bar' => 'baz', 596 'key' => 'foo', 597 ), 598 'foofoobar' =>array(599 'foo' => 'foo', 600 'lorem' => 'ipsum', 601 'key' => 'bar', 602 ), 603 'foofookey' =>array(604 'foo' => 'foo', 605 'key' => 'key', 606 ), 607 'foobazkey' =>array(608 'foo' => 'baz', 609 'key' => 'key', 610 ), 611 'foobarvalue' =>array(280 array( 281 'foo' => 'bar', 282 'bar' => 'baz', 283 'key' => 'foo', 284 ), 285 array( 286 'foo' => 'foo', 287 'lorem' => 'ipsum', 288 'key' => 'bar', 289 ), 290 array( 291 'foo' => 'foo', 292 'key' => 'key', 293 ), 294 array( 295 'foo' => 'baz', 296 'key' => 'key', 297 ), 298 array( 612 299 'foo' => 'bar', 613 300 'key' => 'value', … … 620 307 'IGNORED', 621 308 array( 622 'foobarvalue' =>array(623 'foo' => 'bar', 624 'key' => 'value', 625 ), 626 'foobazkey' =>array(627 'foo' => 'baz', 628 'key' => 'key', 629 ), 630 'foofookey' =>array(631 'foo' => 'foo', 632 'key' => 'key', 633 ), 634 'foobarfoo' =>array(635 'foo' => 'bar', 636 'bar' => 'baz', 637 'key' => 'foo', 638 ), 639 'foofoobar' =>array(309 array( 310 'foo' => 'bar', 311 'key' => 'value', 312 ), 313 array( 314 'foo' => 'baz', 315 'key' => 'key', 316 ), 317 array( 318 'foo' => 'foo', 319 'key' => 'key', 320 ), 321 array( 322 'foo' => 'bar', 323 'bar' => 'baz', 324 'key' => 'foo', 325 ), 326 array( 640 327 'foo' => 'foo', 641 328 'lorem' => 'ipsum', … … 649 336 /** 650 337 * @dataProvider data_test_wp_list_sort_preserve_keys 651 *652 * @covers ::wp_list_sort653 338 * 654 339 * @param string|array $orderby Either the field name to order by or an array … … 660 345 } 661 346 662 /** 663 * @covers WP_List_Util::get_input 664 */ 665 public function test_wp_list_util_get_input() { 666 $input = array( 'foo', 'bar' ); 667 $util = new WP_List_Util( $input ); 668 669 $this->assertSameSets( $input, $util->get_input() ); 670 } 671 672 /** 673 * @covers WP_List_Util::get_output 674 */ 675 public function test_wp_list_util_get_output_immediately() { 676 $input = array( 'foo', 'bar' ); 677 $util = new WP_List_Util( $input ); 678 679 $this->assertSameSets( $input, $util->get_output() ); 680 } 681 682 /** 683 * @covers WP_List_Util::get_output 684 */ 685 public function test_wp_list_util_get_output() { 686 $expected = array( 687 (object) array( 688 'foo' => 'bar', 689 'bar' => 'baz', 347 public function data_test_wp_list_sort_preserve_keys() { 348 return array( 349 'single orderby ascending' => array( 350 array( 351 'foobar' => array( 352 'foo' => 'bar', 353 'bar' => 'baz', 354 'key' => 'foo', 355 ), 356 'foofoo' => array( 357 'foo' => 'foo', 358 'lorem' => 'ipsum', 359 'key' => 'bar', 360 ), 361 'foobaz' => array( 362 'foo' => 'baz', 363 'key' => 'value', 364 ), 365 ), 366 'foo', 367 'ASC', 368 array( 369 'foobar' => array( 370 'foo' => 'bar', 371 'bar' => 'baz', 372 'key' => 'foo', 373 ), 374 'foobaz' => array( 375 'foo' => 'baz', 376 'key' => 'value', 377 ), 378 'foofoo' => array( 379 'foo' => 'foo', 380 'lorem' => 'ipsum', 381 'key' => 'bar', 382 ), 383 ), 384 ), 385 'single orderby descending' => array( 386 array( 387 'foobar' => array( 388 'foo' => 'bar', 389 'bar' => 'baz', 390 'key' => 'foo', 391 ), 392 'foofoo' => array( 393 'foo' => 'foo', 394 'lorem' => 'ipsum', 395 'key' => 'bar', 396 ), 397 'foobaz' => array( 398 'foo' => 'baz', 399 'key' => 'value', 400 ), 401 ), 402 'foo', 403 'DESC', 404 array( 405 'foofoo' => array( 406 'foo' => 'foo', 407 'lorem' => 'ipsum', 408 'key' => 'bar', 409 ), 410 'foobaz' => array( 411 'foo' => 'baz', 412 'key' => 'value', 413 ), 414 'foobar' => array( 415 'foo' => 'bar', 416 'bar' => 'baz', 417 'key' => 'foo', 418 ), 419 ), 420 ), 421 'single orderby array ascending' => array( 422 array( 423 'foobar' => array( 424 'foo' => 'bar', 425 'bar' => 'baz', 426 'key' => 'foo', 427 ), 428 'foofoo' => array( 429 'foo' => 'foo', 430 'lorem' => 'ipsum', 431 'key' => 'bar', 432 ), 433 'foobaz' => array( 434 'foo' => 'baz', 435 'key' => 'value', 436 ), 437 ), 438 array( 'foo' => 'ASC' ), 439 'IGNORED', 440 array( 441 'foobar' => array( 442 'foo' => 'bar', 443 'bar' => 'baz', 444 'key' => 'foo', 445 ), 446 'foobaz' => array( 447 'foo' => 'baz', 448 'key' => 'value', 449 ), 450 'foofoo' => array( 451 'foo' => 'foo', 452 'lorem' => 'ipsum', 453 'key' => 'bar', 454 ), 455 ), 456 ), 457 'single orderby array descending' => array( 458 array( 459 'foobar' => array( 460 'foo' => 'bar', 461 'bar' => 'baz', 462 'key' => 'foo', 463 ), 464 'foofoo' => array( 465 'foo' => 'foo', 466 'lorem' => 'ipsum', 467 'key' => 'bar', 468 ), 469 'foobaz' => array( 470 'foo' => 'baz', 471 'key' => 'value', 472 ), 473 ), 474 array( 'foo' => 'DESC' ), 475 'IGNORED', 476 array( 477 'foofoo' => array( 478 'foo' => 'foo', 479 'lorem' => 'ipsum', 480 'key' => 'bar', 481 ), 482 'foobaz' => array( 483 'foo' => 'baz', 484 'key' => 'value', 485 ), 486 'foobar' => array( 487 'foo' => 'bar', 488 'bar' => 'baz', 489 'key' => 'foo', 490 ), 491 ), 492 ), 493 'multiple orderby ascending' => array( 494 array( 495 'foobarfoo' => array( 496 'foo' => 'bar', 497 'bar' => 'baz', 498 'key' => 'foo', 499 ), 500 'foofoobar' => array( 501 'foo' => 'foo', 502 'lorem' => 'ipsum', 503 'key' => 'bar', 504 ), 505 'foofookey' => array( 506 'foo' => 'foo', 507 'key' => 'key', 508 ), 509 'foobazkey' => array( 510 'foo' => 'baz', 511 'key' => 'key', 512 ), 513 'foobarvalue' => array( 514 'foo' => 'bar', 515 'key' => 'value', 516 ), 517 ), 518 array( 519 'key' => 'ASC', 520 'foo' => 'ASC', 521 ), 522 'IGNORED', 523 array( 524 'foofoobar' => array( 525 'foo' => 'foo', 526 'lorem' => 'ipsum', 527 'key' => 'bar', 528 ), 529 'foobarfoo' => array( 530 'foo' => 'bar', 531 'bar' => 'baz', 532 'key' => 'foo', 533 ), 534 'foobazkey' => array( 535 'foo' => 'baz', 536 'key' => 'key', 537 ), 538 'foofookey' => array( 539 'foo' => 'foo', 540 'key' => 'key', 541 ), 542 'foobarvalue' => array( 543 'foo' => 'bar', 544 'key' => 'value', 545 ), 546 ), 547 ), 548 'multiple orderby descending' => array( 549 array( 550 'foobarfoo' => array( 551 'foo' => 'bar', 552 'bar' => 'baz', 553 'key' => 'foo', 554 ), 555 'foofoobar' => array( 556 'foo' => 'foo', 557 'lorem' => 'ipsum', 558 'key' => 'bar', 559 ), 560 'foofookey' => array( 561 'foo' => 'foo', 562 'key' => 'key', 563 ), 564 'foobazkey' => array( 565 'foo' => 'baz', 566 'key' => 'key', 567 ), 568 'foobarvalue' => array( 569 'foo' => 'bar', 570 'key' => 'value', 571 ), 572 ), 573 array( 574 'key' => 'DESC', 575 'foo' => 'DESC', 576 ), 577 'IGNORED', 578 array( 579 'foobarvalue' => array( 580 'foo' => 'bar', 581 'key' => 'value', 582 ), 583 'foofookey' => array( 584 'foo' => 'foo', 585 'key' => 'key', 586 ), 587 'foobazkey' => array( 588 'foo' => 'baz', 589 'key' => 'key', 590 ), 591 'foobarfoo' => array( 592 'foo' => 'bar', 593 'bar' => 'baz', 594 'key' => 'foo', 595 ), 596 'foofoobar' => array( 597 'foo' => 'foo', 598 'lorem' => 'ipsum', 599 'key' => 'bar', 600 ), 601 ), 602 ), 603 'multiple orderby mixed' => array( 604 array( 605 'foobarfoo' => array( 606 'foo' => 'bar', 607 'bar' => 'baz', 608 'key' => 'foo', 609 ), 610 'foofoobar' => array( 611 'foo' => 'foo', 612 'lorem' => 'ipsum', 613 'key' => 'bar', 614 ), 615 'foofookey' => array( 616 'foo' => 'foo', 617 'key' => 'key', 618 ), 619 'foobazkey' => array( 620 'foo' => 'baz', 621 'key' => 'key', 622 ), 623 'foobarvalue' => array( 624 'foo' => 'bar', 625 'key' => 'value', 626 ), 627 ), 628 array( 629 'key' => 'DESC', 630 'foo' => 'ASC', 631 ), 632 'IGNORED', 633 array( 634 'foobarvalue' => array( 635 'foo' => 'bar', 636 'key' => 'value', 637 ), 638 'foobazkey' => array( 639 'foo' => 'baz', 640 'key' => 'key', 641 ), 642 'foofookey' => array( 643 'foo' => 'foo', 644 'key' => 'key', 645 ), 646 'foobarfoo' => array( 647 'foo' => 'bar', 648 'bar' => 'baz', 649 'key' => 'foo', 650 ), 651 'foofoobar' => array( 652 'foo' => 'foo', 653 'lorem' => 'ipsum', 654 'key' => 'bar', 655 ), 656 ), 690 657 ), 691 658 ); 692 693 $util = new WP_List_Util(694 array(695 (object) array(696 'foo' => 'bar',697 'bar' => 'baz',698 ),699 (object) array( 'bar' => 'baz' ),700 )701 );702 $actual = $util->filter( array( 'foo' => 'bar' ) );703 704 $this->assertEqualSets( $expected, $actual );705 $this->assertEqualSets( $expected, $util->get_output() );706 659 } 707 660 } -
trunk/tests/phpunit/tests/functions/wpListUtil.php
r51666 r51667 2 2 3 3 /** 4 * Test WP_List_Util class. 5 * 4 6 * @group functions.php 5 7 */ 6 8 class Tests_Functions_wpListUtil extends WP_UnitTestCase { 7 8 public function data_test_wp_list_sort() {9 return array(10 'single orderby ascending' => array(11 array(12 array(13 'foo' => 'bar',14 'bar' => 'baz',15 'key' => 'foo',16 ),17 array(18 'foo' => 'foo',19 'lorem' => 'ipsum',20 'key' => 'bar',21 ),22 array(23 'foo' => 'baz',24 'key' => 'value',25 ),26 ),27 'foo',28 'ASC',29 array(30 array(31 'foo' => 'bar',32 'bar' => 'baz',33 'key' => 'foo',34 ),35 array(36 'foo' => 'baz',37 'key' => 'value',38 ),39 array(40 'foo' => 'foo',41 'lorem' => 'ipsum',42 'key' => 'bar',43 ),44 ),45 ),46 'single orderby descending' => array(47 array(48 array(49 'foo' => 'bar',50 'bar' => 'baz',51 'key' => 'foo',52 ),53 array(54 'foo' => 'foo',55 'lorem' => 'ipsum',56 'key' => 'bar',57 ),58 array(59 'foo' => 'baz',60 'key' => 'value',61 ),62 ),63 'foo',64 'DESC',65 array(66 array(67 'foo' => 'foo',68 'lorem' => 'ipsum',69 'key' => 'bar',70 ),71 array(72 'foo' => 'baz',73 'key' => 'value',74 ),75 array(76 'foo' => 'bar',77 'bar' => 'baz',78 'key' => 'foo',79 ),80 ),81 ),82 'single orderby array ascending' => array(83 array(84 array(85 'foo' => 'bar',86 'bar' => 'baz',87 'key' => 'foo',88 ),89 array(90 'foo' => 'foo',91 'lorem' => 'ipsum',92 'key' => 'bar',93 ),94 array(95 'foo' => 'baz',96 'key' => 'value',97 ),98 ),99 array( 'foo' => 'ASC' ),100 'IGNORED',101 array(102 array(103 'foo' => 'bar',104 'bar' => 'baz',105 'key' => 'foo',106 ),107 array(108 'foo' => 'baz',109 'key' => 'value',110 ),111 array(112 'foo' => 'foo',113 'lorem' => 'ipsum',114 'key' => 'bar',115 ),116 ),117 ),118 'single orderby array descending' => array(119 array(120 array(121 'foo' => 'bar',122 'bar' => 'baz',123 'key' => 'foo',124 ),125 array(126 'foo' => 'foo',127 'lorem' => 'ipsum',128 'key' => 'bar',129 ),130 array(131 'foo' => 'baz',132 'key' => 'value',133 ),134 ),135 array( 'foo' => 'DESC' ),136 'IGNORED',137 array(138 array(139 'foo' => 'foo',140 'lorem' => 'ipsum',141 'key' => 'bar',142 ),143 array(144 'foo' => 'baz',145 'key' => 'value',146 ),147 array(148 'foo' => 'bar',149 'bar' => 'baz',150 'key' => 'foo',151 ),152 ),153 ),154 'multiple orderby ascending' => array(155 array(156 array(157 'foo' => 'bar',158 'bar' => 'baz',159 'key' => 'foo',160 ),161 array(162 'foo' => 'foo',163 'lorem' => 'ipsum',164 'key' => 'bar',165 ),166 array(167 'foo' => 'foo',168 'key' => 'key',169 ),170 array(171 'foo' => 'baz',172 'key' => 'key',173 ),174 array(175 'foo' => 'bar',176 'key' => 'value',177 ),178 ),179 array(180 'key' => 'ASC',181 'foo' => 'ASC',182 ),183 'IGNORED',184 array(185 array(186 'foo' => 'foo',187 'lorem' => 'ipsum',188 'key' => 'bar',189 ),190 array(191 'foo' => 'bar',192 'bar' => 'baz',193 'key' => 'foo',194 ),195 array(196 'foo' => 'baz',197 'key' => 'key',198 ),199 array(200 'foo' => 'foo',201 'key' => 'key',202 ),203 array(204 'foo' => 'bar',205 'key' => 'value',206 ),207 ),208 ),209 'multiple orderby descending' => array(210 array(211 array(212 'foo' => 'bar',213 'bar' => 'baz',214 'key' => 'foo',215 ),216 array(217 'foo' => 'foo',218 'lorem' => 'ipsum',219 'key' => 'bar',220 ),221 array(222 'foo' => 'foo',223 'key' => 'key',224 ),225 array(226 'foo' => 'baz',227 'key' => 'key',228 ),229 array(230 'foo' => 'bar',231 'key' => 'value',232 ),233 ),234 array(235 'key' => 'DESC',236 'foo' => 'DESC',237 ),238 'IGNORED',239 array(240 array(241 'foo' => 'bar',242 'key' => 'value',243 ),244 array(245 'foo' => 'foo',246 'key' => 'key',247 ),248 array(249 'foo' => 'baz',250 'key' => 'key',251 ),252 array(253 'foo' => 'bar',254 'bar' => 'baz',255 'key' => 'foo',256 ),257 array(258 'foo' => 'foo',259 'lorem' => 'ipsum',260 'key' => 'bar',261 ),262 ),263 ),264 'multiple orderby mixed' => array(265 array(266 array(267 'foo' => 'bar',268 'bar' => 'baz',269 'key' => 'foo',270 ),271 array(272 'foo' => 'foo',273 'lorem' => 'ipsum',274 'key' => 'bar',275 ),276 array(277 'foo' => 'foo',278 'key' => 'key',279 ),280 array(281 'foo' => 'baz',282 'key' => 'key',283 ),284 array(285 'foo' => 'bar',286 'key' => 'value',287 ),288 ),289 array(290 'key' => 'DESC',291 'foo' => 'ASC',292 ),293 'IGNORED',294 array(295 array(296 'foo' => 'bar',297 'key' => 'value',298 ),299 array(300 'foo' => 'baz',301 'key' => 'key',302 ),303 array(304 'foo' => 'foo',305 'key' => 'key',306 ),307 array(308 'foo' => 'bar',309 'bar' => 'baz',310 'key' => 'foo',311 ),312 array(313 'foo' => 'foo',314 'lorem' => 'ipsum',315 'key' => 'bar',316 ),317 ),318 ),319 );320 }321 322 /**323 * @dataProvider data_test_wp_list_sort324 *325 * @covers ::wp_list_sort326 *327 * @param string|array $orderby Either the field name to order by or an array328 * of multiple orderby fields as $orderby => $order.329 * @param string $order Either 'ASC' or 'DESC'.330 */331 public function test_wp_list_sort( $list, $orderby, $order, $expected ) {332 $this->assertSame( $expected, wp_list_sort( $list, $orderby, $order ) );333 }334 335 public function data_test_wp_list_sort_preserve_keys() {336 return array(337 'single orderby ascending' => array(338 array(339 'foobar' => array(340 'foo' => 'bar',341 'bar' => 'baz',342 'key' => 'foo',343 ),344 'foofoo' => array(345 'foo' => 'foo',346 'lorem' => 'ipsum',347 'key' => 'bar',348 ),349 'foobaz' => array(350 'foo' => 'baz',351 'key' => 'value',352 ),353 ),354 'foo',355 'ASC',356 array(357 'foobar' => array(358 'foo' => 'bar',359 'bar' => 'baz',360 'key' => 'foo',361 ),362 'foobaz' => array(363 'foo' => 'baz',364 'key' => 'value',365 ),366 'foofoo' => array(367 'foo' => 'foo',368 'lorem' => 'ipsum',369 'key' => 'bar',370 ),371 ),372 ),373 'single orderby descending' => array(374 array(375 'foobar' => array(376 'foo' => 'bar',377 'bar' => 'baz',378 'key' => 'foo',379 ),380 'foofoo' => array(381 'foo' => 'foo',382 'lorem' => 'ipsum',383 'key' => 'bar',384 ),385 'foobaz' => array(386 'foo' => 'baz',387 'key' => 'value',388 ),389 ),390 'foo',391 'DESC',392 array(393 'foofoo' => array(394 'foo' => 'foo',395 'lorem' => 'ipsum',396 'key' => 'bar',397 ),398 'foobaz' => array(399 'foo' => 'baz',400 'key' => 'value',401 ),402 'foobar' => array(403 'foo' => 'bar',404 'bar' => 'baz',405 'key' => 'foo',406 ),407 ),408 ),409 'single orderby array ascending' => array(410 array(411 'foobar' => array(412 'foo' => 'bar',413 'bar' => 'baz',414 'key' => 'foo',415 ),416 'foofoo' => array(417 'foo' => 'foo',418 'lorem' => 'ipsum',419 'key' => 'bar',420 ),421 'foobaz' => array(422 'foo' => 'baz',423 'key' => 'value',424 ),425 ),426 array( 'foo' => 'ASC' ),427 'IGNORED',428 array(429 'foobar' => array(430 'foo' => 'bar',431 'bar' => 'baz',432 'key' => 'foo',433 ),434 'foobaz' => array(435 'foo' => 'baz',436 'key' => 'value',437 ),438 'foofoo' => array(439 'foo' => 'foo',440 'lorem' => 'ipsum',441 'key' => 'bar',442 ),443 ),444 ),445 'single orderby array descending' => array(446 array(447 'foobar' => array(448 'foo' => 'bar',449 'bar' => 'baz',450 'key' => 'foo',451 ),452 'foofoo' => array(453 'foo' => 'foo',454 'lorem' => 'ipsum',455 'key' => 'bar',456 ),457 'foobaz' => array(458 'foo' => 'baz',459 'key' => 'value',460 ),461 ),462 array( 'foo' => 'DESC' ),463 'IGNORED',464 array(465 'foofoo' => array(466 'foo' => 'foo',467 'lorem' => 'ipsum',468 'key' => 'bar',469 ),470 'foobaz' => array(471 'foo' => 'baz',472 'key' => 'value',473 ),474 'foobar' => array(475 'foo' => 'bar',476 'bar' => 'baz',477 'key' => 'foo',478 ),479 ),480 ),481 'multiple orderby ascending' => array(482 array(483 'foobarfoo' => array(484 'foo' => 'bar',485 'bar' => 'baz',486 'key' => 'foo',487 ),488 'foofoobar' => array(489 'foo' => 'foo',490 'lorem' => 'ipsum',491 'key' => 'bar',492 ),493 'foofookey' => array(494 'foo' => 'foo',495 'key' => 'key',496 ),497 'foobazkey' => array(498 'foo' => 'baz',499 'key' => 'key',500 ),501 'foobarvalue' => array(502 'foo' => 'bar',503 'key' => 'value',504 ),505 ),506 array(507 'key' => 'ASC',508 'foo' => 'ASC',509 ),510 'IGNORED',511 array(512 'foofoobar' => array(513 'foo' => 'foo',514 'lorem' => 'ipsum',515 'key' => 'bar',516 ),517 'foobarfoo' => array(518 'foo' => 'bar',519 'bar' => 'baz',520 'key' => 'foo',521 ),522 'foobazkey' => array(523 'foo' => 'baz',524 'key' => 'key',525 ),526 'foofookey' => array(527 'foo' => 'foo',528 'key' => 'key',529 ),530 'foobarvalue' => array(531 'foo' => 'bar',532 'key' => 'value',533 ),534 ),535 ),536 'multiple orderby descending' => array(537 array(538 'foobarfoo' => array(539 'foo' => 'bar',540 'bar' => 'baz',541 'key' => 'foo',542 ),543 'foofoobar' => array(544 'foo' => 'foo',545 'lorem' => 'ipsum',546 'key' => 'bar',547 ),548 'foofookey' => array(549 'foo' => 'foo',550 'key' => 'key',551 ),552 'foobazkey' => array(553 'foo' => 'baz',554 'key' => 'key',555 ),556 'foobarvalue' => array(557 'foo' => 'bar',558 'key' => 'value',559 ),560 ),561 array(562 'key' => 'DESC',563 'foo' => 'DESC',564 ),565 'IGNORED',566 array(567 'foobarvalue' => array(568 'foo' => 'bar',569 'key' => 'value',570 ),571 'foofookey' => array(572 'foo' => 'foo',573 'key' => 'key',574 ),575 'foobazkey' => array(576 'foo' => 'baz',577 'key' => 'key',578 ),579 'foobarfoo' => array(580 'foo' => 'bar',581 'bar' => 'baz',582 'key' => 'foo',583 ),584 'foofoobar' => array(585 'foo' => 'foo',586 'lorem' => 'ipsum',587 'key' => 'bar',588 ),589 ),590 ),591 'multiple orderby mixed' => array(592 array(593 'foobarfoo' => array(594 'foo' => 'bar',595 'bar' => 'baz',596 'key' => 'foo',597 ),598 'foofoobar' => array(599 'foo' => 'foo',600 'lorem' => 'ipsum',601 'key' => 'bar',602 ),603 'foofookey' => array(604 'foo' => 'foo',605 'key' => 'key',606 ),607 'foobazkey' => array(608 'foo' => 'baz',609 'key' => 'key',610 ),611 'foobarvalue' => array(612 'foo' => 'bar',613 'key' => 'value',614 ),615 ),616 array(617 'key' => 'DESC',618 'foo' => 'ASC',619 ),620 'IGNORED',621 array(622 'foobarvalue' => array(623 'foo' => 'bar',624 'key' => 'value',625 ),626 'foobazkey' => array(627 'foo' => 'baz',628 'key' => 'key',629 ),630 'foofookey' => array(631 'foo' => 'foo',632 'key' => 'key',633 ),634 'foobarfoo' => array(635 'foo' => 'bar',636 'bar' => 'baz',637 'key' => 'foo',638 ),639 'foofoobar' => array(640 'foo' => 'foo',641 'lorem' => 'ipsum',642 'key' => 'bar',643 ),644 ),645 ),646 );647 }648 649 /**650 * @dataProvider data_test_wp_list_sort_preserve_keys651 *652 * @covers ::wp_list_sort653 *654 * @param string|array $orderby Either the field name to order by or an array655 * of multiple orderby fields as $orderby => $order.656 * @param string $order Either 'ASC' or 'DESC'.657 */658 public function test_wp_list_sort_preserve_keys( $list, $orderby, $order, $expected ) {659 $this->assertSame( $expected, wp_list_sort( $list, $orderby, $order, true ) );660 }661 9 662 10 /**
Note: See TracChangeset
for help on using the changeset viewer.