WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/21/2020 12:27:46 AM (15 months ago)
Author:
whyisjake
Message:

Comments: Don't show the filter/pagination actions if there are no comments to list.

It doesn't make sense to be able to filter the comments list table when there are are no (trashed/spam) comments available.

Fixes #40188.
Props swissspidy, Jim_Panse, menakas, akbarhusen429, dinhtungdu, birgire, SergeyBiryukov, davidbaumwald, rebasaurus, whyisjake.

File:
1 edited

Legend:

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

    r48165 r48521  
    283283
    284284    /**
     285     * @ticket 40188
     286     */
     287    public function test_filter_button_should_not_be_shown_if_there_are_no_comments() {
     288        $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
     289
     290        ob_start();
     291        $table->extra_tablenav( 'top' );
     292        $output = ob_get_clean();
     293
     294        $this->assertNotContains( 'id="post-query-submit"', $output );
     295    }
     296
     297    /**
     298     * @ticket 40188
     299     */
     300    public function test_filter_button_should_be_shown_if_there_are_comments() {
     301        $post_id    = self::factory()->post->create();
     302        $comment_id = self::factory()->comment->create(
     303            array(
     304                'comment_post_ID'  => $post_id,
     305                'comment_approved' => '1',
     306            )
     307        );
     308
     309        $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
     310        $table->prepare_items();
     311
     312        ob_start();
     313        $table->extra_tablenav( 'top' );
     314        $output = ob_get_clean();
     315
     316        $this->assertContains( 'id="post-query-submit"', $output );
     317    }
     318
     319    /**
     320     * @ticket 40188
     321     */
     322    public function test_filter_comment_status_dropdown_should_be_shown_if_there_are_comments() {
     323        $post_id    = self::factory()->post->create();
     324        $comment_id = self::factory()->comment->create(
     325            array(
     326                'comment_post_ID'  => $post_id,
     327                'comment_approved' => '1',
     328            )
     329        );
     330
     331        $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
     332        $table->prepare_items();
     333
     334        ob_start();
     335        $table->extra_tablenav( 'top' );
     336        $output = ob_get_clean();
     337
     338        $this->assertContains( 'id="filter-by-comment-type"', $output );
     339        $this->assertContains( "<option value='comment'>", $output );
     340    }
     341
     342    /**
    285343     * @ticket 38341
    286344     */
Note: See TracChangeset for help on using the changeset viewer.