Complete testing infrastructure for the Tour Operator WordPress plugin.
# Install dependencies
npm install
composer install
# Run all tests
npm test
# Run specific test suites
npm run test:php:all # PHPUnit (all tests)
npm run test:unit # Jest (JavaScript)
npm run test:e2e # Playwright (E2E)
npm run lint:yaml # YAML validationLocation: tests/php/
- TestRegistration.php - Verifies core WordPress component registration:
- Custom Post Types (tour, accommodation, destination)
- Taxonomies (travel-style, accommodation-type, etc.)
- Block Pattern categories and patterns
- Custom Fields bindings (lsx/post-connection, lsx/post-meta)
Run:
npm run test:php:all
npm run test:php:registrationLocation: tests/js/
- conditional-registration.test.js - Tests conditional block registration utilities:
createConditionalRegistration()function- Post type conditional registration
- Template slug matching
- Helper functions (registerForPostTypes, registerForTemplates)
Run:
npm run test:unit
npm run test:unit:watch # Watch mode
npm run test:unit:coverage # With coverageLocation: tests/e2e/
- plugin-activation.spec.js - Verifies plugin integration:
- Admin menu items visibility (Tours, Accommodations, Destinations)
- Submenu structure and links
- Post type creation workflows
- Block Editor integration
- Pattern availability
- Taxonomy management interfaces
- Plugin settings pages
Run:
npm run test:e2e
npm run test:e2e:ui # Interactive UI
npm run test:e2e:debug # Debug mode
npm run test:e2e:plugin # Specific testLocation: .github/workflows/
Validates:
- GitHub Actions workflow syntax
- YAML structure and formatting
- Best practices compliance
Run:
npm run lint:yaml
npm run lint:yaml:workflows # Workflows onlyPrerequisites:
- PHP 7.4+
- Composer
- MySQL/MariaDB
Installation:
# Install Composer dependencies
composer install
# Set up WordPress test environment
bash bin/install-wp-tests.sh wordpress_test root '' localhost latest
# Or set environment variables
export WP_TESTS_DIR=/tmp/wordpress-tests-lib
export WP_CORE_DIR=/tmp/wordpressConfiguration:
Create .env from .env.example:
cp .env.example .envEdit .env:
WP_TESTS_DIR=/tmp/wordpress-tests-lib
WP_CORE_DIR=/tmp/wordpress
DB_NAME=wordpress_test
DB_USER=root
DB_PASS=
DB_HOST=localhostPrerequisites:
- Node.js 18+
- npm
Installation:
npm installNo additional configuration needed - Jest uses WordPress preset from @wordpress/scripts.
Prerequisites:
- Node.js 18+
- WordPress test environment running
- Admin credentials
Installation:
# Install Playwright
npm install
# Install browser binaries
npx playwright installConfiguration:
Update .env with your WordPress environment:
WP_BASE_URL=http://localhost:8888
WP_ADMIN_USER=admin
WP_ADMIN_PASS=passwordOr set environment variables:
export WP_BASE_URL=http://localhost:8888
export WP_ADMIN_USER=admin
export WP_ADMIN_PASS=passwordPrerequisites:
- Python 3.x
- pip
Installation:
# macOS
brew install yamllint
# Linux (Ubuntu/Debian)
sudo apt-get install yamllint
# Using pip
pip install yamllintConfiguration:
YAML rules are in .yamllint - no additional setup needed.
npm test # PHPUnit + Jest + Playwright
npm run test:all # All PHPUnit tests + Jest + Playwrightnpm run test:php # Single test file
npm run test:php:all # All PHPUnit tests
npm run test:php:registration # Registration tests only
# Direct PHPUnit usage
./vendor/bin/phpunit
./vendor/bin/phpunit tests/php/TestRegistration.php
./vendor/bin/phpunit --filter test_post_types_registerednpm run test:unit # Run once
npm run test:unit:watch # Watch mode
npm run test:unit:coverage # With coverage report
# Run specific test file
npm run test:unit -- conditional-registration.test.jsnpm run test:e2e # Headless mode
npm run test:e2e:ui # Interactive UI
npm run test:e2e:debug # Debug mode (step through)
npm run test:e2e:plugin # Plugin activation tests only
# Direct Playwright usage
npx playwright test
npx playwright test tests/e2e/plugin-activation.spec.js
npx playwright test --headed # Show browsernpm run lint:yaml # All YAML files
npm run lint:yaml:workflows # GitHub workflows only
# Direct yamllint usage
yamllint .
yamllint .github/workflows/
yamllint .github/workflows/ci.ymlnpm run lint:all # PHP, JS, CSS, JSON, YAMLAutomated testing runs on:
- Push to
develop,main,2.*-trunk - Pull requests
- Manual workflow dispatch
Workflows:
-
ci.yml - Main CI pipeline
- PHPUnit tests
- Jest unit tests
- Code linting (PHP, JS, CSS)
-
yaml-lint.yml - YAML validation
- GitHub Actions workflows
- Configuration files
-
push-deploy.yml - Deployment (post-merge)
Run the same checks as CI:
# All linting
npm run lint:all
# All tests
npm run test:all<?php
/**
* Test Description
*
* @package Tour_Operator
* @subpackage Tests
*/
class TestMyFeature extends Tour_Operator_Test_Case {
public function test_feature_works() {
$tour_id = $this->create_tour([
'post_title' => 'Test Tour',
]);
$this->assertPostExists($tour_id, 'tour', 'publish');
}
}import { myFunction } from '../../src/js/my-module';
describe('My Module', () => {
it('should do something', () => {
const result = myFunction();
expect(result).toBe(true);
});
});import { test, expect } from '@wordpress/e2e-test-utils-playwright';
test.describe('My Feature', () => {
test('should work correctly', async ({ admin, page }) => {
await admin.visitAdminPage('/');
const element = page.locator('#my-element');
await expect(element).toBeVisible();
});
});WordPress test library not found:
export WP_TESTS_DIR=/tmp/wordpress-tests-lib
bash bin/install-wp-tests.sh wordpress_test root '' localhost latestDatabase errors:
- Verify MySQL is running
- Check database credentials in
.env - Ensure test database exists
Module not found:
npm run test:unit -- --clearCache
rm -rf node_modules package-lock.json
npm installBrowsers not installed:
npx playwright installWordPress not accessible:
- Verify WordPress is running at
WP_BASE_URL - Check admin credentials in
.env - Test manually at
http://localhost:8888/wp-admin
yamllint not found:
pip install yamllint
# or
brew install yamllint- Complete Testing Guide - Detailed documentation
- Playwright Testing Guide - E2E testing
- Test Spec Templates - Test templates
- Testing Guide - General testing practices
- PHPUnit Documentation
- Jest Documentation
- Playwright Documentation
- WordPress Testing Handbook
- yamllint Documentation
When adding new features:
- ✅ Write tests first (TDD)
- ✅ Ensure all tests pass locally
- ✅ Run linting (
npm run lint:all) - ✅ Submit PR with test coverage
Questions? See docs/testing-complete.md for comprehensive documentation.