Make WordPress Core

Ticket #38341: 38341.6.diff

File 38341.6.diff, 4.1 KB (added by swissspidy, 8 years ago)

Adds another test for the comments list table

  • src/wp-admin/includes/class-wp-comments-list-table.php

    diff --git src/wp-admin/includes/class-wp-comments-list-table.php src/wp-admin/includes/class-wp-comments-list-table.php
    index 8f53ae4be7..fa41a7203c 100644
    class WP_Comments_List_Table extends WP_List_Table { 
    354354                        submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
    355355                }
    356356
    357                 if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && current_user_can( 'moderate_comments' ) ) {
     357                if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && current_user_can( 'moderate_comments' ) && $this->has_items() ) {
    358358                        wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
    359359                        $title = ( 'spam' === $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' );
    360360                        submit_button( $title, 'apply', 'delete_all', false );
  • src/wp-admin/includes/class-wp-media-list-table.php

    diff --git src/wp-admin/includes/class-wp-media-list-table.php src/wp-admin/includes/class-wp-media-list-table.php
    index 97b166e59c..805f4017d3 100644
    class WP_Media_List_Table extends WP_List_Table { 
    177177                        submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
    178178                }
    179179
    180                 if ( $this->is_trash && current_user_can( 'edit_others_posts' ) ) {
     180                if ( $this->is_trash && current_user_can( 'edit_others_posts' ) && $this->has_items() ) {
    181181                        submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
    182182                } ?>
    183183                </div>
  • src/wp-admin/includes/class-wp-posts-list-table.php

    diff --git src/wp-admin/includes/class-wp-posts-list-table.php src/wp-admin/includes/class-wp-posts-list-table.php
    index 668c3d20a4..535a2dd0c8 100644
    class WP_Posts_List_Table extends WP_List_Table { 
    489489                        }
    490490                }
    491491
    492                 if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) ) {
     492                if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) && $this->has_items() ) {
    493493                        submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
    494494                }
    495495?>
  • src/wp-admin/js/edit-comments.js

    diff --git src/wp-admin/js/edit-comments.js src/wp-admin/js/edit-comments.js
    index 3de031022c..491d61e015 100644
    setCommentsList = function() { 
    461461                        updateCountText( 'span.trash-count', trashDiff );
    462462                }
    463463
     464                if ( ( 'trash' === settings.data.comment_status ) && ( 0 === getCount( $( 'span.trash-count' ) ) ) {
     465                        $( '#delete_all' ).hide();
     466                }
     467               
     468                if ( ( 'spam' === settings.data.comment_status ) && ( 0 === getCount( $( 'span.spam-count' ) ) ) {
     469                        $( '#delete_all' ).hide();
     470                }
     471
    464472                if ( ! isDashboard ) {
    465473                        total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
    466474                        if ( $(settings.target).parent().is('span.undo') )
  • tests/phpunit/tests/admin/includesListTable.php

    diff --git tests/phpunit/tests/admin/includesListTable.php tests/phpunit/tests/admin/includesListTable.php
    index b0be74f28c..cf40457cdf 100644
    class Tests_Admin_includesListTable extends WP_UnitTestCase { 
    235235
    236236                $this->assertNotContains( 'id="cat"', $output );
    237237        }
     238
     239        /**
     240         * @ticket 38341
     241         */
     242        public function test_empty_trash_button_should_not_be_shown_if_there_are_no_posts() {
     243                // Set post type to a non-existent one.
     244                $this->table->screen->post_type = 'foo';
     245
     246                ob_start();
     247                $this->table->extra_tablenav( 'top' );
     248                $output = ob_get_clean();
     249
     250                $this->assertNotContains( 'id="delete_all"', $output );
     251        }
     252
     253        /**
     254         * @ticket 38341
     255         */
     256        public function test_empty_trash_button_should_not_be_shown_if_there_are_no_comments() {
     257                $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
     258
     259                ob_start();
     260                $table->extra_tablenav( 'top' );
     261                $output = ob_get_clean();
     262
     263                $this->assertNotContains( 'id="delete_all"', $output );
     264        }
    238265}