Changeset 48151
- Timestamp:
- 06/23/2020 11:13:35 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-list-table.php
r48134 r48151 947 947 948 948 /** 949 * Get a list of sortable columns. The format is:950 * 'internal-name' => 'orderby'951 * or952 * 'internal-name' => array( 'orderby', true )953 * 954 * The second format will make the initial sorting order be descending949 * Get a list of sortable columns. 950 * 951 * The format is: 952 * - `'internal-name' => 'orderby'` 953 * - `'internal-name' => array( 'orderby', 'asc' )` - The second element set the initial sorting order. 954 * - `'internal-name' => array( 'orderby', true )` - The second element will make the initial sorting order be descending. 955 955 * 956 956 * @since 3.1.0 … … 1162 1162 $class[] = $current_order; 1163 1163 } else { 1164 $order = $desc_first ? 'desc' : 'asc'; 1164 if ( in_array( strtolower( $desc_first ), array( 'desc', 'asc' ), true ) ) { 1165 $order = 'asc' === strtolower( $desc_first ) ? 'desc' : 'asc'; 1166 } else { 1167 $order = $desc_first ? 'desc' : 'asc'; 1168 } 1165 1169 $class[] = 'sortable'; 1166 $class[] = $desc_first? 'asc' : 'desc';1170 $class[] = 'desc' === $order ? 'asc' : 'desc'; 1167 1171 } 1168 1172 -
trunk/tests/phpunit/tests/admin/includesListTable.php
r47122 r48151 294 294 $this->assertNotContains( 'id="delete_all"', $output ); 295 295 } 296 297 /** 298 * @ticket 45089 299 */ 300 public function test_sortable_columns() { 301 require_once ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php'; 302 303 $override_sortable_columns = array( 304 'author' => array( 'comment_author', true ), 305 'response' => 'comment_post_ID', 306 'date' => array( 'comment_date', 'dEsC' ), // The ordering support should be case insensitive. 307 ); 308 309 // Stub the get_sortable_columns() method. 310 $object = $this->getMockBuilder( 'WP_Comments_List_Table' ) 311 ->setConstructorArgs( array( array( 'screen' => 'edit-comments' ) ) ) 312 ->setMethods( array( 'get_sortable_columns' ) ) 313 ->getMock(); 314 315 // Change the null return value of the stubbed get_sortable_columns() method. 316 $object->method( 'get_sortable_columns' ) 317 ->willReturn( $override_sortable_columns ); 318 319 $output = get_echo( array( $object, 'print_column_headers' ) ); 320 321 $this->assertContains( '?orderby=comment_author&order=desc', $output, 'Mismatch of the default link ordering for comment author column. Should be desc.' ); 322 $this->assertContains( 'column-author sortable asc', $output, 'Mismatch of CSS classes for the comment author column.' ); 323 324 $this->assertContains( '?orderby=comment_post_ID&order=asc', $output, 'Mismatch of the default link ordering for comment response column. Should be asc.' ); 325 $this->assertContains( 'column-response sortable desc', $output, 'Mismatch of CSS classes for the comment post ID column.' ); 326 327 $this->assertContains( '?orderby=comment_date&order=asc', $output, 'Mismatch of the default link ordering for comment author column. Should be asc.' ); 328 $this->assertContains( 'column-date sortable desc', $output, 'Mismatch of CSS classes for the comment date column.' ); 329 } 330 331 /** 332 * @ticket 45089 333 */ 334 public function test_sortable_columns_with_current_ordering() { 335 require_once ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php'; 336 337 $override_sortable_columns = array( 338 'author' => array( 'comment_author', false ), 339 'response' => 'comment_post_ID', 340 'date' => array( 'comment_date', 'asc' ), // We will override this with current ordering. 341 ); 342 343 // Current ordering. 344 $_GET['orderby'] = 'comment_date'; 345 $_GET['order'] = 'desc'; 346 347 // Stub the get_sortable_columns() method. 348 $object = $this->getMockBuilder( 'WP_Comments_List_Table' ) 349 ->setConstructorArgs( array( array( 'screen' => 'edit-comments' ) ) ) 350 ->setMethods( array( 'get_sortable_columns' ) ) 351 ->getMock(); 352 353 // Change the null return value of the stubbed get_sortable_columns() method. 354 $object->method( 'get_sortable_columns' ) 355 ->willReturn( $override_sortable_columns ); 356 357 $output = get_echo( array( $object, 'print_column_headers' ) ); 358 359 $this->assertContains( '?orderby=comment_author&order=asc', $output, 'Mismatch of the default link ordering for comment author column. Should be asc.' ); 360 $this->assertContains( 'column-author sortable desc', $output, 'Mismatch of CSS classes for the comment author column.' ); 361 362 $this->assertContains( '?orderby=comment_post_ID&order=asc', $output, 'Mismatch of the default link ordering for comment response column. Should be asc.' ); 363 $this->assertContains( 'column-response sortable desc', $output, 'Mismatch of CSS classes for the comment post ID column.' ); 364 365 $this->assertContains( '?orderby=comment_date&order=asc', $output, 'Mismatch of the current link ordering for comment date column. Should be asc.' ); 366 $this->assertContains( 'column-date sorted desc', $output, 'Mismatch of CSS classes for the comment date column.' ); 367 } 368 296 369 }
Note: See TracChangeset
for help on using the changeset viewer.