mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@51997 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group admin
|
||||
*/
|
||||
class Tests_Admin_wpCommentsListTable extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var WP_Comments_List_Table
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
function set_up() {
|
||||
parent::set_up();
|
||||
$this->table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40188
|
||||
*
|
||||
* @covers WP_Posts_List_Table::extra_tablenav
|
||||
*/
|
||||
public function test_filter_button_should_not_be_shown_if_there_are_no_comments() {
|
||||
ob_start();
|
||||
$this->table->extra_tablenav( 'top' );
|
||||
$output = ob_get_clean();
|
||||
|
||||
$this->assertStringNotContainsString( 'id="post-query-submit"', $output );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40188
|
||||
*
|
||||
* @covers WP_Posts_List_Table::extra_tablenav
|
||||
*/
|
||||
public function test_filter_button_should_be_shown_if_there_are_comments() {
|
||||
$post_id = self::factory()->post->create();
|
||||
$comment_id = self::factory()->comment->create(
|
||||
array(
|
||||
'comment_post_ID' => $post_id,
|
||||
'comment_approved' => '1',
|
||||
)
|
||||
);
|
||||
|
||||
$this->table->prepare_items();
|
||||
|
||||
ob_start();
|
||||
$this->table->extra_tablenav( 'top' );
|
||||
$output = ob_get_clean();
|
||||
|
||||
$this->assertStringContainsString( 'id="post-query-submit"', $output );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40188
|
||||
*
|
||||
* @covers WP_Posts_List_Table::extra_tablenav
|
||||
*/
|
||||
public function test_filter_comment_type_dropdown_should_be_shown_if_there_are_comments() {
|
||||
$post_id = self::factory()->post->create();
|
||||
$comment_id = self::factory()->comment->create(
|
||||
array(
|
||||
'comment_post_ID' => $post_id,
|
||||
'comment_approved' => '1',
|
||||
)
|
||||
);
|
||||
|
||||
$this->table->prepare_items();
|
||||
|
||||
ob_start();
|
||||
$this->table->extra_tablenav( 'top' );
|
||||
$output = ob_get_clean();
|
||||
|
||||
$this->assertStringContainsString( 'id="filter-by-comment-type"', $output );
|
||||
$this->assertStringContainsString( "<option value='comment'>", $output );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38341
|
||||
*
|
||||
* @covers WP_Posts_List_Table::extra_tablenav
|
||||
*/
|
||||
public function test_empty_trash_button_should_not_be_shown_if_there_are_no_comments() {
|
||||
ob_start();
|
||||
$this->table->extra_tablenav( 'top' );
|
||||
$output = ob_get_clean();
|
||||
|
||||
$this->assertStringNotContainsString( 'id="delete_all"', $output );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 19278
|
||||
*
|
||||
* @covers WP_Posts_List_Table::bulk_actions
|
||||
*/
|
||||
public function test_bulk_action_menu_supports_options_and_optgroups() {
|
||||
add_filter(
|
||||
'bulk_actions-edit-comments',
|
||||
static function() {
|
||||
return array(
|
||||
'delete' => 'Delete',
|
||||
'Change State' => array(
|
||||
'feature' => 'Featured',
|
||||
'sale' => 'On Sale',
|
||||
),
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ob_start();
|
||||
$this->table->bulk_actions();
|
||||
$output = ob_get_clean();
|
||||
|
||||
$expected = <<<'OPTIONS'
|
||||
<option value="delete">Delete</option>
|
||||
<optgroup label="Change State">
|
||||
<option value="feature">Featured</option>
|
||||
<option value="sale">On Sale</option>
|
||||
</optgroup>
|
||||
OPTIONS;
|
||||
$expected = str_replace( "\r\n", "\n", $expected );
|
||||
|
||||
$this->assertStringContainsString( $expected, $output );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 45089
|
||||
*
|
||||
* @covers WP_Posts_List_Table::print_column_headers
|
||||
*/
|
||||
public function test_sortable_columns() {
|
||||
$override_sortable_columns = array(
|
||||
'author' => array( 'comment_author', true ),
|
||||
'response' => 'comment_post_ID',
|
||||
'date' => array( 'comment_date', 'dEsC' ), // The ordering support should be case-insensitive.
|
||||
);
|
||||
|
||||
// Stub the get_sortable_columns() method.
|
||||
$object = $this->getMockBuilder( 'WP_Comments_List_Table' )
|
||||
->setConstructorArgs( array( array( 'screen' => 'edit-comments' ) ) )
|
||||
->setMethods( array( 'get_sortable_columns' ) )
|
||||
->getMock();
|
||||
|
||||
// Change the null return value of the stubbed get_sortable_columns() method.
|
||||
$object->method( 'get_sortable_columns' )
|
||||
->willReturn( $override_sortable_columns );
|
||||
|
||||
$output = get_echo( array( $object, 'print_column_headers' ) );
|
||||
|
||||
$this->assertStringContainsString( '?orderby=comment_author&order=desc', $output, 'Mismatch of the default link ordering for comment author column. Should be desc.' );
|
||||
$this->assertStringContainsString( 'column-author sortable asc', $output, 'Mismatch of CSS classes for the comment author column.' );
|
||||
|
||||
$this->assertStringContainsString( '?orderby=comment_post_ID&order=asc', $output, 'Mismatch of the default link ordering for comment response column. Should be asc.' );
|
||||
$this->assertStringContainsString( 'column-response sortable desc', $output, 'Mismatch of CSS classes for the comment post ID column.' );
|
||||
|
||||
$this->assertStringContainsString( '?orderby=comment_date&order=desc', $output, 'Mismatch of the default link ordering for comment date column. Should be asc.' );
|
||||
$this->assertStringContainsString( 'column-date sortable asc', $output, 'Mismatch of CSS classes for the comment date column.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 45089
|
||||
*
|
||||
* @covers WP_Posts_List_Table::print_column_headers
|
||||
*/
|
||||
public function test_sortable_columns_with_current_ordering() {
|
||||
$override_sortable_columns = array(
|
||||
'author' => array( 'comment_author', false ),
|
||||
'response' => 'comment_post_ID',
|
||||
'date' => array( 'comment_date', 'asc' ), // We will override this with current ordering.
|
||||
);
|
||||
|
||||
// Current ordering.
|
||||
$_GET['orderby'] = 'comment_date';
|
||||
$_GET['order'] = 'desc';
|
||||
|
||||
// Stub the get_sortable_columns() method.
|
||||
$object = $this->getMockBuilder( 'WP_Comments_List_Table' )
|
||||
->setConstructorArgs( array( array( 'screen' => 'edit-comments' ) ) )
|
||||
->setMethods( array( 'get_sortable_columns' ) )
|
||||
->getMock();
|
||||
|
||||
// Change the null return value of the stubbed get_sortable_columns() method.
|
||||
$object->method( 'get_sortable_columns' )
|
||||
->willReturn( $override_sortable_columns );
|
||||
|
||||
$output = get_echo( array( $object, 'print_column_headers' ) );
|
||||
|
||||
$this->assertStringContainsString( '?orderby=comment_author&order=asc', $output, 'Mismatch of the default link ordering for comment author column. Should be asc.' );
|
||||
$this->assertStringContainsString( 'column-author sortable desc', $output, 'Mismatch of CSS classes for the comment author column.' );
|
||||
|
||||
$this->assertStringContainsString( '?orderby=comment_post_ID&order=asc', $output, 'Mismatch of the default link ordering for comment response column. Should be asc.' );
|
||||
$this->assertStringContainsString( 'column-response sortable desc', $output, 'Mismatch of CSS classes for the comment post ID column.' );
|
||||
|
||||
$this->assertStringContainsString( '?orderby=comment_date&order=asc', $output, 'Mismatch of the current link ordering for comment date column. Should be asc.' );
|
||||
$this->assertStringContainsString( 'column-date sorted desc', $output, 'Mismatch of CSS classes for the comment date column.' );
|
||||
}
|
||||
|
||||
}
|
||||
+1
-193
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* @group admin
|
||||
*/
|
||||
class Tests_Admin_IncludesListTable extends WP_UnitTestCase {
|
||||
class Tests_Admin_wpPostsListTable extends WP_UnitTestCase {
|
||||
protected static $top = array();
|
||||
protected static $children = array();
|
||||
protected static $grandchildren = array();
|
||||
@@ -319,196 +319,4 @@ class Tests_Admin_IncludesListTable extends WP_UnitTestCase {
|
||||
$this->assertStringNotContainsString( 'id="delete_all"', $output );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40188
|
||||
*
|
||||
* @covers WP_Posts_List_Table::extra_tablenav
|
||||
*/
|
||||
public function test_filter_button_should_not_be_shown_if_there_are_no_comments() {
|
||||
$table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
|
||||
|
||||
ob_start();
|
||||
$table->extra_tablenav( 'top' );
|
||||
$output = ob_get_clean();
|
||||
|
||||
$this->assertStringNotContainsString( 'id="post-query-submit"', $output );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40188
|
||||
*
|
||||
* @covers WP_Posts_List_Table::extra_tablenav
|
||||
*/
|
||||
public function test_filter_button_should_be_shown_if_there_are_comments() {
|
||||
$post_id = self::factory()->post->create();
|
||||
$comment_id = self::factory()->comment->create(
|
||||
array(
|
||||
'comment_post_ID' => $post_id,
|
||||
'comment_approved' => '1',
|
||||
)
|
||||
);
|
||||
|
||||
$table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
|
||||
$table->prepare_items();
|
||||
|
||||
ob_start();
|
||||
$table->extra_tablenav( 'top' );
|
||||
$output = ob_get_clean();
|
||||
|
||||
$this->assertStringContainsString( 'id="post-query-submit"', $output );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40188
|
||||
*
|
||||
* @covers WP_Posts_List_Table::extra_tablenav
|
||||
*/
|
||||
public function test_filter_comment_type_dropdown_should_be_shown_if_there_are_comments() {
|
||||
$post_id = self::factory()->post->create();
|
||||
$comment_id = self::factory()->comment->create(
|
||||
array(
|
||||
'comment_post_ID' => $post_id,
|
||||
'comment_approved' => '1',
|
||||
)
|
||||
);
|
||||
|
||||
$table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
|
||||
$table->prepare_items();
|
||||
|
||||
ob_start();
|
||||
$table->extra_tablenav( 'top' );
|
||||
$output = ob_get_clean();
|
||||
|
||||
$this->assertStringContainsString( 'id="filter-by-comment-type"', $output );
|
||||
$this->assertStringContainsString( "<option value='comment'>", $output );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38341
|
||||
*
|
||||
* @covers WP_Posts_List_Table::extra_tablenav
|
||||
*/
|
||||
public function test_empty_trash_button_should_not_be_shown_if_there_are_no_comments() {
|
||||
$table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
|
||||
|
||||
ob_start();
|
||||
$table->extra_tablenav( 'top' );
|
||||
$output = ob_get_clean();
|
||||
|
||||
$this->assertStringNotContainsString( 'id="delete_all"', $output );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 19278
|
||||
*
|
||||
* @covers WP_Posts_List_Table::bulk_actions
|
||||
*/
|
||||
public function test_bulk_action_menu_supports_options_and_optgroups() {
|
||||
$table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
|
||||
|
||||
add_filter(
|
||||
'bulk_actions-edit-comments',
|
||||
static function() {
|
||||
return array(
|
||||
'delete' => 'Delete',
|
||||
'Change State' => array(
|
||||
'feature' => 'Featured',
|
||||
'sale' => 'On Sale',
|
||||
),
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ob_start();
|
||||
$table->bulk_actions();
|
||||
$output = ob_get_clean();
|
||||
|
||||
$expected = <<<'OPTIONS'
|
||||
<option value="delete">Delete</option>
|
||||
<optgroup label="Change State">
|
||||
<option value="feature">Featured</option>
|
||||
<option value="sale">On Sale</option>
|
||||
</optgroup>
|
||||
OPTIONS;
|
||||
$expected = str_replace( "\r\n", "\n", $expected );
|
||||
|
||||
$this->assertStringContainsString( $expected, $output );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 45089
|
||||
*
|
||||
* @covers WP_Posts_List_Table::print_column_headers
|
||||
*/
|
||||
public function test_sortable_columns() {
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php';
|
||||
|
||||
$override_sortable_columns = array(
|
||||
'author' => array( 'comment_author', true ),
|
||||
'response' => 'comment_post_ID',
|
||||
'date' => array( 'comment_date', 'dEsC' ), // The ordering support should be case-insensitive.
|
||||
);
|
||||
|
||||
// Stub the get_sortable_columns() method.
|
||||
$object = $this->getMockBuilder( 'WP_Comments_List_Table' )
|
||||
->setConstructorArgs( array( array( 'screen' => 'edit-comments' ) ) )
|
||||
->setMethods( array( 'get_sortable_columns' ) )
|
||||
->getMock();
|
||||
|
||||
// Change the null return value of the stubbed get_sortable_columns() method.
|
||||
$object->method( 'get_sortable_columns' )
|
||||
->willReturn( $override_sortable_columns );
|
||||
|
||||
$output = get_echo( array( $object, 'print_column_headers' ) );
|
||||
|
||||
$this->assertStringContainsString( '?orderby=comment_author&order=desc', $output, 'Mismatch of the default link ordering for comment author column. Should be desc.' );
|
||||
$this->assertStringContainsString( 'column-author sortable asc', $output, 'Mismatch of CSS classes for the comment author column.' );
|
||||
|
||||
$this->assertStringContainsString( '?orderby=comment_post_ID&order=asc', $output, 'Mismatch of the default link ordering for comment response column. Should be asc.' );
|
||||
$this->assertStringContainsString( 'column-response sortable desc', $output, 'Mismatch of CSS classes for the comment post ID column.' );
|
||||
|
||||
$this->assertStringContainsString( '?orderby=comment_date&order=desc', $output, 'Mismatch of the default link ordering for comment date column. Should be asc.' );
|
||||
$this->assertStringContainsString( 'column-date sortable asc', $output, 'Mismatch of CSS classes for the comment date column.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 45089
|
||||
*
|
||||
* @covers WP_Posts_List_Table::print_column_headers
|
||||
*/
|
||||
public function test_sortable_columns_with_current_ordering() {
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php';
|
||||
|
||||
$override_sortable_columns = array(
|
||||
'author' => array( 'comment_author', false ),
|
||||
'response' => 'comment_post_ID',
|
||||
'date' => array( 'comment_date', 'asc' ), // We will override this with current ordering.
|
||||
);
|
||||
|
||||
// Current ordering.
|
||||
$_GET['orderby'] = 'comment_date';
|
||||
$_GET['order'] = 'desc';
|
||||
|
||||
// Stub the get_sortable_columns() method.
|
||||
$object = $this->getMockBuilder( 'WP_Comments_List_Table' )
|
||||
->setConstructorArgs( array( array( 'screen' => 'edit-comments' ) ) )
|
||||
->setMethods( array( 'get_sortable_columns' ) )
|
||||
->getMock();
|
||||
|
||||
// Change the null return value of the stubbed get_sortable_columns() method.
|
||||
$object->method( 'get_sortable_columns' )
|
||||
->willReturn( $override_sortable_columns );
|
||||
|
||||
$output = get_echo( array( $object, 'print_column_headers' ) );
|
||||
|
||||
$this->assertStringContainsString( '?orderby=comment_author&order=asc', $output, 'Mismatch of the default link ordering for comment author column. Should be asc.' );
|
||||
$this->assertStringContainsString( 'column-author sortable desc', $output, 'Mismatch of CSS classes for the comment author column.' );
|
||||
|
||||
$this->assertStringContainsString( '?orderby=comment_post_ID&order=asc', $output, 'Mismatch of the default link ordering for comment response column. Should be asc.' );
|
||||
$this->assertStringContainsString( 'column-response sortable desc', $output, 'Mismatch of CSS classes for the comment post ID column.' );
|
||||
|
||||
$this->assertStringContainsString( '?orderby=comment_date&order=asc', $output, 'Mismatch of the current link ordering for comment date column. Should be asc.' );
|
||||
$this->assertStringContainsString( 'column-date sorted desc', $output, 'Mismatch of CSS classes for the comment date column.' );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user