mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
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
61 lines
2.8 KiB
JavaScript
61 lines
2.8 KiB
JavaScript
const dotenv = require( 'dotenv' );
|
|
const dotenvExpand = require( 'dotenv-expand' );
|
|
const wait_on = require( 'wait-on' );
|
|
const { execSync } = require( 'child_process' );
|
|
const { renameSync, readFileSync, writeFileSync } = require( 'fs' );
|
|
|
|
dotenvExpand.expand( dotenv.config() );
|
|
|
|
// Create wp-config.php.
|
|
wp_cli( 'config create --dbname=wordpress_develop --dbuser=root --dbpass=password --dbhost=mysql --path=/var/www/src --force' );
|
|
|
|
// Add the debug settings to wp-config.php.
|
|
// Windows requires this to be done as an additional step, rather than using the --extra-php option in the previous step.
|
|
wp_cli( `config set WP_DEBUG ${process.env.LOCAL_WP_DEBUG} --raw --type=constant` );
|
|
wp_cli( `config set WP_DEBUG_LOG ${process.env.LOCAL_WP_DEBUG_LOG} --raw --type=constant` );
|
|
wp_cli( `config set WP_DEBUG_DISPLAY ${process.env.LOCAL_WP_DEBUG_DISPLAY} --raw --type=constant` );
|
|
wp_cli( `config set SCRIPT_DEBUG ${process.env.LOCAL_SCRIPT_DEBUG} --raw --type=constant` );
|
|
wp_cli( `config set WP_ENVIRONMENT_TYPE ${process.env.LOCAL_WP_ENVIRONMENT_TYPE} --type=constant` );
|
|
wp_cli( `config set WP_DEVELOPMENT_MODE ${process.env.LOCAL_WP_DEVELOPMENT_MODE} --type=constant` );
|
|
|
|
// Move wp-config.php to the base directory, so it doesn't get mixed up in the src or build directories.
|
|
renameSync( 'src/wp-config.php', 'wp-config.php' );
|
|
|
|
install_wp_importer();
|
|
|
|
// Read in wp-tests-config-sample.php, edit it to work with our config, then write it to wp-tests-config.php.
|
|
const testConfig = readFileSync( 'wp-tests-config-sample.php', 'utf8' )
|
|
.replace( 'youremptytestdbnamehere', 'wordpress_develop_tests' )
|
|
.replace( 'yourusernamehere', 'root' )
|
|
.replace( 'yourpasswordhere', 'password' )
|
|
.replace( 'localhost', 'mysql' )
|
|
.concat( "\ndefine( 'FS_METHOD', 'direct' );\n" );
|
|
|
|
writeFileSync( 'wp-tests-config.php', testConfig );
|
|
|
|
// Once the site is available, install WordPress!
|
|
wait_on( { resources: [ `tcp:localhost:${process.env.LOCAL_PORT}`] } )
|
|
.then( () => {
|
|
wp_cli( 'db reset --yes' );
|
|
wp_cli( `core install --title="WordPress Develop" --admin_user=admin --admin_password=password --admin_email=test@test.com --skip-email --url=http://localhost:${process.env.LOCAL_PORT}` );
|
|
} );
|
|
|
|
/**
|
|
* Runs WP-CLI commands in the Docker environment.
|
|
*
|
|
* @param {string} cmd The WP-CLI command to run.
|
|
*/
|
|
function wp_cli( cmd ) {
|
|
execSync( `docker-compose run --rm cli ${cmd}`, { stdio: 'inherit' } );
|
|
}
|
|
|
|
/**
|
|
* Downloads the WordPress Importer plugin for use in tests.
|
|
*/
|
|
function install_wp_importer() {
|
|
const testPluginDirectory = 'tests/phpunit/data/plugins/wordpress-importer';
|
|
|
|
execSync( `docker-compose exec -T php rm -rf ${testPluginDirectory}`, { stdio: 'inherit' } );
|
|
execSync( `docker-compose exec -T php git clone https://github.com/WordPress/wordpress-importer.git ${testPluginDirectory} --depth=1`, { stdio: 'inherit' } );
|
|
}
|