| 369 | /** |
| 370 | * Helper function to test default sorting for sortable columns. |
| 371 | * |
| 372 | * @param WP_ListTable $table Table to check. |
| 373 | * @param array $columns Column information to check for in table. |
| 374 | */ |
| 375 | protected function _test_sortable_columns( WP_List_Table $table, array $columns ) { |
| 376 | ob_start(); |
| 377 | $table->print_column_headers(); |
| 378 | $output = ob_get_clean(); |
| 379 | |
| 380 | foreach ( $columns as $col ) { |
| 381 | $col_id = $col['id']; |
| 382 | $col_orderby = $col['orderby']; |
| 383 | $col_order = $col['order']; |
| 384 | |
| 385 | $search_pattern = "|<th[^>]*id=['\"]{$col_id}['\"][^>]*><a[^>]*>|"; |
| 386 | $matches = array(); |
| 387 | preg_match_all( $search_pattern, $output, $matches ); |
| 388 | |
| 389 | $this->assertCount( 1, array_keys( $matches[0] ) ); |
| 390 | $this->assertContains( "orderby={$col_orderby}", $matches[0][0] ); |
| 391 | $this->assertContains( "order={$col_order}", $matches[0][0] ); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | /** |
| 396 | * @ticket 38238 |
| 397 | */ |
| 398 | public function test_comments_default_column_sorting() { |
| 399 | $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); |
| 400 | $columns = array( |
| 401 | array( |
| 402 | 'id' => 'author', |
| 403 | 'orderby' => 'comment_author', |
| 404 | 'order' => 'asc', |
| 405 | ), |
| 406 | array( |
| 407 | 'id' => 'response', |
| 408 | 'orderby' => 'comment_post_ID', |
| 409 | 'order' => 'asc', |
| 410 | ), |
| 411 | array( |
| 412 | 'id' => 'date', |
| 413 | 'orderby' => 'comment_date', |
| 414 | 'order' => 'asc', |
| 415 | ), |
| 416 | ); |
| 417 | $this->_test_sortable_columns( $table, $columns ); |
| 418 | } |
| 419 | |
| 420 | /** |
| 421 | * @ticket 38238 |
| 422 | */ |
| 423 | public function test_links_default_column_sorting() { |
| 424 | $table = _get_list_table( 'WP_Links_List_Table', array( 'screen' => 'link-manager' ) ); |
| 425 | $columns = array( |
| 426 | array( |
| 427 | 'id' => 'name', |
| 428 | 'orderby' => 'name', |
| 429 | 'order' => 'asc', |
| 430 | ), |
| 431 | array( |
| 432 | 'id' => 'url', |
| 433 | 'orderby' => 'url', |
| 434 | 'order' => 'asc', |
| 435 | ), |
| 436 | array( |
| 437 | 'id' => 'visible', |
| 438 | 'orderby' => 'visible', |
| 439 | 'order' => 'asc', |
| 440 | ), |
| 441 | array( |
| 442 | 'id' => 'rating', |
| 443 | 'orderby' => 'rating', |
| 444 | 'order' => 'desc', |
| 445 | ), |
| 446 | ); |
| 447 | $this->_test_sortable_columns( $table, $columns ); |
| 448 | } |
| 449 | |
| 450 | /* |
| 451 | * @ticket 38238 |
| 452 | */ |
| 453 | public function test_link_categories_default_column_sorting() { |
| 454 | $table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => 'edit-link_category' ) ); |
| 455 | $columns = array( |
| 456 | array( |
| 457 | 'id' => 'name', |
| 458 | 'orderby' => 'name', |
| 459 | 'order' => 'asc', |
| 460 | ), |
| 461 | array( |
| 462 | 'id' => 'description', |
| 463 | 'orderby' => 'description', |
| 464 | 'order' => 'asc', |
| 465 | ), |
| 466 | array( |
| 467 | 'id' => 'slug', |
| 468 | 'orderby' => 'slug', |
| 469 | 'order' => 'asc', |
| 470 | ), |
| 471 | array( |
| 472 | 'id' => 'links', |
| 473 | 'orderby' => 'count', |
| 474 | 'order' => 'desc', |
| 475 | ), |
| 476 | ); |
| 477 | $this->_test_sortable_columns( $table, $columns ); |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * @ticket 38238 |
| 482 | */ |
| 483 | public function test_media_default_column_sorting() { |
| 484 | $table = _get_list_table( 'WP_Media_List_Table', array( 'screen' => 'upload' ) ); |
| 485 | $columns = array( |
| 486 | array( |
| 487 | 'id' => 'title', |
| 488 | 'orderby' => 'title', |
| 489 | 'order' => 'asc', |
| 490 | ), |
| 491 | array( |
| 492 | 'id' => 'author', |
| 493 | 'orderby' => 'author', |
| 494 | 'order' => 'asc', |
| 495 | ), |
| 496 | array( |
| 497 | 'id' => 'parent', |
| 498 | 'orderby' => 'parent', |
| 499 | 'order' => 'asc', |
| 500 | ), |
| 501 | array( |
| 502 | 'id' => 'comments', |
| 503 | 'orderby' => 'comment_count', |
| 504 | 'order' => 'desc', |
| 505 | ), |
| 506 | array( |
| 507 | 'id' => 'date', |
| 508 | 'orderby' => 'date', |
| 509 | 'order' => 'desc', |
| 510 | ), |
| 511 | ); |
| 512 | $this->_test_sortable_columns( $table, $columns ); |
| 513 | } |
| 514 | |
| 515 | /* |
| 516 | * @ticket 38238 |
| 517 | */ |
| 518 | public function test_pages_default_column_sorting() { |
| 519 | $table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => 'edit-page' ) ); |
| 520 | $columns = array( |
| 521 | array( |
| 522 | 'id' => 'title', |
| 523 | 'orderby' => 'title', |
| 524 | 'order' => 'asc', |
| 525 | ), |
| 526 | array( |
| 527 | 'id' => 'comments', |
| 528 | 'orderby' => 'comment_count', |
| 529 | 'order' => 'desc', |
| 530 | ), |
| 531 | array( |
| 532 | 'id' => 'date', |
| 533 | 'orderby' => 'date', |
| 534 | 'order' => 'desc', |
| 535 | ), |
| 536 | ); |
| 537 | $this->_test_sortable_columns( $table, $columns ); |
| 538 | } |
| 539 | |
| 540 | /** |
| 541 | * @ticket 38238 |
| 542 | */ |
| 543 | public function test_posts_default_column_sorting() { |
| 544 | $table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => 'edit-post' ) ); |
| 545 | $columns = array( |
| 546 | array( |
| 547 | 'id' => 'title', |
| 548 | 'orderby' => 'title', |
| 549 | 'order' => 'asc', |
| 550 | ), |
| 551 | array( |
| 552 | 'id' => 'comments', |
| 553 | 'orderby' => 'comment_count', |
| 554 | 'order' => 'desc', |
| 555 | ), |
| 556 | array( |
| 557 | 'id' => 'date', |
| 558 | 'orderby' => 'date', |
| 559 | 'order' => 'desc', |
| 560 | ), |
| 561 | ); |
| 562 | $this->_test_sortable_columns( $table, $columns ); |
| 563 | } |
| 564 | |
| 565 | /* |
| 566 | * @ticket 38238 |
| 567 | */ |
| 568 | public function test_post_categories_default_column_sorting() { |
| 569 | $table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => 'edit-category' ) ); |
| 570 | $columns = array( |
| 571 | array( |
| 572 | 'id' => 'name', |
| 573 | 'orderby' => 'name', |
| 574 | 'order' => 'asc', |
| 575 | ), |
| 576 | array( |
| 577 | 'id' => 'description', |
| 578 | 'orderby' => 'description', |
| 579 | 'order' => 'asc', |
| 580 | ), |
| 581 | array( |
| 582 | 'id' => 'slug', |
| 583 | 'orderby' => 'slug', |
| 584 | 'order' => 'asc', |
| 585 | ), |
| 586 | array( |
| 587 | 'id' => 'posts', |
| 588 | 'orderby' => 'count', |
| 589 | 'order' => 'desc', |
| 590 | ), |
| 591 | ); |
| 592 | $this->_test_sortable_columns( $table, $columns ); |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * @ticket 38238 |
| 597 | */ |
| 598 | public function test_post_tags_default_column_sorting() { |
| 599 | $table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => 'edit-post_tags' ) ); |
| 600 | $columns = array( |
| 601 | array( |
| 602 | 'id' => 'name', |
| 603 | 'orderby' => 'name', |
| 604 | 'order' => 'asc', |
| 605 | ), |
| 606 | array( |
| 607 | 'id' => 'description', |
| 608 | 'orderby' => 'description', |
| 609 | 'order' => 'asc', |
| 610 | ), |
| 611 | array( |
| 612 | 'id' => 'slug', |
| 613 | 'orderby' => 'slug', |
| 614 | 'order' => 'asc', |
| 615 | ), |
| 616 | array( |
| 617 | 'id' => 'posts', |
| 618 | 'orderby' => 'count', |
| 619 | 'order' => 'desc', |
| 620 | ), |
| 621 | ); |
| 622 | $this->_test_sortable_columns( $table, $columns ); |
| 623 | } |
| 624 | |
| 625 | /** |
| 626 | * @ticket 38238 |
| 627 | */ |
| 628 | public function test_users_default_column_sorting() { |
| 629 | $table = _get_list_table( 'WP_MS_Users_List_Table', array( 'screen' => 'users' ) ); |
| 630 | $columns = array( |
| 631 | array( |
| 632 | 'id' => 'username', |
| 633 | 'orderby' => 'login', |
| 634 | 'order' => 'asc', |
| 635 | ), |
| 636 | array( |
| 637 | 'id' => 'email', |
| 638 | 'orderby' => 'email', |
| 639 | 'order' => 'asc', |
| 640 | ), |
| 641 | array( |
| 642 | 'id' => 'registered', |
| 643 | 'orderby' => 'registered', |
| 644 | 'order' => 'desc', |
| 645 | ), |
| 646 | ); |
| 647 | $this->_test_sortable_columns( $table, $columns ); |
| 648 | } |
| 649 | |