| | 265 | |
| | 266 | /** |
| | 267 | * Helper function to test default sorting for sortable columns. |
| | 268 | * @param WP_ListTable $table Table to check. |
| | 269 | * @param array $columns Column information to check for in table. |
| | 270 | */ |
| | 271 | protected function _test_sortable_columns( WP_List_Table $table, array $columns ) { |
| | 272 | ob_start(); |
| | 273 | $table->print_column_headers(); |
| | 274 | $output = ob_get_clean(); |
| | 275 | |
| | 276 | foreach( $columns as $col ) { |
| | 277 | $col_id = $col['id']; |
| | 278 | $col_orderby = $col['orderby']; |
| | 279 | $col_order = $col['order']; |
| | 280 | |
| | 281 | $search_pattern = "|<th[^>]*id=['\"]{$col_id}['\"][^>]*><a[^>]*>|"; |
| | 282 | $matches = array(); |
| | 283 | preg_match_all( $search_pattern, $output, $matches ); |
| | 284 | |
| | 285 | $this->assertCount( 1, array_keys( $matches[0] ) ); |
| | 286 | $this->assertContains( "orderby={$col_orderby}", $matches[0][0] ); |
| | 287 | $this->assertContains( "order={$col_order}", $matches[0][0] ); |
| | 288 | } |
| | 289 | } |
| | 290 | |
| | 291 | /** |
| | 292 | * @ticket 38238 |
| | 293 | */ |
| | 294 | public function test_comments_default_column_sorting() { |
| | 295 | $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); |
| | 296 | $columns = array( |
| | 297 | array( |
| | 298 | 'id' => 'author', |
| | 299 | 'orderby' => 'comment_author', |
| | 300 | 'order' => 'asc', |
| | 301 | ), |
| | 302 | array( |
| | 303 | 'id' => 'response', |
| | 304 | 'orderby' => 'comment_post_ID', |
| | 305 | 'order' => 'asc', |
| | 306 | ), |
| | 307 | array( |
| | 308 | 'id' => 'date', |
| | 309 | 'orderby' => 'comment_date', |
| | 310 | 'order' => 'asc', |
| | 311 | ), |
| | 312 | ); |
| | 313 | $this->_test_sortable_columns( $table, $columns ); |
| | 314 | } |
| | 315 | |
| | 316 | /** |
| | 317 | * @ticket 38238 |
| | 318 | */ |
| | 319 | public function test_links_default_column_sorting() { |
| | 320 | $table = _get_list_table( 'WP_Links_List_Table', array( 'screen' => 'link-manager' ) ); |
| | 321 | $columns = array( |
| | 322 | array( |
| | 323 | 'id' => 'name', |
| | 324 | 'orderby' => 'name', |
| | 325 | 'order' => 'asc', |
| | 326 | ), |
| | 327 | array( |
| | 328 | 'id' => 'url', |
| | 329 | 'orderby' => 'url', |
| | 330 | 'order' => 'asc', |
| | 331 | ), |
| | 332 | array( |
| | 333 | 'id' => 'visible', |
| | 334 | 'orderby' => 'visible', |
| | 335 | 'order' => 'asc', |
| | 336 | ), |
| | 337 | array( |
| | 338 | 'id' => 'rating', |
| | 339 | 'orderby' => 'rating', |
| | 340 | 'order' => 'desc', |
| | 341 | ), |
| | 342 | ); |
| | 343 | $this->_test_sortable_columns( $table, $columns ); |
| | 344 | } |
| | 345 | |
| | 346 | /* |
| | 347 | * @ticket 38238 |
| | 348 | */ |
| | 349 | public function test_link_categories_default_column_sorting() { |
| | 350 | $table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => 'edit-link_category' ) ); |
| | 351 | $columns = array( |
| | 352 | array( |
| | 353 | 'id' => 'name', |
| | 354 | 'orderby' => 'name', |
| | 355 | 'order' => 'asc', |
| | 356 | ), |
| | 357 | array( |
| | 358 | 'id' => 'description', |
| | 359 | 'orderby' => 'description', |
| | 360 | 'order' => 'asc', |
| | 361 | ), |
| | 362 | array( |
| | 363 | 'id' => 'slug', |
| | 364 | 'orderby' => 'slug', |
| | 365 | 'order' => 'asc', |
| | 366 | ), |
| | 367 | array( |
| | 368 | 'id' => 'links', |
| | 369 | 'orderby' => 'count', |
| | 370 | 'order' => 'desc', |
| | 371 | ), |
| | 372 | ); |
| | 373 | $this->_test_sortable_columns( $table, $columns ); |
| | 374 | } |
| | 375 | |
| | 376 | /** |
| | 377 | * @ticket 38238 |
| | 378 | */ |
| | 379 | public function test_media_default_column_sorting() { |
| | 380 | $table = _get_list_table( 'WP_Media_List_Table', array( 'screen' => 'upload' ) ); |
| | 381 | $columns = array( |
| | 382 | array( |
| | 383 | 'id' => 'title', |
| | 384 | 'orderby' => 'title', |
| | 385 | 'order' => 'asc', |
| | 386 | ), |
| | 387 | array( |
| | 388 | 'id' => 'author', |
| | 389 | 'orderby' => 'author', |
| | 390 | 'order' => 'asc', |
| | 391 | ), |
| | 392 | array( |
| | 393 | 'id' => 'parent', |
| | 394 | 'orderby' => 'parent', |
| | 395 | 'order' => 'asc', |
| | 396 | ), |
| | 397 | array( |
| | 398 | 'id' => 'comments', |
| | 399 | 'orderby' => 'comment_count', |
| | 400 | 'order' => 'desc', |
| | 401 | ), |
| | 402 | array( |
| | 403 | 'id' => 'date', |
| | 404 | 'orderby' => 'date', |
| | 405 | 'order' => 'desc', |
| | 406 | ), |
| | 407 | ); |
| | 408 | $this->_test_sortable_columns( $table, $columns ); |
| | 409 | } |
| | 410 | |
| | 411 | /* |
| | 412 | * @ticket 38238 |
| | 413 | */ |
| | 414 | public function test_pages_default_column_sorting() { |
| | 415 | $table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => 'edit-page' ) ); |
| | 416 | $columns = array( |
| | 417 | array( |
| | 418 | 'id' => 'title', |
| | 419 | 'orderby' => 'title', |
| | 420 | 'order' => 'asc' |
| | 421 | ), |
| | 422 | array( |
| | 423 | 'id' => 'comments', |
| | 424 | 'orderby' => 'comment_count', |
| | 425 | 'order' => 'desc' |
| | 426 | ), |
| | 427 | array( |
| | 428 | 'id' => 'date', |
| | 429 | 'orderby' => 'date', |
| | 430 | 'order' => 'desc' |
| | 431 | ), |
| | 432 | ); |
| | 433 | $this->_test_sortable_columns( $table, $columns ); |
| | 434 | } |
| | 435 | |
| | 436 | /** |
| | 437 | * @ticket 38238 |
| | 438 | */ |
| | 439 | public function test_posts_default_column_sorting() { |
| | 440 | $table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => 'edit-post' ) ); |
| | 441 | $columns = array( |
| | 442 | array( |
| | 443 | 'id' => 'title', |
| | 444 | 'orderby' => 'title', |
| | 445 | 'order' => 'asc' |
| | 446 | ), |
| | 447 | array( |
| | 448 | 'id' => 'comments', |
| | 449 | 'orderby' => 'comment_count', |
| | 450 | 'order' => 'desc' |
| | 451 | ), |
| | 452 | array( |
| | 453 | 'id' => 'date', |
| | 454 | 'orderby' => 'date', |
| | 455 | 'order' => 'desc' |
| | 456 | ), |
| | 457 | ); |
| | 458 | $this->_test_sortable_columns( $table, $columns ); |
| | 459 | } |
| | 460 | |
| | 461 | /* |
| | 462 | * @ticket 38238 |
| | 463 | */ |
| | 464 | public function test_post_categories_default_column_sorting() { |
| | 465 | $table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => 'edit-category' ) ); |
| | 466 | $columns = array( |
| | 467 | array( |
| | 468 | 'id' => 'name', |
| | 469 | 'orderby' => 'name', |
| | 470 | 'order' => 'asc', |
| | 471 | ), |
| | 472 | array( |
| | 473 | 'id' => 'description', |
| | 474 | 'orderby' => 'description', |
| | 475 | 'order' => 'asc', |
| | 476 | ), |
| | 477 | array( |
| | 478 | 'id' => 'slug', |
| | 479 | 'orderby' => 'slug', |
| | 480 | 'order' => 'asc', |
| | 481 | ), |
| | 482 | array( |
| | 483 | 'id' => 'posts', |
| | 484 | 'orderby' => 'count', |
| | 485 | 'order' => 'desc', |
| | 486 | ), |
| | 487 | ); |
| | 488 | $this->_test_sortable_columns( $table, $columns ); |
| | 489 | } |
| | 490 | |
| | 491 | /** |
| | 492 | * @ticket 38238 |
| | 493 | */ |
| | 494 | public function test_post_tags_default_column_sorting() { |
| | 495 | $table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => 'edit-post_tags' ) ); |
| | 496 | $columns = array( |
| | 497 | array( |
| | 498 | 'id' => 'name', |
| | 499 | 'orderby' => 'name', |
| | 500 | 'order' => 'asc', |
| | 501 | ), |
| | 502 | array( |
| | 503 | 'id' => 'description', |
| | 504 | 'orderby' => 'description', |
| | 505 | 'order' => 'asc', |
| | 506 | ), |
| | 507 | array( |
| | 508 | 'id' => 'slug', |
| | 509 | 'orderby' => 'slug', |
| | 510 | 'order' => 'asc', |
| | 511 | ), |
| | 512 | array( |
| | 513 | 'id' => 'posts', |
| | 514 | 'orderby' => 'count', |
| | 515 | 'order' => 'desc', |
| | 516 | ), |
| | 517 | ); |
| | 518 | $this->_test_sortable_columns( $table, $columns ); |
| | 519 | } |
| | 520 | |
| | 521 | /** |
| | 522 | * @ticket 38238 |
| | 523 | */ |
| | 524 | public function test_users_default_column_sorting() { |
| | 525 | $table = _get_list_table( 'WP_MS_Users_List_Table', array( 'screen' => 'users' ) ); |
| | 526 | $columns = array( |
| | 527 | array( |
| | 528 | 'id' => 'username', |
| | 529 | 'orderby' => 'login', |
| | 530 | 'order' => 'asc', |
| | 531 | ), |
| | 532 | array( |
| | 533 | 'id' => 'email', |
| | 534 | 'orderby' => 'email', |
| | 535 | 'order' => 'asc', |
| | 536 | ), |
| | 537 | array( |
| | 538 | 'id' => 'registered', |
| | 539 | 'orderby' => 'registered', |
| | 540 | 'order' => 'desc', |
| | 541 | ), |
| | 542 | ); |
| | 543 | $this->_test_sortable_columns( $table, $columns ); |
| | 544 | } |