Make WordPress Core

Ticket #39868: 39868.diff

File 39868.diff, 3.2 KB (added by desrosj, 7 years ago)
  • tests/phpunit/tests/functions/WpValidateBoolean.php

     
    11<?php
    22
    33/**
     4 * Tests the wp_validate_boolean function.
     5 *
     6 * @covers ::wp_validate_boolean
    47 * @group functions.php
    58 */
    69class Tests_Functions_WpValidateBoolean extends WP_UnitTestCase {
    7         public function test_bool_true() {
    8                 $this->assertTrue( wp_validate_boolean( true ) );
    9         }
    10 
    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' ) );
    58         }
    59 
    6010        /**
    61          * @ticket 30238
     11         * Provides test scenarios for all possible scenarios in wp_validate_boolean().
     12         *
     13         * @return array
    6214         */
    63         public function test_string_false_uppercase() {
    64                 // Differs from (bool) conversion.
    65                 $this->assertFalse( wp_validate_boolean( 'FALSE' ) );
     15        function data_provider() {
     16                        $std = new \stdClass();
     17
     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                        );
    6643        }
    6744
    6845        /**
    69          * @ticket 30238
     46         * Test wp_validate_boolean().
     47         *
     48         * @dataProvider data_provider
     49         *
     50         * @param mixed $test_value.
     51         * @param bool $expected.
    7052         */
    71         public function test_string_false_mixedcase() {
    72                 // Differs from (bool) conversion.
    73                 $this->assertFalse( wp_validate_boolean( 'FaLsE' ) );
     53        public function test_wp_validate_boolean( $test_value, $expected ) {
     54                $this->assertEquals( wp_validate_boolean( $test_value ), $expected );
    7455        }
    7556}