You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Confirm that installation was successful by entering the `composer --version` command at the command line
159
+
160
+
### Clone Repository
161
+
162
+
Using your preferred Git client or command line, clone this repository into the `wp-content/plugins/` folder of your local WordPress installation.
163
+
164
+
If you prefer to clone the repository elsewhere, and them symlink it to your local WordPress installation, that will work as well.
165
+
166
+
If you're new to this, use [GitHub Desktop](https://desktop.github.com/) or [Tower](https://www.git-tower.com/mac)
167
+
168
+
For Plugins the cloned folder should be under `wp-content/plugins/` and for Themes under `wp-content/themes/`.
169
+
170
+
### Install Dependencies for PHP and JS
171
+
172
+
In the cloned repository's directory, at the command line, run `composer install`.
173
+
This will install the development dependencies. If you want to install just the production dependencies, run `composer install --no-dev`.
174
+
175
+
The development dependencies include:
176
+
- PHPStan
177
+
- PHPUnit
178
+
- PHP_CodeSniffer
179
+
- WordPress Coding Standards
180
+
- WordPress PHPUnit Polyfills
181
+
182
+
For the JS dependencies, run `npm install`.
183
+
To watch for changes in the JS files, run `npm run dev` if present or `npm run dist` to build a new version.
184
+
185
+
### PHP_CodeSniffer
186
+
187
+
To run PHP_CodeSniffer, run `composer lint`. This will run the WordPress Coding Standards checks.
188
+
To fix automatically fixable issues, run `composer format`.
189
+
190
+
### PHPUnit
191
+
192
+
To run PHPUnit, run `phpunit` or `./vendor/bin/phpunit` if it is not configured globally.
193
+
194
+
### E2E Tests
195
+
If the folder `e2e-tests` is present, you can run the E2E tests by following the instructions in the [E2E testing](./e2e-tests/README.md).
196
+
197
+
### Next Steps
198
+
199
+
With your development environment setup, you'll probably want to start development, which is covered bellow in the **Development Guide**.
200
+
201
+
202
+
203
+
# Development Guide
204
+
205
+
This document describes the high level workflow used when working on a WordPress Plugin or Theme.
206
+
207
+
You're free to use your preferred IDE and Git client. We recommend PHPStorm or Visual Studio Code, and GitHub CLI.
208
+
209
+
## Prerequisites
210
+
211
+
If you haven't yet set up your local development environment with a WordPress Plugin repository installed, refer to the [Setup Guide](#setup-guide).
212
+
213
+
his is for a new feature that does not have a GitHub Issue number, enter a short descriptive name for the branch, relative to what you're working on
214
+
- If this is for a feature/bug that has a GitHub Issue number, enter feat/issue_name or fix/issue_name, where issue_name is a descriptive name for the issue
215
+
216
+
Once done, make sure you've switched to your new branch, and begin making the necessary code additions/changes/deletions.
217
+
218
+
## Coding Standards
219
+
220
+
Code must follow [WordPress Coding standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/), which is checked
221
+
when running tests (more on this below).
222
+
223
+
## Security and Sanitization
224
+
225
+
When [outputting data](https://developer.wordpress.org/plugins/security/securing-output/), escape it using WordPress' escaping functions such as `esc_html()`, `esc_attr__()`, `wp_kses()`, `wp_kses_post()`.
226
+
227
+
When reading [user input](https://developer.wordpress.org/plugins/security/securing-input/), sanitize it using WordPress' sanitization functions such as `sanitize_text_field()`, `sanitize_textarea_field()`.
228
+
229
+
When writing to the database, prepare database queries using ``$wpdb->prepare()``
230
+
231
+
Never trust user input. Sanitize it.
232
+
233
+
Make use of [WordPress nonces](https://codex.wordpress.org/WordPress_Nonces) for saving form submitted data.
234
+
235
+
Coding standards will catch any sanitization, escaping or database queries that aren't prepared.
236
+
237
+
## Composer Packages
238
+
239
+
We use Composer for package management. A package can be added to one of two sections of the `composer.json` file: `require` or `require-dev`.
240
+
241
+
### "require"
242
+
243
+
Packages listed in the "require" directive are packages that the Plugin needs in order to function for end users.
244
+
245
+
These packages are included when the Plugin is deployed to WordPress.org
246
+
247
+
Typically, packages listed in this section would be libraries that the Plugin uses.
248
+
249
+
### "require-dev"
250
+
251
+
Packages listed in the "require-dev" directive are packages that the Plugin **does not** need in order to function for end users.
252
+
253
+
These packages are **not** included when the Plugin is deployed to wordpress.org
254
+
255
+
Typically, packages listed in this section would be internal development tools for testing, such as:
256
+
- Coding Standards
257
+
- PHPStan
258
+
- PHPUnit
259
+
260
+
## Committing Work
261
+
262
+
Remember to commit your changes to your branch relatively frequently, with a meaningful, short summary that explains what the change(s) do.
263
+
This helps anyone looking at the commit history in the future to find what they might be looking for.
264
+
265
+
If it's a particularly large commit, be sure to include more information in the commit description.
266
+
267
+
## Next Steps
268
+
269
+
Once you've finished your feature or issue, you must write/amend tests for it. Refer to the [Testing Guide](#testing-guide) for a detailed walkthrough
270
+
on how to write a test.
271
+
272
+
273
+
274
+
# Testing Guide
275
+
276
+
This document describes how to:
277
+
- create and run tests for your development work,
278
+
- ensure code meets PHP and WordPress Coding Standards, for best practices and security,
279
+
- ensure code passes static analysis, to catch potential errors that tests might miss
280
+
281
+
If you're new to creating and running tests, this guide will walk you through how to do this.
282
+
283
+
For those more experienced with creating and running tests, our tests are written in TS for [Playwright](https://playwright.dev/) used for End-to-End testing,
284
+
and in PHP for [PHPUnit](https://phpunit.de/).
285
+
286
+
A PHPUnit guide for WordPress can be found [here](https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/).
287
+
288
+
## Prerequisites
289
+
290
+
If you haven't yet set up your local development environment with this Plugin repository installed, refer to the [Setup Guide](#setup-guide).
291
+
292
+
If you haven't yet created a branch and made any code changes to the Plugin or Theme, refer to the [Development Guide](#development-guide)
293
+
294
+
## Write (or modify) a test
295
+
296
+
If your work creates new functionality, write a test.
297
+
298
+
If your work fixes existing functionality, check if a test exists. Either update that test, or create a new test if one doesn't exist.
299
+
300
+
Tests are written in TS using [Playwright](https://playwright.dev/) and PHP using [PHPUnit](https://phpunit.de/).
301
+
302
+
## Types of Test
303
+
304
+
There are different types of tests that can be written:
305
+
- Acceptance Tests: Test as a non-technical user in the web browser.
306
+
- Functional Tests: Test the framework (WordPress).
307
+
- Integration Tests: Test code modules in the context of a WordPress website.
308
+
- Unit Tests: Test single PHP classes or functions in isolation.
309
+
- WordPress Unit Tests: Test single PHP classes or functions in isolation, with WordPress functions and classes loaded.
310
+
311
+
There is no definitive / hard guide, as a test can typically overlap into different types (such as Acceptance and Functional).
312
+
313
+
The most important thing is that you have a test for *something*. If in doubt, an Acceptance Test will suffice.
314
+
315
+
### Writing an Acceptance Test
316
+
317
+
An acceptance test is a test that simulates a user interacting with the Plugin or Theme in a web browser.
318
+
Refer to Writing an End-to-End Test below.
319
+
320
+
### Writing an End-to-End Test
321
+
322
+
To write an End-to-End test, create a new file under `e2e-tests/specs` with the name of the spec or functionality you are testing, and add `.spec.test` to the file name.
323
+
324
+
E.g. for `e2e-tests/specs/checkout.spec.test.js`, the test file should be `checkout.spec.test.js`.
325
+
326
+
For more information on writing End-to-End tests, refer to the [Playwright documentation](https://playwright.dev/docs/test-intro).
327
+
328
+
You can check End-to-End [README](./e2e-tests/README.md) for more details.
329
+
330
+
## Writing a WordPress Unit Test
331
+
332
+
WordPress Unit tests provide testing of Plugin/Theme specific functions and/or classes, typically to assert that they perform as expected
333
+
by a developer. This is primarily useful for testing our API class, and confirming that any Plugin registered filters return
334
+
the correct data.
335
+
336
+
To create a new WordPress Unit Test, create a new file under `tests/php/unit` with the name of the class you are testing, and the suffix `Test`.
337
+
The filename should be in `lower-case-with-dash`, and the class name should be in `CamelCase`.
338
+
339
+
E.g. for `tests/php/unit/class-api-test.php`, the test class should be `class APITest extends \PHPUnit\Framework\TestCase`.
0 commit comments