From 73375c4b326de73a4b0b885e658e9506c72606c6 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 30 Aug 2020 01:34:38 +0000 Subject: [PATCH] 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 --- .../phpunit/tests/admin/includesTemplate.php | 43 ------------------- tests/phpunit/tests/general/template.php | 41 ++++++++++++++++++ 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/tests/phpunit/tests/admin/includesTemplate.php b/tests/phpunit/tests/admin/includesTemplate.php index 20bd4bd0fd..4768bcb764 100644 --- a/tests/phpunit/tests/admin/includesTemplate.php +++ b/tests/phpunit/tests/admin/includesTemplate.php @@ -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 diff --git a/tests/phpunit/tests/general/template.php b/tests/phpunit/tests/general/template.php index b55bd37cb3..8c4a2b003a 100644 --- a/tests/phpunit/tests/general/template.php +++ b/tests/phpunit/tests/general/template.php @@ -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 ), + ); + } }