Testing a Patch

Alert: This page is under construction and may contain inaccurate information. Want to help fix it? Ping the #docs channel in WordPress Slack.

Testing patches is an important part of ensuring the quality of WordPress releases.

Setting up without VVV Setting up without VVV

If you use VVV, skip to the section below.

Grunt is a command runner that allows you to test patches that have been uploaded to Trac. To use Grunt, follow these steps:

  1. Install nodejs and npm to your development environment.
  2. Clone the develop WordPress repository located at https://develop.svn.wordpress.org/
  3. Run npm install to get all the dependencies.
  4. Run npm run grunt build to get the fully-built version
  5. Setup your server to use /build as the root (varies depending on how your development environment is setup).
  6. In order for changes to /src to be reflected in /build, run npm run grunt watch while you are working.
  7. Alternatively, you can use /src as your document root, which may be much more convenient for PHP-focused development. You’ll need to run npm run grunt build -- --dev once, but after that you don’t need npm run grunt watch at all, unless you’re changing JavaScript/CSS. If you are, then use npm run grunt watch -- --dev instead of npm run grunt watch.

Top ↑

Setting up with VVV Setting up with VVV

VVV include support for WP Core Development and you can find the settings on the config.yml file.

Using this integration you can have 2 ways to download the WP trunk version, svn or git. The first version is the official used but require knowledge of this VCS system and ca be difficult for the new comers compared to git.
WP offers a git mirror (also on GitHub) and is possible to choose what system VVV will use.

For the purpose of this guide we will use git because there is specific documentation in this handbook and is more simple, including the GitHub integration that now Trac offers.

After adding this settings and doing the provisioning of VVV yiou should have a new folder (`wordpress-trunk is the default name in the config and we will refer to that to the rest of the guide) inside VVV/www/.

VVV as explained above use 2 different folders `src that is from the vcs system but instead in VVV and other system is used another folder where everything is used by the web server that is build, generate on the fly when Grunt is executed the first time.

Grunt will copy the src folder to the build one, and will start a watcher that will copy any changes that you during the development will do on the folders. So the right way is editing the file in src folder with `npm run grunt watch executed to copy (and compile any js/css assets automatically).

This command is better to executing inside the Host machine and not the VM for performance reasons and avoid issues with the shared file system.

Now you have 2 ways to test a patch: using Grunt to download/apply a patch from Trac (or doing manually) or download from GitHub.

Top ↑

Testing with Grunt Testing with Grunt

Now that Grunt is setup, type in npm run grunt patch:####, replacing #### with either a ticket number from Trac or a patch URL. This will download the patch and apply the changes to your development environment.

Note: If you receive a Cannot find module 'grunt-cli/bin/grunt' error, run the following and then try again:

rm -rf node_modules && npm install

Ready to test your environment? Use npm run grunt test to automatically run automated tests. Note that this step requires PHPUnit to be installed.

If you’re a committer, be sure to run npm run grunt precommit before committing code, especially code that touches anything on the front-end (CSS/JS).

Top ↑

Testing without Grunt Testing without Grunt

[This section needs to be renamed and filled with glorious content.]

See https://make.wordpress.org/core/handbook/tutorials/working-with-patches/#applying-a-patch-with-the-command-line