Merge pull request #24337 from woocommerce/fix/uppercase-boolean-values-importer

Allow wc_string_to_bool to not be case sensitive
This commit is contained in:
Claudio Sanches 2019-08-06 13:12:40 -03:00 committed by GitHub
commit b600b00091
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -18,7 +18,7 @@ defined( 'ABSPATH' ) || exit;
* @return bool
*/
function wc_string_to_bool( $string ) {
return is_bool( $string ) ? $string : ( 'yes' === $string || 1 === $string || 'true' === $string || '1' === $string );
return is_bool( $string ) ? $string : ( 'yes' === strtolower( $string ) || 1 === $string || 'true' === strtolower( $string ) || '1' === $string );
}
/**

View File

@ -30,10 +30,18 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
public function test_wc_string_to_bool() {
$this->assertTrue( wc_string_to_bool( 1 ) );
$this->assertTrue( wc_string_to_bool( 'yes' ) );
$this->assertTrue( wc_string_to_bool( 'Yes' ) );
$this->assertTrue( wc_string_to_bool( 'YES' ) );
$this->assertTrue( wc_string_to_bool( 'true' ) );
$this->assertTrue( wc_string_to_bool( 'True' ) );
$this->assertTrue( wc_string_to_bool( 'TRUE' ) );
$this->assertFalse( wc_string_to_bool( 0 ) );
$this->assertFalse( wc_string_to_bool( 'no' ) );
$this->assertFalse( wc_string_to_bool( 'No' ) );
$this->assertFalse( wc_string_to_bool( 'NO' ) );
$this->assertFalse( wc_string_to_bool( 'false' ) );
$this->assertFalse( wc_string_to_bool( 'False' ) );
$this->assertFalse( wc_string_to_bool( 'FALSE' ) );
}
/**