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
This commit is contained in:
Boone Gorges 2014-11-03 15:51:11 +00:00
parent f744ee189e
commit 1219355f2b
1 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,59 @@
<?php
/**
* @group functions.php
*/
class Tests_Functions_WpValidateBoolean extends WP_UnitTestCase {
public function test_bool_true() {
$this->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' ) );
}
}