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:
commit
b600b00091
|
@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue