<?php
define( 'TESTDOX', true );
function wp_is_development_mode( $mode = null ) {
$current_mode = wp_get_development_mode();
if ( empty( $current_mode ) ) {
return '' === $mode;
}
// Return true if the current mode encompasses all modes.
if ( 'all' === $current_mode ) {
return true;
}
// Return true if the current mode is the given mode.
return $mode === $current_mode;
}
// Polyfill.
global $test_development_mode;
function wp_get_development_mode() {
global $test_development_mode;
return $test_development_mode;
}
// Test cases.
$dataset = array(
'both are empty strings' => array(
'mode' => '',
'dev' => '',
'expected' => true,
),
'both are non-empty, matching strings' => array(
'mode' => 'plugin',
'dev' => 'plugin',
'expected' => true,
),
'both are non-empty, unmatching strings' => array(
'mode' => 'core',
'dev' => 'theme',
'expected' => false,
),
'$mode is null and development mode is an empty string' => array(
'mode' => null,
'dev' => '',
'expected' => false,
),
'$mode is an empty string, development mode is a non-empty string' => array(
'mode' => '',
'dev' => 'core',
'expected' => false,
),
'$mode is a non-empty string, development mode is an empty string' => array(
'mode' => 'core',
'dev' => '',
'expected' => false,
),
);
foreach ( $dataset as $name => $data ) {
$test_development_mode = $data['dev'];
$actual = null === $data['mode'] ? wp_is_development_mode() : wp_is_development_mode( $data['mode'] );
$result = $actual === $data['expected'] ? '.' : 'F';
if ( defined( 'TESTDOX' ) && TESTDOX ) {
echo '.' === $result ? 'PASS' : 'FAIL', ': ', $name, ' (', var_export( $data['expected'], true ), ')', PHP_EOL;
} else {
echo $result;
}
}
preferences:
50.96 ms | 405 KiB | 5 Q