Make WordPress Core


Ignore:
Timestamp:
11/03/2021 12:48:42 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Split WP_Posts_List_Table and WP_Comments_List_Table tests into two separate files for clarity.

These were previously combined in the includesListTable.php file. Since the tests were specific neither to the _get_list_table() function nor the parent WP_List_Table class, the naming was confusing, which should now be resolved.

Follow-up to [31730], [38854], [40297], [48151], [48521], [49190], [51993].

See #53363.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/wpPostsListTable.php

    r51996 r51997  
    44 * @group admin
    55 */
    6 class Tests_Admin_IncludesListTable extends WP_UnitTestCase {
     6class Tests_Admin_wpPostsListTable extends WP_UnitTestCase {
    77    protected static $top           = array();
    88    protected static $children      = array();
     
    320320    }
    321321
    322     /**
    323      * @ticket 40188
    324      *
    325      * @covers WP_Posts_List_Table::extra_tablenav
    326      */
    327     public function test_filter_button_should_not_be_shown_if_there_are_no_comments() {
    328         $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
    329 
    330         ob_start();
    331         $table->extra_tablenav( 'top' );
    332         $output = ob_get_clean();
    333 
    334         $this->assertStringNotContainsString( 'id="post-query-submit"', $output );
    335     }
    336 
    337     /**
    338      * @ticket 40188
    339      *
    340      * @covers WP_Posts_List_Table::extra_tablenav
    341      */
    342     public function test_filter_button_should_be_shown_if_there_are_comments() {
    343         $post_id    = self::factory()->post->create();
    344         $comment_id = self::factory()->comment->create(
    345             array(
    346                 'comment_post_ID'  => $post_id,
    347                 'comment_approved' => '1',
    348             )
    349         );
    350 
    351         $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
    352         $table->prepare_items();
    353 
    354         ob_start();
    355         $table->extra_tablenav( 'top' );
    356         $output = ob_get_clean();
    357 
    358         $this->assertStringContainsString( 'id="post-query-submit"', $output );
    359     }
    360 
    361     /**
    362      * @ticket 40188
    363      *
    364      * @covers WP_Posts_List_Table::extra_tablenav
    365      */
    366     public function test_filter_comment_type_dropdown_should_be_shown_if_there_are_comments() {
    367         $post_id    = self::factory()->post->create();
    368         $comment_id = self::factory()->comment->create(
    369             array(
    370                 'comment_post_ID'  => $post_id,
    371                 'comment_approved' => '1',
    372             )
    373         );
    374 
    375         $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
    376         $table->prepare_items();
    377 
    378         ob_start();
    379         $table->extra_tablenav( 'top' );
    380         $output = ob_get_clean();
    381 
    382         $this->assertStringContainsString( 'id="filter-by-comment-type"', $output );
    383         $this->assertStringContainsString( "<option value='comment'>", $output );
    384     }
    385 
    386     /**
    387      * @ticket 38341
    388      *
    389      * @covers WP_Posts_List_Table::extra_tablenav
    390      */
    391     public function test_empty_trash_button_should_not_be_shown_if_there_are_no_comments() {
    392         $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
    393 
    394         ob_start();
    395         $table->extra_tablenav( 'top' );
    396         $output = ob_get_clean();
    397 
    398         $this->assertStringNotContainsString( 'id="delete_all"', $output );
    399     }
    400 
    401     /**
    402      * @ticket 19278
    403      *
    404      * @covers WP_Posts_List_Table::bulk_actions
    405      */
    406     public function test_bulk_action_menu_supports_options_and_optgroups() {
    407         $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
    408 
    409         add_filter(
    410             'bulk_actions-edit-comments',
    411             static function() {
    412                 return array(
    413                     'delete'       => 'Delete',
    414                     'Change State' => array(
    415                         'feature' => 'Featured',
    416                         'sale'    => 'On Sale',
    417                     ),
    418                 );
    419             }
    420         );
    421 
    422         ob_start();
    423         $table->bulk_actions();
    424         $output = ob_get_clean();
    425 
    426         $expected = <<<'OPTIONS'
    427 <option value="delete">Delete</option>
    428     <optgroup label="Change State">
    429         <option value="feature">Featured</option>
    430         <option value="sale">On Sale</option>
    431     </optgroup>
    432 OPTIONS;
    433         $expected = str_replace( "\r\n", "\n", $expected );
    434 
    435         $this->assertStringContainsString( $expected, $output );
    436     }
    437 
    438     /**
    439      * @ticket 45089
    440      *
    441      * @covers WP_Posts_List_Table::print_column_headers
    442      */
    443     public function test_sortable_columns() {
    444         require_once ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php';
    445 
    446         $override_sortable_columns = array(
    447             'author'   => array( 'comment_author', true ),
    448             'response' => 'comment_post_ID',
    449             'date'     => array( 'comment_date', 'dEsC' ), // The ordering support should be case-insensitive.
    450         );
    451 
    452         // Stub the get_sortable_columns() method.
    453         $object = $this->getMockBuilder( 'WP_Comments_List_Table' )
    454             ->setConstructorArgs( array( array( 'screen' => 'edit-comments' ) ) )
    455             ->setMethods( array( 'get_sortable_columns' ) )
    456             ->getMock();
    457 
    458         // Change the null return value of the stubbed get_sortable_columns() method.
    459         $object->method( 'get_sortable_columns' )
    460             ->willReturn( $override_sortable_columns );
    461 
    462         $output = get_echo( array( $object, 'print_column_headers' ) );
    463 
    464         $this->assertStringContainsString( '?orderby=comment_author&#038;order=desc', $output, 'Mismatch of the default link ordering for comment author column. Should be desc.' );
    465         $this->assertStringContainsString( 'column-author sortable asc', $output, 'Mismatch of CSS classes for the comment author column.' );
    466 
    467         $this->assertStringContainsString( '?orderby=comment_post_ID&#038;order=asc', $output, 'Mismatch of the default link ordering for comment response column. Should be asc.' );
    468         $this->assertStringContainsString( 'column-response sortable desc', $output, 'Mismatch of CSS classes for the comment post ID column.' );
    469 
    470         $this->assertStringContainsString( '?orderby=comment_date&#038;order=desc', $output, 'Mismatch of the default link ordering for comment date column. Should be asc.' );
    471         $this->assertStringContainsString( 'column-date sortable asc', $output, 'Mismatch of CSS classes for the comment date column.' );
    472     }
    473 
    474     /**
    475      * @ticket 45089
    476      *
    477      * @covers WP_Posts_List_Table::print_column_headers
    478      */
    479     public function test_sortable_columns_with_current_ordering() {
    480         require_once ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php';
    481 
    482         $override_sortable_columns = array(
    483             'author'   => array( 'comment_author', false ),
    484             'response' => 'comment_post_ID',
    485             'date'     => array( 'comment_date', 'asc' ), // We will override this with current ordering.
    486         );
    487 
    488         // Current ordering.
    489         $_GET['orderby'] = 'comment_date';
    490         $_GET['order']   = 'desc';
    491 
    492         // Stub the get_sortable_columns() method.
    493         $object = $this->getMockBuilder( 'WP_Comments_List_Table' )
    494             ->setConstructorArgs( array( array( 'screen' => 'edit-comments' ) ) )
    495             ->setMethods( array( 'get_sortable_columns' ) )
    496             ->getMock();
    497 
    498         // Change the null return value of the stubbed get_sortable_columns() method.
    499         $object->method( 'get_sortable_columns' )
    500             ->willReturn( $override_sortable_columns );
    501 
    502         $output = get_echo( array( $object, 'print_column_headers' ) );
    503 
    504         $this->assertStringContainsString( '?orderby=comment_author&#038;order=asc', $output, 'Mismatch of the default link ordering for comment author column. Should be asc.' );
    505         $this->assertStringContainsString( 'column-author sortable desc', $output, 'Mismatch of CSS classes for the comment author column.' );
    506 
    507         $this->assertStringContainsString( '?orderby=comment_post_ID&#038;order=asc', $output, 'Mismatch of the default link ordering for comment response column. Should be asc.' );
    508         $this->assertStringContainsString( 'column-response sortable desc', $output, 'Mismatch of CSS classes for the comment post ID column.' );
    509 
    510         $this->assertStringContainsString( '?orderby=comment_date&#038;order=asc', $output, 'Mismatch of the current link ordering for comment date column. Should be asc.' );
    511         $this->assertStringContainsString( 'column-date sorted desc', $output, 'Mismatch of CSS classes for the comment date column.' );
    512     }
    513 
    514322}
Note: See TracChangeset for help on using the changeset viewer.