diff --git a/TODO.md b/TODO.md index c9c6f32f..acfec879 100644 --- a/TODO.md +++ b/TODO.md @@ -113,4 +113,5 @@ Overall coverage: **35%** (20,720 / 59,212 statements). 90 files at 0% coverage. - [x] t520 feat(addon): create multisite-ultimate-fluentaffiliate addon for recurring commission tracking #enhancement #auto-dispatch ~12h ref:GH#690 completed:2026-03-29 - [x] t521 chore: remove stale @todo comments for already-implemented methods #enhancement #auto-dispatch ~1h ref:GH#691 pr:#693 completed:2026-03-29 - [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 -- [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 \ No newline at end of file +- [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 +- [ ] 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 \ No newline at end of file diff --git a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Password_Test.php b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Password_Test.php index 87064f7a..6aed3855 100644 --- a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Password_Test.php +++ b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Password_Test.php @@ -208,4 +208,93 @@ public function test_to_fields_array_with_confirm_field(): void { $this->assertArrayHasKey('password_conf', $fields); $this->assertEquals('Confirm Password', $fields['password_conf']['name']); } + + /** + * Test defaults includes auto_generate_password key set to false. + */ + public function test_defaults_includes_auto_generate_password(): void { + $defaults = $this->field->defaults(); + + $this->assertArrayHasKey('auto_generate_password', $defaults); + $this->assertFalse($defaults['auto_generate_password']); + } + + /** + * Test get_fields includes auto_generate_password toggle. + */ + public function test_get_fields_includes_auto_generate_toggle(): void { + $fields = $this->field->get_fields(); + + $this->assertArrayHasKey('auto_generate_password', $fields); + $this->assertEquals('toggle', $fields['auto_generate_password']['type']); + } + + /** + * Test to_fields_array with auto_generate_password emits hidden flag only. + */ + public function test_to_fields_array_with_auto_generate_emits_hidden_flag(): void { + wp_set_current_user(0); + + $attributes = [ + 'name' => 'Password', + 'placeholder' => '', + 'tooltip' => '', + 'auto_generate_password' => true, + 'password_strength_meter' => false, + 'password_confirm_field' => false, + ]; + + $this->field->set_attributes($attributes); + $fields = $this->field->to_fields_array($attributes); + + $this->assertIsArray($fields); + $this->assertArrayHasKey('auto_generate_password', $fields); + $this->assertEquals('hidden', $fields['auto_generate_password']['type']); + $this->assertEquals('1', $fields['auto_generate_password']['value']); + $this->assertArrayNotHasKey('password', $fields); + } + + /** + * Test to_fields_array with auto_generate_password does not render visible password field. + */ + public function test_to_fields_array_auto_generate_no_visible_password(): void { + wp_set_current_user(0); + + $attributes = [ + 'name' => 'Password', + 'placeholder' => '', + 'tooltip' => '', + 'auto_generate_password' => true, + ]; + + $this->field->set_attributes($attributes); + $fields = $this->field->to_fields_array($attributes); + + $this->assertArrayNotHasKey('password', $fields); + $this->assertArrayNotHasKey('password_conf', $fields); + } + + /** + * Test password_strength_meter field has v-show guard when auto_generate is on. + */ + public function test_password_strength_meter_has_v_show_guard(): void { + $fields = $this->field->get_fields(); + + $this->assertArrayHasKey('password_strength_meter', $fields); + $this->assertArrayHasKey('wrapper_html_attr', $fields['password_strength_meter']); + $this->assertArrayHasKey('v-show', $fields['password_strength_meter']['wrapper_html_attr']); + $this->assertEquals('!auto_generate_password', $fields['password_strength_meter']['wrapper_html_attr']['v-show']); + } + + /** + * Test password_confirm_field has v-show guard when auto_generate is on. + */ + public function test_password_confirm_field_has_v_show_guard(): void { + $fields = $this->field->get_fields(); + + $this->assertArrayHasKey('password_confirm_field', $fields); + $this->assertArrayHasKey('wrapper_html_attr', $fields['password_confirm_field']); + $this->assertArrayHasKey('v-show', $fields['password_confirm_field']['wrapper_html_attr']); + $this->assertEquals('!auto_generate_password', $fields['password_confirm_field']['wrapper_html_attr']['v-show']); + } } diff --git a/tests/WP_Ultimo/Models/Checkout_Form_Test.php b/tests/WP_Ultimo/Models/Checkout_Form_Test.php index a8866cfc..a5df87a4 100644 --- a/tests/WP_Ultimo/Models/Checkout_Form_Test.php +++ b/tests/WP_Ultimo/Models/Checkout_Form_Test.php @@ -2836,4 +2836,202 @@ public function test_pay_invoice_form_fields_with_payment_hash_in_request(): voi $this->assertEquals('checkout', $fields[0]['id']); $this->assertEquals('Pay Invoice', $fields[0]['name']); } + + /** + * Test simple template is accepted by validation rules. + */ + public function test_validation_rules_accept_simple_template(): void { + $checkout_form = new Checkout_Form(); + $rules = $checkout_form->validation_rules(); + + $this->assertStringContainsString('simple', $rules['template']); + } + + /** + * Test use_template with simple template returns non-empty settings. + */ + public function test_use_template_simple_returns_settings(): void { + $checkout_form = new Checkout_Form(); + + $checkout_form->use_template('simple'); + $settings = $checkout_form->get_settings(); + + $this->assertNotEmpty($settings); + $this->assertIsArray($settings); + } + + /** + * Test simple template has exactly one step. + */ + public function test_simple_template_has_one_step(): void { + $checkout_form = new Checkout_Form(); + + $checkout_form->use_template('simple'); + $settings = $checkout_form->get_settings(); + + $this->assertCount(1, $settings); + $this->assertEquals('checkout', $settings[0]['id']); + } + + /** + * Test simple template contains email field. + */ + public function test_simple_template_contains_email_field(): void { + $checkout_form = new Checkout_Form(); + + $checkout_form->use_template('simple'); + $settings = $checkout_form->get_settings(); + + $field_types = array_column($settings[0]['fields'], 'type'); + $this->assertContains('email', $field_types); + } + + /** + * Test simple template has password field with auto_generate_password enabled. + */ + public function test_simple_template_password_field_has_auto_generate(): void { + $checkout_form = new Checkout_Form(); + + $checkout_form->use_template('simple'); + $settings = $checkout_form->get_settings(); + + $password_field = null; + foreach ($settings[0]['fields'] as $field) { + if ('password' === $field['type']) { + $password_field = $field; + break; + } + } + + $this->assertNotNull($password_field, 'Password field must exist in simple template'); + $this->assertArrayHasKey('auto_generate_password', $password_field); + $this->assertTrue((bool) $password_field['auto_generate_password']); + } + + /** + * Test simple template has username field with auto_generate_username enabled. + */ + public function test_simple_template_username_field_has_auto_generate(): void { + $checkout_form = new Checkout_Form(); + + $checkout_form->use_template('simple'); + $settings = $checkout_form->get_settings(); + + $username_field = null; + foreach ($settings[0]['fields'] as $field) { + if ('username' === $field['type']) { + $username_field = $field; + break; + } + } + + $this->assertNotNull($username_field, 'Username field must exist in simple template'); + $this->assertArrayHasKey('auto_generate_username', $username_field); + $this->assertTrue((bool) $username_field['auto_generate_username']); + } + + /** + * Test simple template has site_title field with auto_generate_site_title enabled. + */ + public function test_simple_template_site_title_has_auto_generate(): void { + $checkout_form = new Checkout_Form(); + + $checkout_form->use_template('simple'); + $settings = $checkout_form->get_settings(); + + $site_title_field = null; + foreach ($settings[0]['fields'] as $field) { + if ('site_title' === $field['type']) { + $site_title_field = $field; + break; + } + } + + $this->assertNotNull($site_title_field, 'Site title field must exist in simple template'); + $this->assertArrayHasKey('auto_generate_site_title', $site_title_field); + $this->assertTrue((bool) $site_title_field['auto_generate_site_title']); + } + + /** + * Test simple template has site_url field with auto_generate_site_url enabled. + */ + public function test_simple_template_site_url_has_auto_generate(): void { + $checkout_form = new Checkout_Form(); + + $checkout_form->use_template('simple'); + $settings = $checkout_form->get_settings(); + + $site_url_field = null; + foreach ($settings[0]['fields'] as $field) { + if ('site_url' === $field['type']) { + $site_url_field = $field; + break; + } + } + + $this->assertNotNull($site_url_field, 'Site URL field must exist in simple template'); + $this->assertArrayHasKey('auto_generate_site_url', $site_url_field); + $this->assertTrue((bool) $site_url_field['auto_generate_site_url']); + } + + /** + * Test simple template contains all required checkout fields. + */ + public function test_simple_template_contains_required_checkout_fields(): void { + $checkout_form = new Checkout_Form(); + + $checkout_form->use_template('simple'); + $settings = $checkout_form->get_settings(); + + $field_types = array_column($settings[0]['fields'], 'type'); + + $this->assertContains('email', $field_types); + $this->assertContains('username', $field_types); + $this->assertContains('password', $field_types); + $this->assertContains('site_title', $field_types); + $this->assertContains('site_url', $field_types); + $this->assertContains('order_summary', $field_types); + $this->assertContains('payment', $field_types); + $this->assertContains('submit_button', $field_types); + } + + /** + * Test simple template is filterable via wu_checkout_form_simple_template hook. + */ + public function test_simple_template_is_filterable(): void { + $filter_called = false; + + add_filter('wu_checkout_form_simple_template', function ($steps) use (&$filter_called) { + $filter_called = true; + return $steps; + }); + + $checkout_form = new Checkout_Form(); + $checkout_form->use_template('simple'); + + remove_all_filters('wu_checkout_form_simple_template'); + + $this->assertTrue($filter_called, 'wu_checkout_form_simple_template filter must be applied'); + } + + /** + * Test simple template is applied on save when template is set to simple. + */ + public function test_simple_template_applied_on_save(): void { + $checkout_form = wu_create_checkout_form([ + 'name' => 'Simple Template Save Test', + 'slug' => 'simple-template-save-test', + 'template' => 'simple', + ]); + + $this->assertNotWPError($checkout_form); + + $fetched = wu_get_checkout_form($checkout_form->get_id()); + $settings = $fetched->get_settings(); + + $this->assertNotEmpty($settings); + $field_types = array_column($settings[0]['fields'], 'type'); + $this->assertContains('email', $field_types); + $this->assertContains('password', $field_types); + } }