Changeset 46159
- Timestamp:
- 09/17/2019 06:48:27 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/functions/WpValidateBoolean.php
r30207 r46159 2 2 3 3 /** 4 * Tests the wp_validate_boolean function. 5 * 6 * @covers ::wp_validate_boolean 4 7 * @group functions.php 5 8 */ 6 9 class Tests_Functions_WpValidateBoolean extends WP_UnitTestCase { 7 public function test_bool_true() { 8 $this->assertTrue( wp_validate_boolean( true ) ); 9 } 10 /** 11 * Provides test scenarios for all possible scenarios in wp_validate_boolean(). 12 * 13 * @return array 14 */ 15 function data_provider() { 16 $std = new \stdClass(); 10 17 11 public function test_int_1() { 12 $this->assertTrue( wp_validate_boolean( 1 ) ); 13 } 14 15 public function test_string_true_lowercase() { 16 $this->assertTrue( wp_validate_boolean( 'true' ) ); 17 } 18 19 public function test_string_true_uppercase() { 20 $this->assertTrue( wp_validate_boolean( 'TRUE' ) ); 21 } 22 23 public function test_arbitrary_string_should_return_true() { 24 $this->assertTrue( wp_validate_boolean( 'foobar' ) ); 25 } 26 27 public function test_bool_false() { 28 $this->assertFalse( wp_validate_boolean( false ) ); 29 } 30 31 public function test_int_0() { 32 $this->assertFalse( wp_validate_boolean( 0 ) ); 33 } 34 35 public function test_float_0() { 36 $this->assertFalse( wp_validate_boolean( 0.0 ) ); 37 } 38 39 public function test_empty_string() { 40 $this->assertFalse( wp_validate_boolean( '' ) ); 41 } 42 43 public function test_string_0() { 44 $this->assertFalse( wp_validate_boolean( '0' ) ); 45 } 46 47 public function test_empty_array() { 48 $this->assertFalse( wp_validate_boolean( array() ) ); 49 } 50 51 public function test_null() { 52 $this->assertFalse( wp_validate_boolean( null ) ); 53 } 54 55 public function test_string_false_lowercase() { 56 // Differs from (bool) conversion. 57 $this->assertFalse( wp_validate_boolean( 'false' ) ); 18 return array( 19 array( null, false ), 20 array( true, true ), 21 array( false, false ), 22 array( 'true', true ), 23 array( 'false', false ), 24 array( 'FalSE', false ), // @ticket 30238 25 array( 'FALSE', false ), // @ticket 30238 26 array( 'TRUE', true ), 27 array( ' FALSE ', true ), 28 array( 'yes', true ), 29 array( 'no', true ), 30 array( 'string', true ), 31 array( '', false ), 32 array( array(), false ), 33 array( 1, true ), 34 array( 0, false ), 35 array( -1, true ), 36 array( 99, true ), 37 array( 0.1, true ), 38 array( 0.0, false ), 39 array( '1', true ), 40 array( '0', false ), 41 array( $std, true ), 42 ); 58 43 } 59 44 60 45 /** 46 * Test wp_validate_boolean(). 47 * 48 * @dataProvider data_provider 49 * 50 * @param mixed $test_value. 51 * @param bool $expected. 52 * 61 53 * @ticket 30238 54 * @ticket 39868 62 55 */ 63 public function test_string_false_uppercase() { 64 // Differs from (bool) conversion. 65 $this->assertFalse( wp_validate_boolean( 'FALSE' ) ); 66 } 67 68 /** 69 * @ticket 30238 70 */ 71 public function test_string_false_mixedcase() { 72 // Differs from (bool) conversion. 73 $this->assertFalse( wp_validate_boolean( 'FaLsE' ) ); 56 public function test_wp_validate_boolean( $test_value, $expected ) { 57 $this->assertEquals( wp_validate_boolean( $test_value ), $expected ); 74 58 } 75 59 }
Note: See TracChangeset
for help on using the changeset viewer.