Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e3f0941
Added more Admin unit tests. Removed some unusued classes.
colinmurphy Jun 13, 2025
9daaa46
Merge branch 'main' into chore-phpunit-tests-previews-iteration-2
colinmurphy Jun 16, 2025
6d32947
Working on refactoring plugin. Adding settings tests. Moving template…
colinmurphy Jun 16, 2025
b420c0f
Refactor of Template Resolver and added test.
colinmurphy Jun 16, 2025
2de7fb1
Code Quality fix.
colinmurphy Jun 16, 2025
f5c5966
Refactoring. Add some new services to consolidate some of the existin…
colinmurphy Jun 17, 2025
6cef674
Added checks for codeception and phpcs to run tests or code quality
colinmurphy Jun 17, 2025
030de0a
Refactoring URL resolver functionality.
colinmurphy Jun 17, 2025
c7b6206
Refactored post parent functionality. Added constants for default fie…
colinmurphy Jun 18, 2025
595af07
Fixed linting issues.
colinmurphy Jun 18, 2025
0f3b0bf
Refactored checking if classic editor is available. Added tests.
colinmurphy Jun 18, 2025
ac730e0
Merge branch 'main' into chore-phpunit-tests-previews-iteration-2
colinmurphy Jun 18, 2025
c4c9270
Removed some unused classes already refactored. Updated Faust Integra…
colinmurphy Jun 18, 2025
d86ad04
Updated package.
colinmurphy Jun 18, 2025
baaf821
Fixed issues after refactoring Faust Integration. e2e and code qualit…
colinmurphy Jun 18, 2025
bf2ead5
Set plugin version as 0.0.1-beta for #257 process
colinmurphy Jun 18, 2025
7efff6e
Added tests for activation and de-activation.
colinmurphy Jun 18, 2025
360ae41
Added more tests for the plugin main classes.
colinmurphy Jun 19, 2025
0476f83
Added tests for Preview Parameters.
colinmurphy Jun 19, 2025
f87491a
Added Tests for Preview URL Resolver. A lot of critical tests for UR…
colinmurphy Jun 19, 2025
c28f757
Added WP_Mock so we could test Faust with Preview. Refactored Faust t…
colinmurphy Jun 19, 2025
5c3d266
Fixed issues with tests.
colinmurphy Jun 19, 2025
f279727
Fixed issue with Faust Integration. Had accidentally imported the fun…
colinmurphy Jun 19, 2025
7371944
Added tests for Preview hooks.
colinmurphy Jun 23, 2025
dd47988
PHPCS fixes.
colinmurphy Jun 23, 2025
e0ab68b
Added tests for the Settings_Page class. Slight refactor to help with…
colinmurphy Jun 24, 2025
eb604fa
Fixed TODOs. Added tests for Settings form manager for sanitizing fie…
colinmurphy Jun 24, 2025
973b45a
Added missing tests.
colinmurphy Jun 24, 2025
31501f8
Small fixes for the artifact not to include dev dependencies.
colinmurphy Jun 24, 2025
06dc013
test: e2e test for URL param validation
ahuseyn Jun 24, 2025
2916d1f
Reviewing admin functionality. Tidy up of docs etc.
colinmurphy Jun 24, 2025
6898425
Merge branch 'chore-phpunit-tests-previews-iteration-2' of github.com…
colinmurphy Jun 24, 2025
eb5b831
Adding missing doc blocks.
colinmurphy Jun 24, 2025
5ae239e
Fixed PHPCS issues and Licence.
colinmurphy Jun 24, 2025
44136c5
Updating README. Updating the wording of some actions for the badges …
colinmurphy Jun 24, 2025
0f9984f
Merge branch 'main' into chore-phpunit-tests-previews-iteration-2
colinmurphy Jun 24, 2025
5823a8d
Minor update to force changeset bot.
colinmurphy Jun 24, 2025
abb77f7
fix: replace "Extending functionality" link with "Actions and filters"
ahuseyn Jun 25, 2025
8d8e67f
Update plugins/hwp-previews/README.md
ahuseyn Jun 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .github/actions/codeception/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,6 @@ runs:
WP_VERSION: ${{ inputs.wordpress }}
PHP_VERSION: ${{ inputs.php }}

- name: Run Acceptance Tests w/ Docker
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
docker exec \
--env DEBUG=${{ env.DEBUG }} \
--env SKIP_TESTS_CLEANUP=${{ env.SKIP_TESTS_CLEANUP }} \
--env SUITES=acceptance \
$(docker compose ps -q wordpress) \
bash -c "cd wp-content/plugins/$(basename $(echo ${{ inputs.working-directory }} | sed 's:/*$::')) && bin/run-codeception.sh"
env:
DEBUG: ${{ env.ACTIONS_STEP_DEBUG }}
SKIP_TESTS_CLEANUP: "true"
continue-on-error: true

- name: Run Functional Tests w/ Docker
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
docker exec \
--env DEBUG=${{ env.DEBUG }} \
--env SKIP_TESTS_CLEANUP=${{ env.SKIP_TESTS_CLEANUP }} \
--env SUITES=functional \
$(docker compose ps -q wordpress) \
bash -c "cd wp-content/plugins/$(basename ${{ inputs.working-directory }}) && bin/run-codeception.sh"
env:
DEBUG: ${{ env.ACTIONS_STEP_DEBUG }}
SKIP_TESTS_CLEANUP: "true"
continue-on-error: true

- name: Run WPUnit Tests w/ Docker
working-directory: ${{ inputs.working-directory }}
shell: bash
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ jobs:
plugin=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2)
echo "slug=$plugin" >> $GITHUB_OUTPUT

# We should at least have a phpcs.xml file to run code quality checks
- name: Validate phpcs.xml
run: |
if [ ! -f "plugins/${{ steps.plugin.outputs.slug }}/phpcs.xml" ]; then
echo "Exiting as no phpcs.xml file found for /${{ steps.plugin.outputs.slug }}"
exit 1
fi

- name: PHP Code Quality
uses: ./.github/actions/code-quality
with:
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/codeception.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Codeception
name: Testing Integration

on:
push:
Expand Down Expand Up @@ -43,10 +43,18 @@ jobs:
plugin=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2)
echo "slug=$plugin" >> $GITHUB_OUTPUT

- name: Validate codeception.dist.yml
run: |
if [ ! -f "plugins/${{ steps.plugin.outputs.slug }}/codeception.dist.yml" ]; then
echo "Exiting as no codeception file found for this plugin - /${{ steps.plugin.outputs.slug }}"
exit 1
fi

- name: Validate composer.json
run: |
if [ ! -f "plugins/${{ steps.plugin.outputs.slug }}/composer.json" ]; then
echo "Warning: composer.json missing in plugins/${{ steps.plugin.outputs.slug }}"
echo "Exiting as no composer file found for this plugin - ${{ steps.plugin.outputs.slug }}"
exit 1
fi

- name: Run Codeception Tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Playwright End-to-End Tests
name: End-to-End Tests

on:
push:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/plugin-artifact-for-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
PLUGIN_SLUG: ${{ steps.plugin.outputs.slug }}
with:
slug: ${{ env.PLUGIN_SLUG }}
composer-options: '--no-progress --optimize-autoloader --no-dev'

- name: Comment with artifact link
uses: actions/github-script@v7
Expand Down
20 changes: 15 additions & 5 deletions plugins/hwp-previews/ACTIONS_AND_FILTERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,33 @@

## PHP Filters

## Admin

- `hwp_previews_settings_init` - Allows a user to modify the `Settings` instance
- `hwp_previews_settings_form_manager_init` - Allows a user to modify the `Settings_Form_Manager` instance and update fields and post types
- `hwp_previews_settings_fields` - Allows a user to register, modify, or remove settings fields for the settings page
- `hwp_previews_settings_group_option_key` - Filter to modify the settings group option key. Default is HWP_PREVIEWS_SETTINGS_KEY
- `hwp_previews_settings_group_settings_group` - Filter to modify the settings group name. Default is HWP_PREVIEWS_SETTINGS_GROUP



- `hwp_previews_register_parameters` - Allows modification of the URL parameters used for previews for the class `Preview_Parameter_Registry`
- `hwp_previews_template_path` - To use our own template for iframe previews
- `hwp_previews_core` - Register or unregister URL parameters, and adjust types/statuses
- `hwp_previews_filter_available_post_types` - Filter to modify the available post types for Previews.
- `hwp_previews_settings_group_option_key` - Filter to modify the settings group option key. Default is HWP_PREVIEWS_SETTINGS_KEY
- `hwp_previews_settings_group_settings_group` - Filter to modify the settings group name. Default is HWP_PREVIEWS_SETTINGS_GROUP
- `hwp_previews_filter_available_post_statuses` - Filter for post statuses for previews for Previews
- `hwp_previews_filter_available_parent_post_statuses` - Filter for parent post statuses for Previews
- `hwp_previews_settings_group_settings_config` - Filter to modify the settings array. See `Settings_Group`
- `hwp_previews_settings_group_cache_groups` - Filter to modify cache groups for `Settings_Group`
- `hwp_previews_get_post_types_config` - Filter for generating the instance of `Post_Types_Config_Interface`
- `hwp_previews_hooks_post_type_config` - Filter for post type config service for the Hook class
- `hwp_previews_hooks_post_status_config` - Filter for post status config service for the Hook class
- `hwp_previews_hooks_preview_link_service` - Filter for preview link service for the Hook class
- `hwp_previews_hooks_post_statuses` - Filter for post statuses for previews for the Hook Class
- `hwp_previews_settings_fields` - Allows a user to register, modify, or remove settings fields for the settings page

## Usage Examples

@TODO - Redo


### Filter: Post Types List

Modify which post types appear in the settings UI:
Expand Down
2 changes: 1 addition & 1 deletion plugins/hwp-previews/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# HWP Previews

## 0.0.1
## 0.0.1-beta

- Proof of concept.
81 changes: 72 additions & 9 deletions plugins/hwp-previews/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
# HWP Previews

**Headless Previews** solution for WordPress: fully configurable preview URLs via the settings page.
**Headless Previews** solution for WordPress: fully configurable preview URLs via the settings page which is framework agnostic.

* [Join the Headless WordPress community on Discord.](https://discord.gg/headless-wordpress-836253505944813629)
* [Documentation](#getting-started)


-----

[![Version](https://img.shields.io/badge/version-0.0.1-beta)]()
[![License](https://img.shields.io/badge/license-GPLv2%2B-green)]()
![GitHub forks](https://img.shields.io/github/forks/wpengine/hwptoolkit?style=social)
![GitHub stars](https://img.shields.io/github/stars/wpengine/hwptoolkit?style=social)
[![Testing Integration](https://github.com/wpengine/hwptoolkit/workflows/Testing%20Integration/badge.svg)](https://github.com/wpengine/hwptoolkit/actions?query=workflow%3A%22Testing+Integration%22)
[![Code Quality](https://github.com/wpengine/hwptoolkit/workflows/Code%20Quality/badge.svg)](https://github.com/wpengine/hwptoolkit/actions?query=workflow%3A%22Code+Quality%22)
[![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)
-----


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

> [!CAUTION]
> 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.
> 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)

---

Expand All @@ -26,6 +41,11 @@ HWP Previews is a robust and extensible WordPress plugin that centralizes all pr
It empowers site administrators and developers to tailor preview behaviors for each public post type independently, facilitating seamless headless or decoupled workflows.
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.



>[!IMPORTANT]
> 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.

---

## Features
Expand All @@ -34,8 +54,8 @@ With HWP Previews, you can define dynamic URL templates, enforce unique slugs fo
- **Custom URL Templates**: Define preview URLs using placeholder tokens for dynamic content.
- **Parent Status**: Allow posts of **all** statuses to be used as parent within hierarchical post types.
- **Highly Customizable**: Extend core behavior with a comprehensive set of actions and filters.
- **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).

---

## Getting Started

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

---

## Project Structure

```text
hwp-previews/
├── src/ # Main plugin source code
│ ├── Admin/ # Admin settings, menu, and settings page logic
│ ├── Hooks/ # WordPress hooks and filters
│ ├── Integration/ # Integrations (e.g. Faust)
│ ├── Preview/ # Preview URL logic, template resolver, helpers
│ ├── Plugin.php # Main plugin class (entry point)
│ └── Autoload.php # PSR-4 autoloader
├── tests/ # All test suites
│ ├── wpunit/ # WPBrowser/Codeception unit
├── [hwp-previews.php]
├── [activation.php]
├── [composer.json]
├── [deactivation.php]
├── [ACTIONS_AND_FILTERS.md]
├── [TESTING.md]
├── [README.md]
```

## Configuration

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

---

## Extending the Functionality

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.

### Actions & Filters
## Actions & Filters

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

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

See [Testing.md](TESTING.md) for details on how to test the plugin.


## Screenshots

<details>
<summary>Click to expand screenshots</summary>

![Custom Post Type Preview](./screenshots/settings_page.png)
*Preview settings page.*

![Custom Post Type Preview](./screenshots/cpt_preview.png)
*Preview settings for a custom post type.*

![Post Preview](./screenshots/post_preview.png)
*Preview button in the WordPress editor.*

![Post Preview in Iframe](./screenshots/post_preview_iframe.png)
*Preview loaded inside the WordPress editor using an iframe.*

![Preview Token](./screenshots/preview_token.png)
*Preview token parameter for secure preview URLs.*

![App Password](./screenshots/app_password.png)
*App password setup for authentication.*
</details>
38 changes: 9 additions & 29 deletions plugins/hwp-previews/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The plugin provides scripts to set up a local WordPress environment for testing,
1. **Copy and configure environment variables:**

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

## Running Tests

### Unit Tests
Currently the plugin has the following suite of tests

Run unit tests (no WordPress loaded):

```bash
composer run test:unit
# or
vendor/bin/codecept run unit
```
1. WP Unit Tests - (Unit and Integration Tests)
2. E2E Tests - Playright tests

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

Run WPUnit tests (WordPress loaded):

```bash
composer run test:wpunit
# or
vendor/bin/codecept run wpunit
sh bin/local/run-unit-tests.sh coverage
```

### Functional Tests
> [!IMPORTANT]
> 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)

Run functional tests (simulate web requests):

```bash
composer run test:functional
# or
vendor/bin/codecept run functional
```

### Acceptance Tests
### E2WTests

Run browser-based acceptance tests:

```bash
composer run test:acceptance
# or
vendor/bin/codecept run acceptance
sh bin/local/run-e2e-tests.sh coverage
```

### All Tests
Expand Down Expand Up @@ -142,13 +128,7 @@ tests/
├── _envs/ # Environment configs
├── _output/ # Test output (logs, coverage)
├── _support/ # Helper classes, modules
├── acceptance/ # Acceptance test cases
├── functional/ # Functional test cases
├── unit/ # Unit test cases
├── wpunit/ # WPUnit (WordPress-aware unit/integration) test cases
├── acceptance.suite.dist.yml
├── functional.suite.dist.yml
├── unit.suite.dist.yml
├── wpunit.suite.dist.yml
└── wpunit/
└── bootstrap.php # Bootstrap for WPUnit tests
Expand Down
2 changes: 2 additions & 0 deletions plugins/hwp-previews/activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Activation Hook
*
* @package HWP\Previews
*
* @since 0.0.1
*/

declare(strict_types=1);
Expand Down
23 changes: 23 additions & 0 deletions plugins/hwp-previews/bin/local/run-e2e-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# Run Playwright E2E tests for GitHub Actions

set -e

# Install dependencies if needed
npm ci

# Install composer dependencies
composer install

# Install Playwright browsers
npx playwright install --with-deps

# Start wp-env
npm run wp-env start

# Run Playwright tests
npm run test:e2e

# Stop wp-env
npm run wp-env stop
6 changes: 4 additions & 2 deletions plugins/hwp-previews/codeception.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ extensions:
- lucatume\WPBrowser\Command\MonkeyCachePath
- lucatume\WPBrowser\Command\RunAll
- lucatume\WPBrowser\Command\RunOriginal
exclude:
- src/Templates
- src/Templates/*
coverage:
enabled: true
remote: false
c3_url: "%WORDPRESS_URL%/wp-content/plugins/hwp-previews/hwp-previews.php"
include:
- src/*
- /access-functions.php
- /activation.php
- /deactivation.php
exclude:
Expand All @@ -46,8 +48,8 @@ coverage:
- /node_modules/*
- /packages/*
- /tests/*
- /vendor-prefixed/*
- /vendor/*
- /src/Templates/*
show_only_summary: false
modules:
config:
Expand Down
Loading
Loading