Ticket #30188: 30188.diff
File 30188.diff, 2.5 KB (added by , 5 years ago) 


src/wpincludes/functions.php
diff git src/wpincludes/functions.php src/wpincludes/functions.php index 94f7371..42606c1 100644
function wp_validate_boolean( $var ) { 4762 4762 4763 4763 return (bool) $var; 4764 4764 } 4765 4766 /** 4767 * Check if any number of constants are defined and true. 4768 * 4769 * e.g. wp_check_constants( array( 'DOING_AJAX', 'DOING_AUTOSAVE' ) ) 4770 * 4771 * @since 4.1.0 4772 * 4773 * @param stringarray $constants Constant(s) to test. 4774 * @return bool True if all provided constants are defined and true, otherwise false. 4775 */ 4776 function wp_check_constants( $constants = '' ) { 4777 foreach( (array) $constants as $constant ) { 4778 if ( ! is_constant_true( $constant ) ) { 4779 return false; 4780 } 4781 } 4782 4783 return true; 4784 } 4785 4786 /** 4787 * Check if a constant is defined and true. 4788 * 4789 * @since 4.1.0 4790 * 4791 * @param string $constants Constant to test. 4792 * @return bool True if constant is defined and true, otherwise false. 4793 */ 4794 function is_constant_true( $constant = '' ) { 4795 $constant = strtoupper( $constant ); 4796 return defined( $constant ) && true === constant( $constant ); 4797 } 
tests/phpunit/tests/post.php
diff git tests/phpunit/tests/post.php tests/phpunit/tests/post.php index 7334fe2..7f9cbda 100644
class Tests_Post extends WP_UnitTestCase { 991 991 _unregister_taxonomy( $tax ); 992 992 } 993 993 994 /** 995 * @ticket 30188 996 */ 997 function test_is_constant_true_true() { 998 define( 'TEST_IS_CONSTANT_TRUE_TRUE', true ); 999 $expected = is_constant_true( 'TEST_IS_CONSTANT_TRUE_TRUE' ); 1000 $this>assertTrue( $expected ); 1001 } 1002 1003 /** 1004 * @ticket 30188 1005 */ 1006 function test_is_constant_true_false() { 1007 define( 'TEST_IS_CONSTANT_TRUE_FALSE', false ); 1008 $expected = is_constant_true( 'TEST_IS_CONSTANT_TRUE_FALSE' ); 1009 $this>assertFalse( $expected ); 1010 } 1011 1012 /** 1013 * @ticket 30188 1014 */ 1015 function test_wp_check_constants_true() { 1016 define( 'TEST_WP_CHECK_CONSTANTS_TRUE_A', true ); 1017 define( 'TEST_WP_CHECK_CONSTANTS_TRUE_B', true ); 1018 $expected = wp_check_constants( array( 'TEST_WP_CHECK_CONSTANTS_TRUE_A', 'TEST_WP_CHECK_CONSTANTS_TRUE_B' ) ); 1019 $this>assertTrue( $expected ); 1020 } 1021 1022 /** 1023 * @ticket 30188 1024 */ 1025 function test_wp_check_constants_false() { 1026 define( 'TEST_WP_CHECK_CONSTANTS_FALSE_A', true ); 1027 define( 'TEST_WP_CHECK_CONSTANTS_FALSE_B', false ); 1028 $expected = wp_check_constants( array( 'TEST_WP_CHECK_CONSTANTS_FALSE_A', 'TEST_WP_CHECK_CONSTANTS_FALSE_B' ) ); 1029 $this>assertFalse( $expected ); 1030 } 1031 994 1032 }