From 1219355f2bacb1e04cfb510f570f165a1431b3e4 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 3 Nov 2014 15:51:11 +0000 Subject: [PATCH] Add unit tests for `wp_validate_boolean()`. Props TobiasBg. See #30238. git-svn-id: https://develop.svn.wordpress.org/trunk@30206 602fd350-edb4-49c9-b593-d223f7449a82 --- .../tests/functions/WpValidateBoolean.php | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/phpunit/tests/functions/WpValidateBoolean.php diff --git a/tests/phpunit/tests/functions/WpValidateBoolean.php b/tests/phpunit/tests/functions/WpValidateBoolean.php new file mode 100644 index 0000000000..812563757e --- /dev/null +++ b/tests/phpunit/tests/functions/WpValidateBoolean.php @@ -0,0 +1,59 @@ +assertTrue( wp_validate_boolean( true ) ); + } + + public function test_int_1() { + $this->assertTrue( wp_validate_boolean( 1 ) ); + } + + public function test_string_true_lowercase() { + $this->assertTrue( wp_validate_boolean( 'true' ) ); + } + + public function test_string_true_uppercase() { + $this->assertTrue( wp_validate_boolean( 'TRUE' ) ); + } + + public function test_arbitrary_string_should_return_true() { + $this->assertTrue( wp_validate_boolean( 'foobar' ) ); + } + + public function test_bool_false() { + $this->assertFalse( wp_validate_boolean( false ) ); + } + + public function test_int_0() { + $this->assertFalse( wp_validate_boolean( 0 ) ); + } + + public function test_float_0() { + $this->assertFalse( wp_validate_boolean( 0.0 ) ); + } + + public function test_empty_string() { + $this->assertFalse( wp_validate_boolean( '' ) ); + } + + public function test_string_0() { + $this->assertFalse( wp_validate_boolean( '0' ) ); + } + + public function test_empty_array() { + $this->assertFalse( wp_validate_boolean( array() ) ); + } + + public function test_null() { + $this->assertFalse( wp_validate_boolean( null ) ); + } + + public function test_string_false_lowercase() { + // Differs from (bool) conversion. + $this->assertFalse( wp_validate_boolean( 'false' ) ); + } +}