Make WordPress Core

Ticket #30238: 30238.2-tests.diff

File 30238.2-tests.diff, 2.0 KB (added by TobiasBg, 10 years ago)
  • src/wp-includes/functions.php

    diff --git src/wp-includes/functions.php src/wp-includes/functions.php
    index dce925a..8ca5ca1 100644
    function reset_mbstring_encoding() { 
    47404740}
    47414741
    47424742/**
    4743  * Alternative to filter_var( $var, FILTER_VALIDATE_BOOLEAN ).
     4743 * Filter/validate a variable as a boolean.
     4744 *
     4745 * Alternative to `filter_var( $var, FILTER_VALIDATE_BOOLEAN )`.
    47444746 *
    47454747 * @since 4.0.0
    47464748 *
    function wp_validate_boolean( $var ) { 
    47524754                return $var;
    47534755        }
    47544756
    4755         if ( 'false' === $var ) {
     4757        if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
    47564758                return false;
    47574759        }
    47584760
  • tests/phpunit/tests/functions.php

    diff --git tests/phpunit/tests/functions.php tests/phpunit/tests/functions.php
    index c52623e..2a3eb6d 100644
    class Tests_Functions extends WP_UnitTestCase { 
    571571                $json = wp_json_encode( $data, 0, 1 );
    572572                $this->assertFalse( $json );
    573573        }
     574
     575        /**
     576         * @ticket 30238
     577         */
     578        function test_wp_validate_boolean() {
     579                // Cases where wp_validate_boolean() equals (bool) conversion:
     580                $this->assertTrue( wp_validate_boolean( true ) );
     581                $this->assertTrue( wp_validate_boolean( 1 ) );
     582                $this->assertTrue( wp_validate_boolean( 'true' ) );
     583                $this->assertTrue( wp_validate_boolean( 'TRUE' ) );
     584                $this->assertTrue( wp_validate_boolean( 'foobar' ) );
     585                $this->assertFalse( wp_validate_boolean( false ) );
     586                $this->assertFalse( wp_validate_boolean( 0 ) );
     587                $this->assertFalse( wp_validate_boolean( 0.0 ) );
     588                $this->assertFalse( wp_validate_boolean( '' ) );
     589                $this->assertFalse( wp_validate_boolean( '0' ) );
     590                $this->assertFalse( wp_validate_boolean( array() ) );
     591                $this->assertFalse( wp_validate_boolean( null ) );
     592
     593                // Cases where wp_validate_boolean() differs from (bool) conversion:
     594                $this->assertFalse( wp_validate_boolean( 'false' ) );
     595                $this->assertFalse( wp_validate_boolean( 'FALSE' ) );
     596                $this->assertFalse( wp_validate_boolean( 'FalsE' ) );
     597        }
    574598}