Strategies for testing Form Forge forms in automated environments.
Playwright E2E Tests
javascript
// tests/form-forge-contact.spec.js
const { test, expect } = require( '@playwright/test' );
test( 'contact form submits successfully', async ( { page } ) => {
await page.goto( 'http://localhost:8888/contact/' );
// Fill in form fields
await page.fill( '#formforge_field_field_1', 'Test User' );
await page.fill( '#formforge_field_field_2', '[email protected]' );
await page.fill( '#formforge_field_field_3', 'This is a test message.' );
// Submit
await page.click( '.formforge-submit-btn' );
// Wait for success message
await expect( page.locator( '.formforge-message' ) ).toBeVisible();
await expect( page.locator( '.formforge-message' ) ).toContainText( 'Thank you' );
} );PHP Unit Tests for Custom Hooks
php
class FormForge_Custom_Hook_Test extends WP_UnitTestCase {
public function test_utm_tracking_hook_adds_fields() {
$_POST['utm_source'] = 'google';
$_POST['utm_campaign'] = 'spring2025';
$data = [
'field_1' => [ 'label' => 'Name', 'value' => 'Test', 'type' => 'text' ],
];
// Simulate the hook
do_action( 'formforge_before_submit', 1, $data, new stdClass() );
$this->assertArrayHasKey( 'custom_source', $data );
$this->assertEquals( 'google', $data['custom_source']['value'] );
}
}Testing Webhooks with WP-CLI
bash
#Trigger a test submission and check webhook delivery
wp eval '
$handler = FORMFORGE_Form_Handler::instance();
$result = $handler->process_submission( 42, [
"field_1" => "CLI Test",
"field_2" => "[email protected]",
] );
var_dump( $result );
'Checking Submission Counts via WP-CLI
bash
wp db query "SELECT form_id, COUNT(*) as total FROM wp_formforge_submissions GROUP BY form_id"—