- Refactored fallback submission logic in `class-event-handler.php` to remove `wp_die`/`exit` calls and use redirects for error handling, enabling proper unit testing. - Implemented meta-data saving (dates, venue, organizer) in the fallback logic using `update_post_meta`. - Updated unit tests (`test-event-management.php`) to remove `markTestIncomplete` calls related to handler errors and uncommented meta assertions. Unit tests for fallback logic now pass. - Added Instructions section and Return to Dashboard button to the event form shortcode (`display_event_form_shortcode`). - Applied basic theme styling classes (`ast-container`, `notice`, `ast-button`) to the event form. - Updated `docs/implementation_plan.md` to reflect completion of tasks 4.1-4.5 and set focus to Task 5. Refs: Task 4.1, 4.2, 4.3, 4.4, 4.5
122 lines
No EOL
4.8 KiB
PHP
122 lines
No EOL
4.8 KiB
PHP
<?php
|
|
/**
|
|
* Unit tests for HVAC registration form validation
|
|
*/
|
|
|
|
class RegistrationValidationTest extends WP_UnitTestCase {
|
|
|
|
private $registration;
|
|
|
|
public function setUp(): void { // Added :void return type hint
|
|
parent::setUp();
|
|
require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-registration.php';
|
|
$this->registration = new HVAC_Registration();
|
|
}
|
|
|
|
public function test_required_fields_validation() {
|
|
$data = [
|
|
'first_name' => '',
|
|
'last_name' => '',
|
|
'business_name' => '',
|
|
'business_phone' => '',
|
|
'business_email' => '',
|
|
'user_country' => '',
|
|
'user_state' => '',
|
|
'user_city' => '',
|
|
'user_zip' => '',
|
|
'business_type' => '',
|
|
'user_pass' => 'ValidPass1'
|
|
];
|
|
|
|
$errors = $this->registration->validate_registration($data);
|
|
|
|
$required_fields = [
|
|
'first_name', 'last_name', 'business_name',
|
|
'business_phone', 'business_email', 'user_country',
|
|
'user_state', 'user_city', 'user_zip', 'business_type'
|
|
];
|
|
|
|
|
|
foreach ($required_fields as $field) {
|
|
$this->assertArrayHasKey($field, $errors, "Error missing for required field: $field");
|
|
// Construct the expected message based on the field name
|
|
$expected_message = ucwords(str_replace('_', ' ', $field)) . ' is required.';
|
|
// Special case checks for specific required messages
|
|
if ($field === 'business_email') {
|
|
$this->assertEquals('Business Email is required.', $errors[$field]);
|
|
} elseif ($field === 'user_country') {
|
|
$this->assertEquals('Country is required.', $errors[$field]);
|
|
} elseif ($field === 'user_state') {
|
|
$this->assertEquals('State/Province is required.', $errors[$field]);
|
|
} elseif ($field === 'user_city') {
|
|
$this->assertEquals('City is required.', $errors[$field]);
|
|
} elseif ($field === 'user_zip') {
|
|
$this->assertEquals('Zip/Postal Code is required.', $errors[$field]);
|
|
} else {
|
|
$this->assertEquals($expected_message, $errors[$field]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function test_email_validation() { // Added missing method definition
|
|
$data = $this->get_valid_test_data();
|
|
$data['business_email'] = 'invalid-email';
|
|
|
|
$errors = $this->registration->validate_registration($data);
|
|
|
|
$this->assertArrayHasKey('business_email', $errors);
|
|
$this->assertEquals('Please enter a valid business email address.', $errors['business_email']);
|
|
}
|
|
public function test_password_validation() {
|
|
$test_cases = [
|
|
// Use the actual error message from the validation logic
|
|
'short' => ['pass', 'Password must be at least 8 characters long.'],
|
|
'no_uppercase' => ['password1', 'Password must contain at least one uppercase letter.'], // Assuming this is the actual message
|
|
'no_lowercase' => ['PASSWORD1', 'Password must contain at least one lowercase letter.'], // Assuming this is the actual message
|
|
'no_number' => ['Password', 'Password must contain at least one number.'], // Assuming this is the actual message
|
|
'valid' => ['ValidPass1', null]
|
|
];
|
|
|
|
|
|
foreach ($test_cases as $case => $values) {
|
|
$data = $this->get_valid_test_data();
|
|
$data['user_pass'] = $values[0];
|
|
|
|
$errors = $this->registration->validate_registration($data);
|
|
|
|
if ($values[1] === null) {
|
|
$this->assertArrayNotHasKey('user_pass', $errors);
|
|
} else {
|
|
$this->assertArrayHasKey('user_pass', $errors);
|
|
$this->assertEquals($values[1], $errors['user_pass']);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function test_url_validation() {
|
|
$data = $this->get_valid_test_data();
|
|
$data['business_website'] = 'invalid-url';
|
|
$errors = $this->registration->validate_registration($data);
|
|
|
|
$this->assertArrayHasKey('business_website', $errors);
|
|
$this->assertEquals('Please enter a valid URL for your business website.', $errors['business_website']);
|
|
}
|
|
|
|
|
|
private function get_valid_test_data() {
|
|
return [
|
|
'first_name' => 'John',
|
|
'last_name' => 'Doe',
|
|
'business_name' => 'ACME HVAC',
|
|
'business_phone' => '123-456-7890',
|
|
'business_email' => 'test@example.com',
|
|
'user_country' => 'United States',
|
|
'user_state' => 'California',
|
|
'user_city' => 'Los Angeles',
|
|
'user_zip' => '90001',
|
|
'business_type' => 'Contractor',
|
|
'training_audience' => ['Anyone'],
|
|
'user_pass' => 'ValidPass1'
|
|
];
|
|
}
|
|
} |