- PHP 7.4 or higher
- Composer
- MySQL/MariaDB
composer installcomposer test-installThis command will install the WordPress testing environment.
composer testcomposer test -- --filter NotificationsTestcomposer test -- --filter HelpersFunctionsTestcomposer test -- --filter ErrorLogTestTo run tests with Xdebug enabled:
composer test-debug -- --filter NotificationsTestThe tests/Unit/test-notifications.php file contains complete tests for error notification functions.
Tests included:
- ✅ Function exists
- ✅ Uses custom email when configured
- ✅ Uses admin email by default
- ✅ Subject includes site name
- ✅ Body contains CRM name
- ✅ Body contains form information
- ✅ Body contains site information
- ✅ Body contains lead data
- ✅ Body contains technical details (URL and JSON)
Execution example:
composer test -- --filter test_email_uses_custom_email_when_configuredTests included:
- ✅ Function exists
- ✅ Returns false when no webhook is configured
- ✅ Sends notification when webhook is configured
- ✅ Includes site information
- ✅ Includes form information
- ✅ Includes CRM and error
- ✅ Includes lead data preview (first 3 fields)
- ✅ Includes API URL
- ✅ Uses "danger" color (red) for the message
- ✅ Shows "+N more" counter when there are more than 3 fields
Execution example:
composer test -- --filter test_slack_sends_when_webhook_configured- ✅ Verifies that both email and Slack are sent when both are configured
composer test -- --filter test_integration_both_email_and_slack_sentThe tests/Unit/test-error-log.php file contains 30+ complete tests for Error Log functionality.
📖 Complete documentation: See README-ERROR-LOG-TESTS.md
Database Operations (10 tests):
- ✅ Table creation
- ✅ Log insertion
- ✅ Single log retrieval
- ✅ Multiple logs retrieval
- ✅ Pagination (20 per page)
- ✅ Total count
- ✅ Status update
- ✅ Resend attempts increment
- ✅ Single log deletion
- ✅ Clear all logs
Filtering & Querying (6 tests):
- ✅ Filter by status (failed/success)
- ✅ Filter by CRM type
- ✅ Combined filters
- ✅ Pagination with filters
- ✅ Count with filters
- ✅ Order by date descending
Data Storage & Validation (8 tests):
- ✅ Lead data JSON encoding
- ✅ JSON request storage
- ✅ Form information storage
- ✅ Error date storage
- ✅ Default "failed" status
- ✅ API URL storage
- ✅ Empty data handling
- ✅ Database version tracking
Security & Sanitization (2 tests):
- ✅ CRM type sanitization (XSS prevention)
- ✅ Error message sanitization (XSS prevention)
Integration Tests (3 tests):
- ✅ Integration with
formscrm_alert_error() - ✅ Class existence verification
- ✅ Global variables initialization
Execution example:
# All Error Log tests
composer test -- --filter ErrorLogTest
# Specific test
composer test -- --filter ErrorLogTest::test_insert_log
# With debug
composer test-debug -- --filter ErrorLogTest| Feature | Tested |
|---|---|
| Custom email | ✅ |
| Default email | ✅ |
| Subject with site name | ✅ |
| Site information | ✅ |
| Form information | ✅ |
| Lead data | ✅ |
| Technical details | ✅ |
| Formatted HTML | ✅ |
| Feature | Tested |
|---|---|
| No webhook configured | ✅ |
| With webhook configured | ✅ |
| Site information | ✅ |
| Form information | ✅ |
| CRM and error | ✅ |
| Lead preview | ✅ |
| API URL | ✅ |
| Message color | ✅ |
| Compact format | ✅ |
tests/
├── Unit/
│ ├── test-helpers-functions.php # Helper function tests
│ ├── test-notifications.php # Notification tests
│ └── test-error-log.php # Error Log tests (NEW - 30+ tests)
├── API/
│ └── test-clientify.php # Clientify API tests
├── Forms/
│ └── test-contactform.php # Contact Form 7 tests
├── Data/
│ └── *.json # Test data
└── bootstrap.php # Test bootstrap
Tests use realistic but fictional data:
$data = array(
array( 'name' => 'Name', 'value' => 'John Doe' ),
array( 'name' => 'Email', 'value' => 'john@example.com' ),
array( 'name' => 'Phone', 'value' => '+34 600 123 456' ),
);$form_info = array(
'form_type' => 'Gravity Forms',
'form_id' => '42',
'form_name' => 'Contact Form',
'entry_id' => '12345',
);$webhook_url = 'https://hooks.slack.com/services/TEST/WEBHOOK/URL';composer test -- --filter NotificationsTest --debugTests capture emails using tests_retrieve_phpmailer_instance():
$mailer = tests_retrieve_phpmailer_instance();
echo $mailer->get_sent()->body; // View email contentTests capture HTTP requests:
add_filter(
'pre_http_request',
function( $pre, $r, $url ) use ( &$http_request ) {
$http_request = $r;
// Examine $http_request['body']
return array(...);
},
20,
3
);public function test_new_functionality() {
// Arrange - Prepare data.
$crm = 'Holded';
$error = 'Test error';
$data = array(
array( 'name' => 'Email', 'value' => 'test@example.com' ),
);
// Act - Execute function.
formscrm_alert_error( $crm, $error, $data );
// Assert - Verify result.
$mailer = tests_retrieve_phpmailer_instance();
$this->assertStringContainsString( 'expected', $mailer->get_sent()->body );
}Tests run automatically in GitHub Actions when pushing or creating pull requests.
See: .github/workflows/phpunit.yml
- All tests pass:
composer test - No linting errors:
composer lint - PHPStan is clean:
composer phpstan - New tests documented
- README updated if necessary
To add new tests:
- Create a new file in
tests/Unit/or add to an existing one - Follow naming convention:
test_clear_description - Use the AAA pattern (Arrange, Act, Assert)
- Clean up state after each test (
tearDown) - Run tests locally before committing
| Test Suite | Number of Tests | Status |
|---|---|---|
| Helpers Functions | 25+ | ✅ Passing |
| Notifications | 10+ | ✅ Passing |
| Error Log | 30+ | ✅ Passing |
| API Clientify | 5+ | ✅ Passing |
| Contact Form 7 | 3+ | ✅ Passing |
| TOTAL | 70+ | ✅ Passing |
Last Updated: January 22, 2025
Plugin Version: 4.3.0