Skip to content

Commit 53b1482

Browse files
authored
Merge pull request #260 from wpengine/chore-phpunit-tests-previews-iteration-2
chore: Preview Unit Tests - Iteration 2
2 parents a6a9167 + 8d8e67f commit 53b1482

File tree

90 files changed

+3950
-1624
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+3950
-1624
lines changed

.github/actions/codeception/action.yml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,36 +67,6 @@ runs:
6767
WP_VERSION: ${{ inputs.wordpress }}
6868
PHP_VERSION: ${{ inputs.php }}
6969

70-
- name: Run Acceptance Tests w/ Docker
71-
working-directory: ${{ inputs.working-directory }}
72-
shell: bash
73-
run: |
74-
docker exec \
75-
--env DEBUG=${{ env.DEBUG }} \
76-
--env SKIP_TESTS_CLEANUP=${{ env.SKIP_TESTS_CLEANUP }} \
77-
--env SUITES=acceptance \
78-
$(docker compose ps -q wordpress) \
79-
bash -c "cd wp-content/plugins/$(basename $(echo ${{ inputs.working-directory }} | sed 's:/*$::')) && bin/run-codeception.sh"
80-
env:
81-
DEBUG: ${{ env.ACTIONS_STEP_DEBUG }}
82-
SKIP_TESTS_CLEANUP: "true"
83-
continue-on-error: true
84-
85-
- name: Run Functional Tests w/ Docker
86-
working-directory: ${{ inputs.working-directory }}
87-
shell: bash
88-
run: |
89-
docker exec \
90-
--env DEBUG=${{ env.DEBUG }} \
91-
--env SKIP_TESTS_CLEANUP=${{ env.SKIP_TESTS_CLEANUP }} \
92-
--env SUITES=functional \
93-
$(docker compose ps -q wordpress) \
94-
bash -c "cd wp-content/plugins/$(basename ${{ inputs.working-directory }}) && bin/run-codeception.sh"
95-
env:
96-
DEBUG: ${{ env.ACTIONS_STEP_DEBUG }}
97-
SKIP_TESTS_CLEANUP: "true"
98-
continue-on-error: true
99-
10070
- name: Run WPUnit Tests w/ Docker
10171
working-directory: ${{ inputs.working-directory }}
10272
shell: bash

.github/workflows/code-quality.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ jobs:
2626
plugin=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2)
2727
echo "slug=$plugin" >> $GITHUB_OUTPUT
2828
29+
# We should at least have a phpcs.xml file to run code quality checks
30+
- name: Validate phpcs.xml
31+
run: |
32+
if [ ! -f "plugins/${{ steps.plugin.outputs.slug }}/phpcs.xml" ]; then
33+
echo "Exiting as no phpcs.xml file found for /${{ steps.plugin.outputs.slug }}"
34+
exit 1
35+
fi
36+
2937
- name: PHP Code Quality
3038
uses: ./.github/actions/code-quality
3139
with:

.github/workflows/codeception.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Codeception
1+
name: Testing Integration
22

33
on:
44
push:
@@ -43,10 +43,18 @@ jobs:
4343
plugin=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2)
4444
echo "slug=$plugin" >> $GITHUB_OUTPUT
4545
46+
- name: Validate codeception.dist.yml
47+
run: |
48+
if [ ! -f "plugins/${{ steps.plugin.outputs.slug }}/codeception.dist.yml" ]; then
49+
echo "Exiting as no codeception file found for this plugin - /${{ steps.plugin.outputs.slug }}"
50+
exit 1
51+
fi
52+
4653
- name: Validate composer.json
4754
run: |
4855
if [ ! -f "plugins/${{ steps.plugin.outputs.slug }}/composer.json" ]; then
49-
echo "Warning: composer.json missing in plugins/${{ steps.plugin.outputs.slug }}"
56+
echo "Exiting as no composer file found for this plugin - ${{ steps.plugin.outputs.slug }}"
57+
exit 1
5058
fi
5159
5260
- name: Run Codeception Tests

.github/workflows/e2e-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Playwright End-to-End Tests
1+
name: End-to-End Tests
22

33
on:
44
push:

.github/workflows/plugin-artifact-for-pr.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
PLUGIN_SLUG: ${{ steps.plugin.outputs.slug }}
3131
with:
3232
slug: ${{ env.PLUGIN_SLUG }}
33+
composer-options: '--no-progress --optimize-autoloader --no-dev'
3334

3435
- name: Comment with artifact link
3536
uses: actions/github-script@v7

plugins/hwp-previews/ACTIONS_AND_FILTERS.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,33 @@
88

99
## PHP Filters
1010

11+
## Admin
12+
13+
- `hwp_previews_settings_init` - Allows a user to modify the `Settings` instance
14+
- `hwp_previews_settings_form_manager_init` - Allows a user to modify the `Settings_Form_Manager` instance and update fields and post types
15+
- `hwp_previews_settings_fields` - Allows a user to register, modify, or remove settings fields for the settings page
16+
- `hwp_previews_settings_group_option_key` - Filter to modify the settings group option key. Default is HWP_PREVIEWS_SETTINGS_KEY
17+
- `hwp_previews_settings_group_settings_group` - Filter to modify the settings group name. Default is HWP_PREVIEWS_SETTINGS_GROUP
18+
19+
20+
1121
- `hwp_previews_register_parameters` - Allows modification of the URL parameters used for previews for the class `Preview_Parameter_Registry`
1222
- `hwp_previews_template_path` - To use our own template for iframe previews
1323
- `hwp_previews_core` - Register or unregister URL parameters, and adjust types/statuses
1424
- `hwp_previews_filter_available_post_types` - Filter to modify the available post types for Previews.
15-
- `hwp_previews_settings_group_option_key` - Filter to modify the settings group option key. Default is HWP_PREVIEWS_SETTINGS_KEY
16-
- `hwp_previews_settings_group_settings_group` - Filter to modify the settings group name. Default is HWP_PREVIEWS_SETTINGS_GROUP
25+
- `hwp_previews_filter_available_post_statuses` - Filter for post statuses for previews for Previews
26+
- `hwp_previews_filter_available_parent_post_statuses` - Filter for parent post statuses for Previews
1727
- `hwp_previews_settings_group_settings_config` - Filter to modify the settings array. See `Settings_Group`
1828
- `hwp_previews_settings_group_cache_groups` - Filter to modify cache groups for `Settings_Group`
1929
- `hwp_previews_get_post_types_config` - Filter for generating the instance of `Post_Types_Config_Interface`
20-
- `hwp_previews_hooks_post_type_config` - Filter for post type config service for the Hook class
2130
- `hwp_previews_hooks_post_status_config` - Filter for post status config service for the Hook class
2231
- `hwp_previews_hooks_preview_link_service` - Filter for preview link service for the Hook class
23-
- `hwp_previews_hooks_post_statuses` - Filter for post statuses for previews for the Hook Class
24-
- `hwp_previews_settings_fields` - Allows a user to register, modify, or remove settings fields for the settings page
2532

2633
## Usage Examples
2734

35+
@TODO - Redo
36+
37+
2838
### Filter: Post Types List
2939

3040
Modify which post types appear in the settings UI:

plugins/hwp-previews/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# HWP Previews
22

3-
## 0.0.1
3+
## 0.0.1-beta
44

55
- Proof of concept.

plugins/hwp-previews/README.md

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
# HWP Previews
22

3-
**Headless Previews** solution for WordPress: fully configurable preview URLs via the settings page.
3+
**Headless Previews** solution for WordPress: fully configurable preview URLs via the settings page which is framework agnostic.
4+
5+
* [Join the Headless WordPress community on Discord.](https://discord.gg/headless-wordpress-836253505944813629)
6+
* [Documentation](#getting-started)
7+
8+
9+
-----
10+
11+
[![Version](https://img.shields.io/badge/version-0.0.1-beta)]()
12+
[![License](https://img.shields.io/badge/license-GPLv2%2B-green)]()
13+
![GitHub forks](https://img.shields.io/github/forks/wpengine/hwptoolkit?style=social)
14+
![GitHub stars](https://img.shields.io/github/stars/wpengine/hwptoolkit?style=social)
15+
[![Testing Integration](https://github.com/wpengine/hwptoolkit/workflows/Testing%20Integration/badge.svg)](https://github.com/wpengine/hwptoolkit/actions?query=workflow%3A%22Testing+Integration%22)
16+
[![Code Quality](https://github.com/wpengine/hwptoolkit/workflows/Code%20Quality/badge.svg)](https://github.com/wpengine/hwptoolkit/actions?query=workflow%3A%22Code+Quality%22)
17+
[![End-to-End Tests](https://github.com/wpengine/hwptoolkit/workflows/End-to-End%20Tests/badge.svg)](https://github.com/wpengine/hwptoolkit/actions?query=workflow%3A%22End-to-End+Tests%22)
18+
-----
19+
420

5-
[![Version](https://img.shields.io/badge/version-0.0.1-blue)]() [![License](https://img.shields.io/badge/license-GPLv2%2B-lightgrey)]()
621

722
> [!CAUTION]
8-
> This plugin is currently in an alpha state. It's still under active development, so you may encounter bugs or incomplete features. Updates will be rolled out regularly. Use with caution and provide feedback if possible.
23+
> This plugin is currently in an beta state. It's still under active development, so you may encounter bugs or incomplete features. Updates will be rolled out regularly. Use with caution and provide feedback if possible. You can create an issue at [https://github.com/wpengine/hwptoolkit/issues](https://github.com/wpengine/hwptoolkit/issues)
924
1025
---
1126

@@ -26,6 +41,11 @@ HWP Previews is a robust and extensible WordPress plugin that centralizes all pr
2641
It empowers site administrators and developers to tailor preview behaviors for each public post type independently, facilitating seamless headless or decoupled workflows.
2742
With HWP Previews, you can define dynamic URL templates, enforce unique slugs for drafts, allow all post statuses be used as parent and extend functionality through flexible hooks and filters, ensuring a consistent and conflict-free preview experience across diverse environments.
2843

44+
45+
46+
>[!IMPORTANT]
47+
> For Faust users, HWP Previews integrates seamlessly, automatically configuring settings to match Faust's preview system. This allows you to maintain your existing preview workflow without additional setup.
48+
2949
---
3050

3151
## Features
@@ -34,8 +54,8 @@ With HWP Previews, you can define dynamic URL templates, enforce unique slugs fo
3454
- **Custom URL Templates**: Define preview URLs using placeholder tokens for dynamic content.
3555
- **Parent Status**: Allow posts of **all** statuses to be used as parent within hierarchical post types.
3656
- **Highly Customizable**: Extend core behavior with a comprehensive set of actions and filters.
57+
- **Faust Compatibility**: The plugin is compatible with [Faust.js](https://faustjs.org/) and the [FaustWP plugin](https://github.com/wpengine/faustjs/tree/canary/plugins/faustwp).
3758

38-
---
3959

4060
## Getting Started
4161

@@ -49,6 +69,28 @@ This guide will help you set up your first headless preview link for the "Posts"
4969

5070
---
5171

72+
## Project Structure
73+
74+
```text
75+
hwp-previews/
76+
├── src/ # Main plugin source code
77+
│ ├── Admin/ # Admin settings, menu, and settings page logic
78+
│ ├── Hooks/ # WordPress hooks and filters
79+
│ ├── Integration/ # Integrations (e.g. Faust)
80+
│ ├── Preview/ # Preview URL logic, template resolver, helpers
81+
│ ├── Plugin.php # Main plugin class (entry point)
82+
│ └── Autoload.php # PSR-4 autoloader
83+
├── tests/ # All test suites
84+
│ ├── wpunit/ # WPBrowser/Codeception unit
85+
├── [hwp-previews.php]
86+
├── [activation.php]
87+
├── [composer.json]
88+
├── [deactivation.php]
89+
├── [ACTIONS_AND_FILTERS.md]
90+
├── [TESTING.md]
91+
├── [README.md]
92+
```
93+
5294
## Configuration
5395

5496
HWP Previews configuration located at **Settings > HWP Previews** page in your WP Admin. The settings are organized by post type.
@@ -114,11 +156,7 @@ This out-of-the-box configuration allows your existing preview workflow to conti
114156

115157
---
116158

117-
## Extending the Functionality
118-
119-
The plugin's behavior can be extended using its PHP hooks. Developers can control which post types are configurable in the settings via the `hwp_previews_filter_available_post_types` filter. The `hwp_previews_core` action allows for registering new URL parameters or unregistering default ones. Additionally, the `hwp_previews_template_path` filter can be used to replace the default preview iframe with a custom PHP template.
120-
121-
### Actions & Filters
159+
## Actions & Filters
122160

123161
See the [Actions & Filters documentation](ACTIONS_AND_FILTERS.md) for a comprehensive list of available hooks and how to use them.
124162

@@ -127,3 +165,28 @@ See the [Actions & Filters documentation](ACTIONS_AND_FILTERS.md) for a comprehe
127165
## Testing
128166

129167
See [Testing.md](TESTING.md) for details on how to test the plugin.
168+
169+
170+
## Screenshots
171+
172+
<details>
173+
<summary>Click to expand screenshots</summary>
174+
175+
![Custom Post Type Preview](./screenshots/settings_page.png)
176+
*Preview settings page.*
177+
178+
![Custom Post Type Preview](./screenshots/cpt_preview.png)
179+
*Preview settings for a custom post type.*
180+
181+
![Post Preview](./screenshots/post_preview.png)
182+
*Preview button in the WordPress editor.*
183+
184+
![Post Preview in Iframe](./screenshots/post_preview_iframe.png)
185+
*Preview loaded inside the WordPress editor using an iframe.*
186+
187+
![Preview Token](./screenshots/preview_token.png)
188+
*Preview token parameter for secure preview URLs.*
189+
190+
![App Password](./screenshots/app_password.png)
191+
*App password setup for authentication.*
192+
</details>

plugins/hwp-previews/TESTING.md

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The plugin provides scripts to set up a local WordPress environment for testing,
3333
1. **Copy and configure environment variables:**
3434

3535
```bash
36+
@TODO
3637
cp .env.dist .env
3738
# Edit .env as needed for your local setup
3839
```
@@ -54,44 +55,29 @@ The plugin provides scripts to set up a local WordPress environment for testing,
5455

5556
## Running Tests
5657

57-
### Unit Tests
58+
Currently the plugin has the following suite of tests
5859

59-
Run unit tests (no WordPress loaded):
60-
61-
```bash
62-
composer run test:unit
63-
# or
64-
vendor/bin/codecept run unit
65-
```
60+
1. WP Unit Tests - (Unit and Integration Tests)
61+
2. E2E Tests - Playright tests
6662

6763
### WPUnit (WordPress-aware Unit/Integration) Tests
6864

6965
Run WPUnit tests (WordPress loaded):
7066

7167
```bash
72-
composer run test:wpunit
73-
# or
74-
vendor/bin/codecept run wpunit
68+
sh bin/local/run-unit-tests.sh coverage
7569
```
7670

77-
### Functional Tests
71+
> [!IMPORTANT]
72+
> You can also add coverage e.g. `sh bin/local/run-unit-tests.sh coverage --coverage-html` and the output will be saved in [tests/_output/coverage/dashboard.html](tests/_output/coverage/dashboard.html)
7873
79-
Run functional tests (simulate web requests):
8074

81-
```bash
82-
composer run test:functional
83-
# or
84-
vendor/bin/codecept run functional
85-
```
86-
87-
### Acceptance Tests
75+
### E2WTests
8876

8977
Run browser-based acceptance tests:
9078

9179
```bash
92-
composer run test:acceptance
93-
# or
94-
vendor/bin/codecept run acceptance
80+
sh bin/local/run-e2e-tests.sh coverage
9581
```
9682

9783
### All Tests
@@ -142,13 +128,7 @@ tests/
142128
├── _envs/ # Environment configs
143129
├── _output/ # Test output (logs, coverage)
144130
├── _support/ # Helper classes, modules
145-
├── acceptance/ # Acceptance test cases
146-
├── functional/ # Functional test cases
147-
├── unit/ # Unit test cases
148131
├── wpunit/ # WPUnit (WordPress-aware unit/integration) test cases
149-
├── acceptance.suite.dist.yml
150-
├── functional.suite.dist.yml
151-
├── unit.suite.dist.yml
152132
├── wpunit.suite.dist.yml
153133
└── wpunit/
154134
└── bootstrap.php # Bootstrap for WPUnit tests

plugins/hwp-previews/activation.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Activation Hook
44
*
55
* @package HWP\Previews
6+
*
7+
* @since 0.0.1
68
*/
79

810
declare(strict_types=1);

0 commit comments

Comments
 (0)