Tests: Move the tests for selected() and checked() to a more appropriate place.

Convert the tests to use data providers.

Props wittich.
Fixes #51166.

git-svn-id: https://develop.svn.wordpress.org/trunk@48907 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-08-30 01:34:38 +00:00
parent 5ec12d64d6
commit 73375c4b32
2 changed files with 41 additions and 43 deletions

View File

@ -4,49 +4,6 @@
*/
class Tests_Admin_includesTemplate extends WP_UnitTestCase {
function test_equal() {
$this->assertEquals( ' selected=\'selected\'', selected( 'foo', 'foo', false ) );
$this->assertEquals( ' checked=\'checked\'', checked( 'foo', 'foo', false ) );
$this->assertEquals( ' selected=\'selected\'', selected( '1', 1, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( '1', 1, false ) );
$this->assertEquals( ' selected=\'selected\'', selected( '1', true, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( '1', true, false ) );
$this->assertEquals( ' selected=\'selected\'', selected( 1, 1, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( 1, 1, false ) );
$this->assertEquals( ' selected=\'selected\'', selected( 1, true, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( 1, true, false ) );
$this->assertEquals( ' selected=\'selected\'', selected( true, true, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( true, true, false ) );
$this->assertEquals( ' selected=\'selected\'', selected( '0', 0, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( '0', 0, false ) );
$this->assertEquals( ' selected=\'selected\'', selected( 0, 0, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( 0, 0, false ) );
$this->assertEquals( ' selected=\'selected\'', selected( '', false, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( '', false, false ) );
$this->assertEquals( ' selected=\'selected\'', selected( false, false, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( false, false, false ) );
}
function test_notequal() {
$this->assertEquals( '', selected( '0', '', false ) );
$this->assertEquals( '', checked( '0', '', false ) );
$this->assertEquals( '', selected( 0, '', false ) );
$this->assertEquals( '', checked( 0, '', false ) );
$this->assertEquals( '', selected( 0, false, false ) );
$this->assertEquals( '', checked( 0, false, false ) );
}
/**
* @ticket 51147
* @dataProvider data_wp_terms_checklist_with_selected_cats

View File

@ -690,4 +690,45 @@ class Tests_General_Template extends WP_UnitTestCase {
get_template_part( 'template', 'part', array( 'foo' => 'baz' ) );
}
/**
* @ticket 9862
* @dataProvider data_selected_and_checked_with_equal_values
*/
function test_selected_and_checked_with_equal_values( $selected, $current ) {
$this->assertEquals( " selected='selected'", selected( $selected, $current, false ) );
$this->assertEquals( " checked='checked'", checked( $selected, $current, false ) );
}
function data_selected_and_checked_with_equal_values() {
return array(
array( 'foo', 'foo' ),
array( '1', 1 ),
array( '1', true ),
array( 1, 1 ),
array( 1, true ),
array( true, true ),
array( '0', 0 ),
array( 0, 0 ),
array( '', false ),
array( false, false ),
);
}
/**
* @ticket 9862
* @dataProvider data_selected_and_checked_with_non_equal_values
*/
function test_selected_and_checked_with_non_equal_values( $selected, $current ) {
$this->assertEquals( '', selected( $selected, $current, false ) );
$this->assertEquals( '', checked( $selected, $current, false ) );
}
function data_selected_and_checked_with_non_equal_values() {
return array(
array( '0', '' ),
array( 0, '' ),
array( 0, false ),
);
}
}