mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
General: Introduce WP_DEVELOPMENT_MODE constant to signify context-specific development mode.
In recent releases, WordPress core added several instances of cache usage around specific files. While those caches are safe to use in a production context, in development certain nuances apply for whether or not those caches make sense to use. Initially, `WP_DEBUG` was used as a temporary workaround, but it was clear that a more granular method to signify a specific development mode was required: For example, caches around `theme.json` should be disabled when working on a theme as otherwise it would disrupt the theme developer's workflow, but when working on a plugin or WordPress core, this consideration does not apply. This changeset introduces a `WP_DEVELOPMENT_MODE` constant which, for now, can be set to either "core", "plugin", "theme", or an empty string, the latter of which means no development mode, which is also the default. A new function `wp_get_development_mode()` is the recommended way to retrieve that configuration value. With the new function available, this changeset replaces all existing instances of the aforementioned `WP_DEBUG` workaround to use `wp_get_development_mode()` with a more specific check. Props azaozz, sergeybiryukov, peterwilsoncc, spacedmonkey. Fixes #57487. git-svn-id: https://develop.svn.wordpress.org/trunk@56042 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
46
tests/phpunit/tests/load/wpGetDevelopmentMode.php
Normal file
46
tests/phpunit/tests/load/wpGetDevelopmentMode.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* Unit tests for `wp_get_development_mode()`.
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage UnitTests
|
||||
* @since 6.3.0
|
||||
*
|
||||
* @group load.php
|
||||
* @covers ::wp_get_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() );
|
||||
}
|
||||
}
|
||||
@@ -34,4 +34,29 @@ class Tests_Theme_wpGetGlobalStylesSvgFilters extends WP_UnitTestCase {
|
||||
$this->assertStringContainsString( '<svg', $svg_for_default_theme, 'Block theme should contain SVG' );
|
||||
$this->assertNotSame( $svg_for_default_theme, $svg_for_block_theme, 'Cache value should have changed' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the function relies on the development mode for whether to use caching.
|
||||
*
|
||||
* @ticket 57487
|
||||
*
|
||||
* @covers ::wp_get_global_styles_svg_filters
|
||||
*/
|
||||
public function test_caching_is_used_when_developing_theme() {
|
||||
global $_wp_tests_development_mode;
|
||||
|
||||
switch_theme( 'block-theme' );
|
||||
|
||||
// Store SVG in cache.
|
||||
$svg = '<svg></svg>';
|
||||
wp_cache_set( 'wp_get_global_styles_svg_filters', $svg, 'theme_json' );
|
||||
|
||||
// By default, caching should be used, so the above value will be returned.
|
||||
$_wp_tests_development_mode = '';
|
||||
$this->assertSame( $svg, wp_get_global_styles_svg_filters(), 'Caching was not used despite development mode disabled' );
|
||||
|
||||
// When the development mode is set to 'theme', caching should not be used.
|
||||
$_wp_tests_development_mode = 'theme';
|
||||
$this->assertNotSame( $svg, wp_get_global_styles_svg_filters(), 'Caching was used despite theme development mode' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,6 +220,29 @@ class Tests_Theme_WpGetGlobalStylesheet extends WP_Theme_UnitTestCase {
|
||||
$this->assertStringContainsString( $expected, $stylesheet_for_block_theme, 'Custom font size (100px) should be present for block theme' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the function relies on the development mode for whether to use caching.
|
||||
*
|
||||
* @ticket 57487
|
||||
*/
|
||||
public function test_caching_is_used_when_developing_theme() {
|
||||
global $_wp_tests_development_mode;
|
||||
|
||||
$this->maybe_switch_theme( 'block-theme' );
|
||||
|
||||
// Store CSS in cache.
|
||||
$css = '.my-class { display: block; }';
|
||||
wp_cache_set( 'wp_get_global_stylesheet', $css, 'theme_json' );
|
||||
|
||||
// By default, caching should be used, so the above value will be returned.
|
||||
$_wp_tests_development_mode = '';
|
||||
$this->assertSame( $css, wp_get_global_stylesheet(), 'Caching was not used despite development mode disabled' );
|
||||
|
||||
// When the development mode is set to 'theme', caching should not be used.
|
||||
$_wp_tests_development_mode = 'theme';
|
||||
$this->assertNotSame( $css, wp_get_global_stylesheet(), 'Caching was used despite theme development mode' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the 'editor-font-sizes' theme support with custom font sizes.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user