wordpress-develop/tests/phpunit/tests/load/wpGetDevelopmentMode.php
Peter Wilson 65a048fc15 General: Introduce all development mode.
Introduce the development mode `all` as a a cover-all mode for the existing `theme`, `plugin` and `core` development modes. Developers can use the `all` mode if they are developing both themes and plugins, for example.

Introduce the utility function `wp_in_development_mode()` allowing developers to detect the mode via a parameter. If the development mode is set to `all` this function will always return `true`. If the development mode is specific then only the chosen mode will return `true`.

Follow up to [56079,56042].

Props flixos90.
Fixes #57487.



git-svn-id: https://develop.svn.wordpress.org/trunk@56223 602fd350-edb4-49c9-b593-d223f7449a82
2023-07-13 00:27:06 +00:00

161 lines
3.5 KiB
PHP

<?php
/**
* Unit tests for `wp_get_development_mode()`.
*
* @package WordPress
* @subpackage UnitTests
* @since 6.3.0
*
* @group load.php
* @covers ::wp_get_development_mode
* @covers ::wp_in_development_mode
*/
class Test_WP_Get_Development_Mode extends WP_UnitTestCase {
/**
* Tests that `wp_get_development_mode()` returns the value of the `WP_DEVELOPMENT_MODE` constant.
*
* @ticket 57487
*/
public function test_wp_get_development_mode_constant() {
$this->assertSame( WP_DEVELOPMENT_MODE, wp_get_development_mode() );
}
/**
* Tests that `wp_get_development_mode()` allows test overrides.
*
* @ticket 57487
*/
public function test_wp_get_development_mode_test_overrides() {
global $_wp_tests_development_mode;
$_wp_tests_development_mode = 'plugin';
$this->assertSame( 'plugin', wp_get_development_mode() );
}
/**
* Tests that `wp_get_development_mode()` ignores invalid filter values.
*
* @ticket 57487
*/
public function test_wp_get_development_mode_filter_invalid_value() {
global $_wp_tests_development_mode;
$_wp_tests_development_mode = 'invalid';
$this->assertSame( '', wp_get_development_mode() );
}
/**
* Tests that `wp_in_development_mode()` returns expected results.
*
* @ticket 57487
* @dataProvider data_wp_in_development_mode
*/
public function test_wp_in_development_mode( $current, $given, $expected ) {
global $_wp_tests_development_mode;
$_wp_tests_development_mode = $current;
if ( $expected ) {
$this->assertTrue( wp_in_development_mode( $given ), "{$given} is expected to pass in {$current} mode" );
} else {
$this->assertFalse( wp_in_development_mode( $given ), "{$given} is expected to fail in {$current} mode" );
}
}
/**
* Data provider that returns test scenarios for the `test_wp_in_development_mode()` method.
*
* @return array[]
*/
public function data_wp_in_development_mode() {
return array(
'core mode, testing for core' => array(
'core',
'core',
true,
),
'plugin mode, testing for plugin' => array(
'plugin',
'plugin',
true,
),
'theme mode, testing for theme' => array(
'theme',
'theme',
true,
),
'core mode, testing for plugin' => array(
'core',
'plugin',
false,
),
'core mode, testing for theme' => array(
'core',
'theme',
false,
),
'plugin mode, testing for core' => array(
'plugin',
'core',
false,
),
'plugin mode, testing for theme' => array(
'plugin',
'theme',
false,
),
'theme mode, testing for core' => array(
'theme',
'core',
false,
),
'theme mode, testing for plugin' => array(
'theme',
'plugin',
false,
),
'all mode, testing for core' => array(
'all',
'core',
true,
),
'all mode, testing for plugin' => array(
'all',
'plugin',
true,
),
'all mode, testing for theme' => array(
'all',
'theme',
true,
),
'all mode, testing for all' => array(
'all',
'all',
true,
),
'all mode, testing for non-standard value' => array(
'all',
'random',
true,
),
'invalid mode, testing for core' => array(
'invalid',
'core',
false,
),
'invalid mode, testing for plugin' => array(
'invalid',
'plugin',
false,
),
'invalid mode, testing for theme' => array(
'invalid',
'theme',
false,
),
);
}
}