Skip to content

Commit 0a5ca22

Browse files
authored
t524: test(checkout): add unit tests for simple template and auto-generated credentials (#747)
* chore: add t524 simple checkout form feature to backlog (re-implement PR #740) * test(checkout): add unit tests for simple template and auto-generate password - Signup_Field_Password_Test: 6 new tests covering auto_generate_password defaults, get_fields toggle, to_fields_array hidden flag emission, v-show guards on strength meter and confirm field - Checkout_Form_Test: 11 new tests covering simple template validation, use_template() structure, field presence, auto-generate flags on username/password/site_title/site_url, filterable hook, and save path All 17 tests pass against the implementation already in main (PRs #737, #739, #742). Closes #746
1 parent 820a6a0 commit 0a5ca22

3 files changed

Lines changed: 289 additions & 1 deletion

File tree

TODO.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,5 @@ Overall coverage: **35%** (20,720 / 59,212 statements). 90 files at 0% coverage.
113113
- [x] t520 feat(addon): create multisite-ultimate-fluentaffiliate addon for recurring commission tracking #enhancement #auto-dispatch ~12h ref:GH#690 completed:2026-03-29
114114
- [x] t521 chore: remove stale @todo comments for already-implemented methods #enhancement #auto-dispatch ~1h ref:GH#691 pr:#693 completed:2026-03-29
115115
- [x] t522 test(integrations): write unit tests for integration provider classes (bunnynet, cloudways, enhance, laravel-forge, plesk, rocket, serverpilot, wpengine, wpmudev) #testing #auto-dispatch ~4h ref:GH#697 pr:#698 completed:2026-03-29
116-
- [x] t523 feat(paypal): PayPal PPCP integration review compliance — disconnect disclaimer, onboarding failure UI, merchant status validation, payee field, debug ID logging @superdav42 #paypal #compliance ~8h ref:GH#725 pr:#726 completed:2026-04-01
116+
- [x] t523 feat(paypal): PayPal PPCP integration review compliance — disconnect disclaimer, onboarding failure UI, merchant status validation, payee field, debug ID logging @superdav42 #paypal #compliance ~8h ref:GH#725 pr:#726 completed:2026-04-01
117+
- [ ] t524 feat(checkout): add simple checkout form template with auto-generated credentials (re-implement PR #740 which was closed due to merge conflicts) #enhancement #auto-dispatch ~4h ref:GH#746 logged:2026-04-03

tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Password_Test.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,93 @@ public function test_to_fields_array_with_confirm_field(): void {
208208
$this->assertArrayHasKey('password_conf', $fields);
209209
$this->assertEquals('Confirm Password', $fields['password_conf']['name']);
210210
}
211+
212+
/**
213+
* Test defaults includes auto_generate_password key set to false.
214+
*/
215+
public function test_defaults_includes_auto_generate_password(): void {
216+
$defaults = $this->field->defaults();
217+
218+
$this->assertArrayHasKey('auto_generate_password', $defaults);
219+
$this->assertFalse($defaults['auto_generate_password']);
220+
}
221+
222+
/**
223+
* Test get_fields includes auto_generate_password toggle.
224+
*/
225+
public function test_get_fields_includes_auto_generate_toggle(): void {
226+
$fields = $this->field->get_fields();
227+
228+
$this->assertArrayHasKey('auto_generate_password', $fields);
229+
$this->assertEquals('toggle', $fields['auto_generate_password']['type']);
230+
}
231+
232+
/**
233+
* Test to_fields_array with auto_generate_password emits hidden flag only.
234+
*/
235+
public function test_to_fields_array_with_auto_generate_emits_hidden_flag(): void {
236+
wp_set_current_user(0);
237+
238+
$attributes = [
239+
'name' => 'Password',
240+
'placeholder' => '',
241+
'tooltip' => '',
242+
'auto_generate_password' => true,
243+
'password_strength_meter' => false,
244+
'password_confirm_field' => false,
245+
];
246+
247+
$this->field->set_attributes($attributes);
248+
$fields = $this->field->to_fields_array($attributes);
249+
250+
$this->assertIsArray($fields);
251+
$this->assertArrayHasKey('auto_generate_password', $fields);
252+
$this->assertEquals('hidden', $fields['auto_generate_password']['type']);
253+
$this->assertEquals('1', $fields['auto_generate_password']['value']);
254+
$this->assertArrayNotHasKey('password', $fields);
255+
}
256+
257+
/**
258+
* Test to_fields_array with auto_generate_password does not render visible password field.
259+
*/
260+
public function test_to_fields_array_auto_generate_no_visible_password(): void {
261+
wp_set_current_user(0);
262+
263+
$attributes = [
264+
'name' => 'Password',
265+
'placeholder' => '',
266+
'tooltip' => '',
267+
'auto_generate_password' => true,
268+
];
269+
270+
$this->field->set_attributes($attributes);
271+
$fields = $this->field->to_fields_array($attributes);
272+
273+
$this->assertArrayNotHasKey('password', $fields);
274+
$this->assertArrayNotHasKey('password_conf', $fields);
275+
}
276+
277+
/**
278+
* Test password_strength_meter field has v-show guard when auto_generate is on.
279+
*/
280+
public function test_password_strength_meter_has_v_show_guard(): void {
281+
$fields = $this->field->get_fields();
282+
283+
$this->assertArrayHasKey('password_strength_meter', $fields);
284+
$this->assertArrayHasKey('wrapper_html_attr', $fields['password_strength_meter']);
285+
$this->assertArrayHasKey('v-show', $fields['password_strength_meter']['wrapper_html_attr']);
286+
$this->assertEquals('!auto_generate_password', $fields['password_strength_meter']['wrapper_html_attr']['v-show']);
287+
}
288+
289+
/**
290+
* Test password_confirm_field has v-show guard when auto_generate is on.
291+
*/
292+
public function test_password_confirm_field_has_v_show_guard(): void {
293+
$fields = $this->field->get_fields();
294+
295+
$this->assertArrayHasKey('password_confirm_field', $fields);
296+
$this->assertArrayHasKey('wrapper_html_attr', $fields['password_confirm_field']);
297+
$this->assertArrayHasKey('v-show', $fields['password_confirm_field']['wrapper_html_attr']);
298+
$this->assertEquals('!auto_generate_password', $fields['password_confirm_field']['wrapper_html_attr']['v-show']);
299+
}
211300
}

tests/WP_Ultimo/Models/Checkout_Form_Test.php

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,4 +2836,202 @@ public function test_pay_invoice_form_fields_with_payment_hash_in_request(): voi
28362836
$this->assertEquals('checkout', $fields[0]['id']);
28372837
$this->assertEquals('Pay Invoice', $fields[0]['name']);
28382838
}
2839+
2840+
/**
2841+
* Test simple template is accepted by validation rules.
2842+
*/
2843+
public function test_validation_rules_accept_simple_template(): void {
2844+
$checkout_form = new Checkout_Form();
2845+
$rules = $checkout_form->validation_rules();
2846+
2847+
$this->assertStringContainsString('simple', $rules['template']);
2848+
}
2849+
2850+
/**
2851+
* Test use_template with simple template returns non-empty settings.
2852+
*/
2853+
public function test_use_template_simple_returns_settings(): void {
2854+
$checkout_form = new Checkout_Form();
2855+
2856+
$checkout_form->use_template('simple');
2857+
$settings = $checkout_form->get_settings();
2858+
2859+
$this->assertNotEmpty($settings);
2860+
$this->assertIsArray($settings);
2861+
}
2862+
2863+
/**
2864+
* Test simple template has exactly one step.
2865+
*/
2866+
public function test_simple_template_has_one_step(): void {
2867+
$checkout_form = new Checkout_Form();
2868+
2869+
$checkout_form->use_template('simple');
2870+
$settings = $checkout_form->get_settings();
2871+
2872+
$this->assertCount(1, $settings);
2873+
$this->assertEquals('checkout', $settings[0]['id']);
2874+
}
2875+
2876+
/**
2877+
* Test simple template contains email field.
2878+
*/
2879+
public function test_simple_template_contains_email_field(): void {
2880+
$checkout_form = new Checkout_Form();
2881+
2882+
$checkout_form->use_template('simple');
2883+
$settings = $checkout_form->get_settings();
2884+
2885+
$field_types = array_column($settings[0]['fields'], 'type');
2886+
$this->assertContains('email', $field_types);
2887+
}
2888+
2889+
/**
2890+
* Test simple template has password field with auto_generate_password enabled.
2891+
*/
2892+
public function test_simple_template_password_field_has_auto_generate(): void {
2893+
$checkout_form = new Checkout_Form();
2894+
2895+
$checkout_form->use_template('simple');
2896+
$settings = $checkout_form->get_settings();
2897+
2898+
$password_field = null;
2899+
foreach ($settings[0]['fields'] as $field) {
2900+
if ('password' === $field['type']) {
2901+
$password_field = $field;
2902+
break;
2903+
}
2904+
}
2905+
2906+
$this->assertNotNull($password_field, 'Password field must exist in simple template');
2907+
$this->assertArrayHasKey('auto_generate_password', $password_field);
2908+
$this->assertTrue((bool) $password_field['auto_generate_password']);
2909+
}
2910+
2911+
/**
2912+
* Test simple template has username field with auto_generate_username enabled.
2913+
*/
2914+
public function test_simple_template_username_field_has_auto_generate(): void {
2915+
$checkout_form = new Checkout_Form();
2916+
2917+
$checkout_form->use_template('simple');
2918+
$settings = $checkout_form->get_settings();
2919+
2920+
$username_field = null;
2921+
foreach ($settings[0]['fields'] as $field) {
2922+
if ('username' === $field['type']) {
2923+
$username_field = $field;
2924+
break;
2925+
}
2926+
}
2927+
2928+
$this->assertNotNull($username_field, 'Username field must exist in simple template');
2929+
$this->assertArrayHasKey('auto_generate_username', $username_field);
2930+
$this->assertTrue((bool) $username_field['auto_generate_username']);
2931+
}
2932+
2933+
/**
2934+
* Test simple template has site_title field with auto_generate_site_title enabled.
2935+
*/
2936+
public function test_simple_template_site_title_has_auto_generate(): void {
2937+
$checkout_form = new Checkout_Form();
2938+
2939+
$checkout_form->use_template('simple');
2940+
$settings = $checkout_form->get_settings();
2941+
2942+
$site_title_field = null;
2943+
foreach ($settings[0]['fields'] as $field) {
2944+
if ('site_title' === $field['type']) {
2945+
$site_title_field = $field;
2946+
break;
2947+
}
2948+
}
2949+
2950+
$this->assertNotNull($site_title_field, 'Site title field must exist in simple template');
2951+
$this->assertArrayHasKey('auto_generate_site_title', $site_title_field);
2952+
$this->assertTrue((bool) $site_title_field['auto_generate_site_title']);
2953+
}
2954+
2955+
/**
2956+
* Test simple template has site_url field with auto_generate_site_url enabled.
2957+
*/
2958+
public function test_simple_template_site_url_has_auto_generate(): void {
2959+
$checkout_form = new Checkout_Form();
2960+
2961+
$checkout_form->use_template('simple');
2962+
$settings = $checkout_form->get_settings();
2963+
2964+
$site_url_field = null;
2965+
foreach ($settings[0]['fields'] as $field) {
2966+
if ('site_url' === $field['type']) {
2967+
$site_url_field = $field;
2968+
break;
2969+
}
2970+
}
2971+
2972+
$this->assertNotNull($site_url_field, 'Site URL field must exist in simple template');
2973+
$this->assertArrayHasKey('auto_generate_site_url', $site_url_field);
2974+
$this->assertTrue((bool) $site_url_field['auto_generate_site_url']);
2975+
}
2976+
2977+
/**
2978+
* Test simple template contains all required checkout fields.
2979+
*/
2980+
public function test_simple_template_contains_required_checkout_fields(): void {
2981+
$checkout_form = new Checkout_Form();
2982+
2983+
$checkout_form->use_template('simple');
2984+
$settings = $checkout_form->get_settings();
2985+
2986+
$field_types = array_column($settings[0]['fields'], 'type');
2987+
2988+
$this->assertContains('email', $field_types);
2989+
$this->assertContains('username', $field_types);
2990+
$this->assertContains('password', $field_types);
2991+
$this->assertContains('site_title', $field_types);
2992+
$this->assertContains('site_url', $field_types);
2993+
$this->assertContains('order_summary', $field_types);
2994+
$this->assertContains('payment', $field_types);
2995+
$this->assertContains('submit_button', $field_types);
2996+
}
2997+
2998+
/**
2999+
* Test simple template is filterable via wu_checkout_form_simple_template hook.
3000+
*/
3001+
public function test_simple_template_is_filterable(): void {
3002+
$filter_called = false;
3003+
3004+
add_filter('wu_checkout_form_simple_template', function ($steps) use (&$filter_called) {
3005+
$filter_called = true;
3006+
return $steps;
3007+
});
3008+
3009+
$checkout_form = new Checkout_Form();
3010+
$checkout_form->use_template('simple');
3011+
3012+
remove_all_filters('wu_checkout_form_simple_template');
3013+
3014+
$this->assertTrue($filter_called, 'wu_checkout_form_simple_template filter must be applied');
3015+
}
3016+
3017+
/**
3018+
* Test simple template is applied on save when template is set to simple.
3019+
*/
3020+
public function test_simple_template_applied_on_save(): void {
3021+
$checkout_form = wu_create_checkout_form([
3022+
'name' => 'Simple Template Save Test',
3023+
'slug' => 'simple-template-save-test',
3024+
'template' => 'simple',
3025+
]);
3026+
3027+
$this->assertNotWPError($checkout_form);
3028+
3029+
$fetched = wu_get_checkout_form($checkout_form->get_id());
3030+
$settings = $fetched->get_settings();
3031+
3032+
$this->assertNotEmpty($settings);
3033+
$field_types = array_column($settings[0]['fields'], 'type');
3034+
$this->assertContains('email', $field_types);
3035+
$this->assertContains('password', $field_types);
3036+
}
28393037
}

0 commit comments

Comments
 (0)