From d8644201c5d8f1a0fd56a8fd78cb9d048b9a664f Mon Sep 17 00:00:00 2001 From: David Stone Date: Sun, 29 Mar 2026 00:38:14 -0600 Subject: [PATCH 1/2] test(signup-fields): add unit tests for 8 untested signup field classes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Covers billing-address, order-bump, order-summary, payment, pricing-table, products, steps, and terms-of-use. Each test class verifies get_type(), is_required(), get_title(), get_description(), get_tooltip(), get_icon(), defaults(), default_fields(), force_attributes(), get_fields(), and to_fields_array() where applicable. 135 tests, 262 assertions — all pass. Closes #699 --- .../Signup_Field_Billing_Address_Test.php | 185 ++++++++++++++ .../Signup_Field_Order_Bump_Test.php | 182 ++++++++++++++ .../Signup_Field_Order_Summary_Test.php | 161 ++++++++++++ .../Signup_Field_Payment_Test.php | 190 ++++++++++++++ .../Signup_Field_Pricing_Table_Test.php | 214 ++++++++++++++++ .../Signup_Field_Products_Test.php | 192 +++++++++++++++ .../Signup_Fields/Signup_Field_Steps_Test.php | 166 +++++++++++++ .../Signup_Field_Terms_Of_Use_Test.php | 232 ++++++++++++++++++ 8 files changed, 1522 insertions(+) create mode 100644 tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Billing_Address_Test.php create mode 100644 tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Order_Bump_Test.php create mode 100644 tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Order_Summary_Test.php create mode 100644 tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Payment_Test.php create mode 100644 tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Pricing_Table_Test.php create mode 100644 tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Products_Test.php create mode 100644 tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Steps_Test.php create mode 100644 tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Terms_Of_Use_Test.php diff --git a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Billing_Address_Test.php b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Billing_Address_Test.php new file mode 100644 index 000000000..1adaa5105 --- /dev/null +++ b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Billing_Address_Test.php @@ -0,0 +1,185 @@ +field = new Signup_Field_Billing_Address(); + } + + /** + * Test get_type returns billing_address. + */ + public function test_get_type(): void { + $this->assertEquals( 'billing_address', $this->field->get_type() ); + } + + /** + * Test is_required returns false. + */ + public function test_is_required(): void { + $this->assertFalse( $this->field->is_required() ); + } + + /** + * Test is_user_field returns true. + */ + public function test_is_user_field(): void { + $this->assertTrue( $this->field->is_user_field() ); + } + + /** + * Test is_site_field returns false. + */ + public function test_is_site_field(): void { + $this->assertFalse( $this->field->is_site_field() ); + } + + /** + * Test get_title returns non-empty string. + */ + public function test_get_title(): void { + $title = $this->field->get_title(); + $this->assertIsString( $title ); + $this->assertNotEmpty( $title ); + } + + /** + * Test get_description returns non-empty string. + */ + public function test_get_description(): void { + $description = $this->field->get_description(); + $this->assertIsString( $description ); + $this->assertNotEmpty( $description ); + } + + /** + * Test get_tooltip returns non-empty string. + */ + public function test_get_tooltip(): void { + $tooltip = $this->field->get_tooltip(); + $this->assertIsString( $tooltip ); + $this->assertNotEmpty( $tooltip ); + } + + /** + * Test get_icon returns dashicon class. + */ + public function test_get_icon(): void { + $icon = $this->field->get_icon(); + $this->assertIsString( $icon ); + $this->assertStringContainsString( 'dashicons', $icon ); + } + + /** + * Test defaults returns array with zip_and_country key. + */ + public function test_defaults(): void { + $defaults = $this->field->defaults(); + $this->assertIsArray( $defaults ); + $this->assertArrayHasKey( 'zip_and_country', $defaults ); + $this->assertTrue( $defaults['zip_and_country'] ); + } + + /** + * Test default_fields returns array containing name. + */ + public function test_default_fields(): void { + $fields = $this->field->default_fields(); + $this->assertIsArray( $fields ); + $this->assertContains( 'name', $fields ); + } + + /** + * Test force_attributes returns id and required. + */ + public function test_force_attributes(): void { + $attrs = $this->field->force_attributes(); + $this->assertIsArray( $attrs ); + $this->assertArrayHasKey( 'id', $attrs ); + $this->assertEquals( 'billing_address', $attrs['id'] ); + $this->assertArrayHasKey( 'required', $attrs ); + $this->assertTrue( $attrs['required'] ); + } + + /** + * Test get_fields returns array with zip_and_country key. + */ + public function test_get_fields(): void { + $fields = $this->field->get_fields(); + $this->assertIsArray( $fields ); + $this->assertArrayHasKey( 'zip_and_country', $fields ); + } + + /** + * Test get_fields zip_and_country is a toggle type. + */ + public function test_get_fields_zip_and_country_is_toggle(): void { + $fields = $this->field->get_fields(); + $this->assertEquals( 'toggle', $fields['zip_and_country']['type'] ); + } + + /** + * Test build_select_alternative returns array with expected keys. + */ + public function test_build_select_alternative(): void { + $base_field = array( + 'type' => 'text', + 'title' => 'State', + 'wrapper_html_attr' => array(), + 'html_attr' => array(), + ); + + $result = $this->field->build_select_alternative( $base_field, 'state_list', 'state_field' ); + + $this->assertIsArray( $result ); + $this->assertEquals( 'select', $result['type'] ); + $this->assertArrayHasKey( 'options_template', $result ); + $this->assertArrayHasKey( 'options', $result ); + $this->assertTrue( $result['required'] ); + } + + /** + * Test build_select_alternative sets v-if on base_field. + */ + public function test_build_select_alternative_sets_v_if_on_base_field(): void { + $base_field = array( + 'type' => 'text', + 'title' => 'State', + 'wrapper_html_attr' => array(), + 'html_attr' => array(), + ); + + $this->field->build_select_alternative( $base_field, 'state_list', 'state_field' ); + + $this->assertArrayHasKey( 'v-if', $base_field['wrapper_html_attr'] ); + $this->assertStringContainsString( 'state_list', $base_field['wrapper_html_attr']['v-if'] ); + } + + /** + * Test field is instance of Base_Signup_Field. + */ + public function test_field_is_instance_of_base(): void { + $this->assertInstanceOf( Base_Signup_Field::class, $this->field ); + } +} diff --git a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Order_Bump_Test.php b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Order_Bump_Test.php new file mode 100644 index 000000000..5d30cb6d8 --- /dev/null +++ b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Order_Bump_Test.php @@ -0,0 +1,182 @@ +field = new Signup_Field_Order_Bump(); + } + + /** + * Test get_type returns order_bump. + */ + public function test_get_type(): void { + $this->assertEquals( 'order_bump', $this->field->get_type() ); + } + + /** + * Test is_required returns false. + */ + public function test_is_required(): void { + $this->assertFalse( $this->field->is_required() ); + } + + /** + * Test get_title returns non-empty string. + */ + public function test_get_title(): void { + $title = $this->field->get_title(); + $this->assertIsString( $title ); + $this->assertNotEmpty( $title ); + } + + /** + * Test get_description returns non-empty string. + */ + public function test_get_description(): void { + $description = $this->field->get_description(); + $this->assertIsString( $description ); + $this->assertNotEmpty( $description ); + } + + /** + * Test get_tooltip returns non-empty string. + */ + public function test_get_tooltip(): void { + $tooltip = $this->field->get_tooltip(); + $this->assertIsString( $tooltip ); + $this->assertNotEmpty( $tooltip ); + } + + /** + * Test get_icon returns dashicon class. + */ + public function test_get_icon(): void { + $icon = $this->field->get_icon(); + $this->assertIsString( $icon ); + $this->assertStringContainsString( 'dashicons', $icon ); + } + + /** + * Test is_user_field returns false by default. + */ + public function test_is_user_field(): void { + $this->assertFalse( $this->field->is_user_field() ); + } + + /** + * Test is_site_field returns false by default. + */ + public function test_is_site_field(): void { + $this->assertFalse( $this->field->is_site_field() ); + } + + /** + * Test defaults returns expected keys. + */ + public function test_defaults(): void { + $defaults = $this->field->defaults(); + $this->assertIsArray( $defaults ); + $this->assertArrayHasKey( 'order_bump_template', $defaults ); + $this->assertEquals( 'simple', $defaults['order_bump_template'] ); + $this->assertArrayHasKey( 'display_product_description', $defaults ); + $this->assertEquals( 0, $defaults['display_product_description'] ); + } + + /** + * Test default_fields returns array containing name. + */ + public function test_default_fields(): void { + $fields = $this->field->default_fields(); + $this->assertIsArray( $fields ); + $this->assertContains( 'name', $fields ); + } + + /** + * Test force_attributes returns order_bump_template. + */ + public function test_force_attributes(): void { + $attrs = $this->field->force_attributes(); + $this->assertIsArray( $attrs ); + $this->assertArrayHasKey( 'order_bump_template', $attrs ); + $this->assertEquals( 'simple', $attrs['order_bump_template'] ); + } + + /** + * Test get_fields returns array with expected keys. + */ + public function test_get_fields(): void { + $fields = $this->field->get_fields(); + $this->assertIsArray( $fields ); + $this->assertArrayHasKey( 'product', $fields ); + $this->assertArrayHasKey( 'display_product_description', $fields ); + $this->assertArrayHasKey( 'display_product_image', $fields ); + } + + /** + * Test get_fields product field is model type. + */ + public function test_get_fields_product_is_model_type(): void { + $fields = $this->field->get_fields(); + $this->assertEquals( 'model', $fields['product']['type'] ); + } + + /** + * Test get_fields display_product_description is toggle type. + */ + public function test_get_fields_display_product_description_is_toggle(): void { + $fields = $this->field->get_fields(); + $this->assertEquals( 'toggle', $fields['display_product_description']['type'] ); + } + + /** + * Test get_fields display_product_image is toggle type. + */ + public function test_get_fields_display_product_image_is_toggle(): void { + $fields = $this->field->get_fields(); + $this->assertEquals( 'toggle', $fields['display_product_image']['type'] ); + } + + /** + * Test to_fields_array returns empty array when product not found. + */ + public function test_to_fields_array_returns_empty_when_no_product(): void { + $attributes = array( + 'product' => 999999, + 'order_bump_template' => 'simple', + 'id' => 'order_bump', + 'element_classes' => '', + ); + + $result = $this->field->to_fields_array( $attributes ); + $this->assertIsArray( $result ); + $this->assertEmpty( $result ); + } + + /** + * Test field is instance of Base_Signup_Field. + */ + public function test_field_is_instance_of_base(): void { + $this->assertInstanceOf( Base_Signup_Field::class, $this->field ); + } +} diff --git a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Order_Summary_Test.php b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Order_Summary_Test.php new file mode 100644 index 000000000..9cf671a65 --- /dev/null +++ b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Order_Summary_Test.php @@ -0,0 +1,161 @@ +field = new Signup_Field_Order_Summary(); + } + + /** + * Test get_type returns order_summary. + */ + public function test_get_type(): void { + $this->assertEquals( 'order_summary', $this->field->get_type() ); + } + + /** + * Test is_required returns true. + */ + public function test_is_required(): void { + $this->assertTrue( $this->field->is_required() ); + } + + /** + * Test get_title returns non-empty string. + */ + public function test_get_title(): void { + $title = $this->field->get_title(); + $this->assertIsString( $title ); + $this->assertNotEmpty( $title ); + } + + /** + * Test get_description returns non-empty string. + */ + public function test_get_description(): void { + $description = $this->field->get_description(); + $this->assertIsString( $description ); + $this->assertNotEmpty( $description ); + } + + /** + * Test get_tooltip returns non-empty string. + */ + public function test_get_tooltip(): void { + $tooltip = $this->field->get_tooltip(); + $this->assertIsString( $tooltip ); + $this->assertNotEmpty( $tooltip ); + } + + /** + * Test get_icon returns dashicon class. + */ + public function test_get_icon(): void { + $icon = $this->field->get_icon(); + $this->assertIsString( $icon ); + $this->assertStringContainsString( 'dashicons', $icon ); + } + + /** + * Test is_user_field returns false by default. + */ + public function test_is_user_field(): void { + $this->assertFalse( $this->field->is_user_field() ); + } + + /** + * Test is_site_field returns false by default. + */ + public function test_is_site_field(): void { + $this->assertFalse( $this->field->is_site_field() ); + } + + /** + * Test defaults returns expected keys. + */ + public function test_defaults(): void { + $defaults = $this->field->defaults(); + $this->assertIsArray( $defaults ); + $this->assertArrayHasKey( 'order_summary_template', $defaults ); + $this->assertEquals( 'clean', $defaults['order_summary_template'] ); + $this->assertArrayHasKey( 'table_columns', $defaults ); + $this->assertEquals( 'simple', $defaults['table_columns'] ); + } + + /** + * Test default_fields returns array containing name. + */ + public function test_default_fields(): void { + $fields = $this->field->default_fields(); + $this->assertIsArray( $fields ); + $this->assertContains( 'name', $fields ); + } + + /** + * Test force_attributes returns id = order_summary. + */ + public function test_force_attributes(): void { + $attrs = $this->field->force_attributes(); + $this->assertIsArray( $attrs ); + $this->assertArrayHasKey( 'id', $attrs ); + $this->assertEquals( 'order_summary', $attrs['id'] ); + } + + /** + * Test get_fields returns array with expected keys. + */ + public function test_get_fields(): void { + $fields = $this->field->get_fields(); + $this->assertIsArray( $fields ); + $this->assertArrayHasKey( 'table_columns', $fields ); + $this->assertArrayHasKey( 'order_summary_template', $fields ); + } + + /** + * Test get_fields table_columns is select type with options. + */ + public function test_get_fields_table_columns_is_select_with_options(): void { + $fields = $this->field->get_fields(); + $this->assertEquals( 'select', $fields['table_columns']['type'] ); + $this->assertArrayHasKey( 'options', $fields['table_columns'] ); + $this->assertArrayHasKey( 'simple', $fields['table_columns']['options'] ); + $this->assertArrayHasKey( 'full', $fields['table_columns']['options'] ); + } + + /** + * Test get_fields order_summary_template is group type. + */ + public function test_get_fields_order_summary_template_is_group(): void { + $fields = $this->field->get_fields(); + $this->assertEquals( 'group', $fields['order_summary_template']['type'] ); + $this->assertArrayHasKey( 'fields', $fields['order_summary_template'] ); + } + + /** + * Test field is instance of Base_Signup_Field. + */ + public function test_field_is_instance_of_base(): void { + $this->assertInstanceOf( Base_Signup_Field::class, $this->field ); + } +} diff --git a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Payment_Test.php b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Payment_Test.php new file mode 100644 index 000000000..c831e3686 --- /dev/null +++ b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Payment_Test.php @@ -0,0 +1,190 @@ +field = new Signup_Field_Payment(); + } + + /** + * Test get_type returns payment. + */ + public function test_get_type(): void { + $this->assertEquals( 'payment', $this->field->get_type() ); + } + + /** + * Test is_required returns true. + */ + public function test_is_required(): void { + $this->assertTrue( $this->field->is_required() ); + } + + /** + * Test get_title returns non-empty string. + */ + public function test_get_title(): void { + $title = $this->field->get_title(); + $this->assertIsString( $title ); + $this->assertNotEmpty( $title ); + } + + /** + * Test get_description returns non-empty string. + */ + public function test_get_description(): void { + $description = $this->field->get_description(); + $this->assertIsString( $description ); + $this->assertNotEmpty( $description ); + } + + /** + * Test get_tooltip returns non-empty string. + */ + public function test_get_tooltip(): void { + $tooltip = $this->field->get_tooltip(); + $this->assertIsString( $tooltip ); + $this->assertNotEmpty( $tooltip ); + } + + /** + * Test get_icon returns dashicon class. + */ + public function test_get_icon(): void { + $icon = $this->field->get_icon(); + $this->assertIsString( $icon ); + $this->assertStringContainsString( 'dashicons', $icon ); + } + + /** + * Test is_user_field returns false by default. + */ + public function test_is_user_field(): void { + $this->assertFalse( $this->field->is_user_field() ); + } + + /** + * Test is_site_field returns false by default. + */ + public function test_is_site_field(): void { + $this->assertFalse( $this->field->is_site_field() ); + } + + /** + * Test defaults returns an array. + */ + public function test_defaults(): void { + $defaults = $this->field->defaults(); + $this->assertIsArray( $defaults ); + } + + /** + * Test default_fields returns array containing name. + */ + public function test_default_fields(): void { + $fields = $this->field->default_fields(); + $this->assertIsArray( $fields ); + $this->assertContains( 'name', $fields ); + } + + /** + * Test force_attributes returns id = payment. + */ + public function test_force_attributes(): void { + $attrs = $this->field->force_attributes(); + $this->assertIsArray( $attrs ); + $this->assertArrayHasKey( 'id', $attrs ); + $this->assertEquals( 'payment', $attrs['id'] ); + } + + /** + * Test get_fields returns empty array. + */ + public function test_get_fields(): void { + $fields = $this->field->get_fields(); + $this->assertIsArray( $fields ); + $this->assertEmpty( $fields ); + } + + /** + * Test to_fields_array returns payment_template and payment keys. + */ + public function test_to_fields_array_contains_payment_keys(): void { + $attributes = array( + 'id' => 'payment', + 'name' => 'Payment', + 'wrapper_element_classes' => '', + 'element_classes' => '', + ); + + $this->field->set_attributes( $attributes ); + $fields = $this->field->to_fields_array( $attributes ); + + $this->assertIsArray( $fields ); + $this->assertArrayHasKey( 'payment_template', $fields ); + $this->assertArrayHasKey( 'payment', $fields ); + } + + /** + * Test to_fields_array payment_template is hidden text field. + */ + public function test_to_fields_array_payment_template_is_text(): void { + $attributes = array( + 'id' => 'payment', + 'name' => 'Payment', + 'wrapper_element_classes' => '', + 'element_classes' => '', + ); + + $this->field->set_attributes( $attributes ); + $fields = $this->field->to_fields_array( $attributes ); + + $this->assertEquals( 'text', $fields['payment_template']['type'] ); + $this->assertStringContainsString( 'wu-hidden', $fields['payment_template']['classes'] ); + } + + /** + * Test to_fields_array payment field is payment-methods type. + */ + public function test_to_fields_array_payment_field_type(): void { + $attributes = array( + 'id' => 'payment', + 'name' => 'Payment', + 'wrapper_element_classes' => '', + 'element_classes' => '', + ); + + $this->field->set_attributes( $attributes ); + $fields = $this->field->to_fields_array( $attributes ); + + $this->assertEquals( 'payment-methods', $fields['payment']['type'] ); + } + + /** + * Test field is instance of Base_Signup_Field. + */ + public function test_field_is_instance_of_base(): void { + $this->assertInstanceOf( Base_Signup_Field::class, $this->field ); + } +} diff --git a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Pricing_Table_Test.php b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Pricing_Table_Test.php new file mode 100644 index 000000000..f6b0c10b9 --- /dev/null +++ b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Pricing_Table_Test.php @@ -0,0 +1,214 @@ +field = new Signup_Field_Pricing_Table(); + } + + /** + * Test get_type returns pricing_table. + */ + public function test_get_type(): void { + $this->assertEquals( 'pricing_table', $this->field->get_type() ); + } + + /** + * Test is_required returns false. + */ + public function test_is_required(): void { + $this->assertFalse( $this->field->is_required() ); + } + + /** + * Test get_title returns non-empty string. + */ + public function test_get_title(): void { + $title = $this->field->get_title(); + $this->assertIsString( $title ); + $this->assertNotEmpty( $title ); + } + + /** + * Test get_description returns non-empty string. + */ + public function test_get_description(): void { + $description = $this->field->get_description(); + $this->assertIsString( $description ); + $this->assertNotEmpty( $description ); + } + + /** + * Test get_tooltip returns non-empty string. + */ + public function test_get_tooltip(): void { + $tooltip = $this->field->get_tooltip(); + $this->assertIsString( $tooltip ); + $this->assertNotEmpty( $tooltip ); + } + + /** + * Test get_icon returns dashicon class. + */ + public function test_get_icon(): void { + $icon = $this->field->get_icon(); + $this->assertIsString( $icon ); + $this->assertStringContainsString( 'dashicons', $icon ); + } + + /** + * Test is_user_field returns false by default. + */ + public function test_is_user_field(): void { + $this->assertFalse( $this->field->is_user_field() ); + } + + /** + * Test is_site_field returns false by default. + */ + public function test_is_site_field(): void { + $this->assertFalse( $this->field->is_site_field() ); + } + + /** + * Test defaults returns expected keys with correct values. + */ + public function test_defaults(): void { + $defaults = $this->field->defaults(); + $this->assertIsArray( $defaults ); + $this->assertArrayHasKey( 'pricing_table_products', $defaults ); + $this->assertArrayHasKey( 'pricing_table_template', $defaults ); + $this->assertEquals( 'list', $defaults['pricing_table_template'] ); + $this->assertArrayHasKey( 'force_different_durations', $defaults ); + $this->assertFalse( $defaults['force_different_durations'] ); + $this->assertArrayHasKey( 'hide_pricing_table_when_pre_selected', $defaults ); + $this->assertFalse( $defaults['hide_pricing_table_when_pre_selected'] ); + } + + /** + * Test default_fields returns empty array. + */ + public function test_default_fields(): void { + $fields = $this->field->default_fields(); + $this->assertIsArray( $fields ); + $this->assertEmpty( $fields ); + } + + /** + * Test force_attributes returns id, name, and required. + */ + public function test_force_attributes(): void { + $attrs = $this->field->force_attributes(); + $this->assertIsArray( $attrs ); + $this->assertArrayHasKey( 'id', $attrs ); + $this->assertEquals( 'pricing_table', $attrs['id'] ); + $this->assertArrayHasKey( 'name', $attrs ); + $this->assertIsString( $attrs['name'] ); + $this->assertArrayHasKey( 'required', $attrs ); + $this->assertTrue( $attrs['required'] ); + } + + /** + * Test get_fields returns expected keys. + */ + public function test_get_fields(): void { + $fields = $this->field->get_fields(); + $this->assertIsArray( $fields ); + $this->assertArrayHasKey( 'pricing_table_products', $fields ); + $this->assertArrayHasKey( 'force_different_durations', $fields ); + $this->assertArrayHasKey( 'hide_pricing_table_when_pre_selected', $fields ); + $this->assertArrayHasKey( 'pricing_table_template', $fields ); + } + + /** + * Test get_fields pricing_table_products is model type. + */ + public function test_get_fields_products_is_model_type(): void { + $fields = $this->field->get_fields(); + $this->assertEquals( 'model', $fields['pricing_table_products']['type'] ); + } + + /** + * Test get_fields force_different_durations is toggle type. + */ + public function test_get_fields_force_different_durations_is_toggle(): void { + $fields = $this->field->get_fields(); + $this->assertEquals( 'toggle', $fields['force_different_durations']['type'] ); + } + + /** + * Test get_fields hide_pricing_table_when_pre_selected is toggle type. + */ + public function test_get_fields_hide_when_pre_selected_is_toggle(): void { + $fields = $this->field->get_fields(); + $this->assertEquals( 'toggle', $fields['hide_pricing_table_when_pre_selected']['type'] ); + } + + /** + * Test get_fields pricing_table_template is group type. + */ + public function test_get_fields_pricing_table_template_is_group(): void { + $fields = $this->field->get_fields(); + $this->assertEquals( 'group', $fields['pricing_table_template']['type'] ); + $this->assertArrayHasKey( 'fields', $fields['pricing_table_template'] ); + } + + /** + * Test get_pricing_table_templates returns array. + */ + public function test_get_pricing_table_templates(): void { + $templates = $this->field->get_pricing_table_templates(); + $this->assertIsArray( $templates ); + } + + /** + * Test to_fields_array returns empty array when hide_when_pre_selected applies. + */ + public function test_to_fields_array_returns_empty_when_hidden(): void { + $attributes = array( + 'id' => 'pricing_table', + 'type' => 'pricing_table', + 'name' => 'Plan Selection', + 'pricing_table_products' => '', + 'pricing_table_template' => 'list', + 'force_different_durations' => false, + 'hide_pricing_table_when_pre_selected' => false, + 'wrapper_element_classes' => '', + 'element_classes' => '', + ); + + $this->field->set_attributes( $attributes ); + $fields = $this->field->to_fields_array( $attributes ); + + // With no products, the result should be an array (possibly empty after filtering). + $this->assertIsArray( $fields ); + } + + /** + * Test field is instance of Base_Signup_Field. + */ + public function test_field_is_instance_of_base(): void { + $this->assertInstanceOf( Base_Signup_Field::class, $this->field ); + } +} diff --git a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Products_Test.php b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Products_Test.php new file mode 100644 index 000000000..d83cd246b --- /dev/null +++ b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Products_Test.php @@ -0,0 +1,192 @@ +field = new Signup_Field_Products(); + } + + /** + * Test get_type returns products. + */ + public function test_get_type(): void { + $this->assertEquals( 'products', $this->field->get_type() ); + } + + /** + * Test is_required returns false. + */ + public function test_is_required(): void { + $this->assertFalse( $this->field->is_required() ); + } + + /** + * Test get_title returns non-empty string. + */ + public function test_get_title(): void { + $title = $this->field->get_title(); + $this->assertIsString( $title ); + $this->assertNotEmpty( $title ); + } + + /** + * Test get_description returns non-empty string. + */ + public function test_get_description(): void { + $description = $this->field->get_description(); + $this->assertIsString( $description ); + $this->assertNotEmpty( $description ); + } + + /** + * Test get_tooltip returns non-empty string. + */ + public function test_get_tooltip(): void { + $tooltip = $this->field->get_tooltip(); + $this->assertIsString( $tooltip ); + $this->assertNotEmpty( $tooltip ); + } + + /** + * Test get_icon returns dashicon class. + */ + public function test_get_icon(): void { + $icon = $this->field->get_icon(); + $this->assertIsString( $icon ); + $this->assertStringContainsString( 'dashicons', $icon ); + } + + /** + * Test is_user_field returns false by default. + */ + public function test_is_user_field(): void { + $this->assertFalse( $this->field->is_user_field() ); + } + + /** + * Test is_site_field returns false by default. + */ + public function test_is_site_field(): void { + $this->assertFalse( $this->field->is_site_field() ); + } + + /** + * Test defaults returns an array. + */ + public function test_defaults(): void { + $defaults = $this->field->defaults(); + $this->assertIsArray( $defaults ); + } + + /** + * Test default_fields returns empty array. + */ + public function test_default_fields(): void { + $fields = $this->field->default_fields(); + $this->assertIsArray( $fields ); + $this->assertEmpty( $fields ); + } + + /** + * Test force_attributes returns id = products and name. + */ + public function test_force_attributes(): void { + $attrs = $this->field->force_attributes(); + $this->assertIsArray( $attrs ); + $this->assertArrayHasKey( 'id', $attrs ); + $this->assertEquals( 'products', $attrs['id'] ); + $this->assertArrayHasKey( 'name', $attrs ); + $this->assertIsString( $attrs['name'] ); + } + + /** + * Test get_fields returns array with products key. + */ + public function test_get_fields(): void { + $fields = $this->field->get_fields(); + $this->assertIsArray( $fields ); + $this->assertArrayHasKey( 'products', $fields ); + } + + /** + * Test get_fields products is model type. + */ + public function test_get_fields_products_is_model_type(): void { + $fields = $this->field->get_fields(); + $this->assertEquals( 'model', $fields['products']['type'] ); + } + + /** + * Test get_fields products has html_attr with data-model. + */ + public function test_get_fields_products_has_data_model_attr(): void { + $fields = $this->field->get_fields(); + $this->assertArrayHasKey( 'html_attr', $fields['products'] ); + $this->assertArrayHasKey( 'data-model', $fields['products']['html_attr'] ); + $this->assertEquals( 'product', $fields['products']['html_attr']['data-model'] ); + } + + /** + * Test to_fields_array returns hidden fields for each product. + */ + public function test_to_fields_array_returns_hidden_fields(): void { + $attributes = array( + 'id' => 'products', + 'name' => 'Pre-selected Products', + 'products' => '1,2', + ); + + $this->field->set_attributes( $attributes ); + $fields = $this->field->to_fields_array( $attributes ); + + $this->assertIsArray( $fields ); + $this->assertArrayHasKey( 'products[1]', $fields ); + $this->assertArrayHasKey( 'products[2]', $fields ); + } + + /** + * Test to_fields_array hidden fields have correct type and value. + */ + public function test_to_fields_array_hidden_field_structure(): void { + $attributes = array( + 'id' => 'products', + 'name' => 'Pre-selected Products', + 'products' => '42', + ); + + $this->field->set_attributes( $attributes ); + $fields = $this->field->to_fields_array( $attributes ); + + $this->assertArrayHasKey( 'products[42]', $fields ); + $this->assertEquals( 'hidden', $fields['products[42]']['type'] ); + $this->assertEquals( '42', $fields['products[42]']['value'] ); + } + + /** + * Test field is instance of Base_Signup_Field. + */ + public function test_field_is_instance_of_base(): void { + $this->assertInstanceOf( Base_Signup_Field::class, $this->field ); + } +} diff --git a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Steps_Test.php b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Steps_Test.php new file mode 100644 index 000000000..d6ae76fd3 --- /dev/null +++ b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Steps_Test.php @@ -0,0 +1,166 @@ +field = new Signup_Field_Steps(); + } + + /** + * Test get_type returns steps. + */ + public function test_get_type(): void { + $this->assertEquals( 'steps', $this->field->get_type() ); + } + + /** + * Test is_required returns false. + */ + public function test_is_required(): void { + $this->assertFalse( $this->field->is_required() ); + } + + /** + * Test get_title returns non-empty string. + */ + public function test_get_title(): void { + $title = $this->field->get_title(); + $this->assertIsString( $title ); + $this->assertNotEmpty( $title ); + } + + /** + * Test get_description returns non-empty string. + */ + public function test_get_description(): void { + $description = $this->field->get_description(); + $this->assertIsString( $description ); + $this->assertNotEmpty( $description ); + } + + /** + * Test get_tooltip returns non-empty string. + */ + public function test_get_tooltip(): void { + $tooltip = $this->field->get_tooltip(); + $this->assertIsString( $tooltip ); + $this->assertNotEmpty( $tooltip ); + } + + /** + * Test get_icon returns dashicon class. + */ + public function test_get_icon(): void { + $icon = $this->field->get_icon(); + $this->assertIsString( $icon ); + $this->assertStringContainsString( 'dashicons', $icon ); + } + + /** + * Test is_user_field returns false by default. + */ + public function test_is_user_field(): void { + $this->assertFalse( $this->field->is_user_field() ); + } + + /** + * Test is_site_field returns false by default. + */ + public function test_is_site_field(): void { + $this->assertFalse( $this->field->is_site_field() ); + } + + /** + * Test defaults returns expected keys. + */ + public function test_defaults(): void { + $defaults = $this->field->defaults(); + $this->assertIsArray( $defaults ); + $this->assertArrayHasKey( 'steps_template', $defaults ); + $this->assertEquals( 'clean', $defaults['steps_template'] ); + } + + /** + * Test default_fields returns empty array. + */ + public function test_default_fields(): void { + $fields = $this->field->default_fields(); + $this->assertIsArray( $fields ); + $this->assertEmpty( $fields ); + } + + /** + * Test force_attributes returns id = steps. + */ + public function test_force_attributes(): void { + $attrs = $this->field->force_attributes(); + $this->assertIsArray( $attrs ); + $this->assertArrayHasKey( 'id', $attrs ); + $this->assertEquals( 'steps', $attrs['id'] ); + } + + /** + * Test get_fields returns array with steps_template key. + */ + public function test_get_fields(): void { + $fields = $this->field->get_fields(); + $this->assertIsArray( $fields ); + $this->assertArrayHasKey( 'steps_template', $fields ); + } + + /** + * Test get_fields steps_template is group type. + */ + public function test_get_fields_steps_template_is_group(): void { + $fields = $this->field->get_fields(); + $this->assertEquals( 'group', $fields['steps_template']['type'] ); + $this->assertArrayHasKey( 'fields', $fields['steps_template'] ); + } + + /** + * Test get_fields steps_template group contains steps_template select. + */ + public function test_get_fields_steps_template_group_has_select(): void { + $fields = $this->field->get_fields(); + $group_fields = $fields['steps_template']['fields']; + + $this->assertArrayHasKey( 'steps_template', $group_fields ); + $this->assertEquals( 'select', $group_fields['steps_template']['type'] ); + } + + /** + * Test get_templates returns array. + */ + public function test_get_templates(): void { + $templates = $this->field->get_templates(); + $this->assertIsArray( $templates ); + } + + /** + * Test field is instance of Base_Signup_Field. + */ + public function test_field_is_instance_of_base(): void { + $this->assertInstanceOf( Base_Signup_Field::class, $this->field ); + } +} diff --git a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Terms_Of_Use_Test.php b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Terms_Of_Use_Test.php new file mode 100644 index 000000000..fb425a139 --- /dev/null +++ b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Terms_Of_Use_Test.php @@ -0,0 +1,232 @@ +field = new Signup_Field_Terms_Of_Use(); + } + + /** + * Test get_type returns terms_of_use. + */ + public function test_get_type(): void { + $this->assertEquals( 'terms_of_use', $this->field->get_type() ); + } + + /** + * Test is_required returns false. + */ + public function test_is_required(): void { + $this->assertFalse( $this->field->is_required() ); + } + + /** + * Test is_user_field returns false. + */ + public function test_is_user_field(): void { + $this->assertFalse( $this->field->is_user_field() ); + } + + /** + * Test is_site_field returns false. + */ + public function test_is_site_field(): void { + $this->assertFalse( $this->field->is_site_field() ); + } + + /** + * Test get_title returns non-empty string. + */ + public function test_get_title(): void { + $title = $this->field->get_title(); + $this->assertIsString( $title ); + $this->assertNotEmpty( $title ); + } + + /** + * Test get_description returns non-empty string. + */ + public function test_get_description(): void { + $description = $this->field->get_description(); + $this->assertIsString( $description ); + $this->assertNotEmpty( $description ); + } + + /** + * Test get_tooltip returns non-empty string. + */ + public function test_get_tooltip(): void { + $tooltip = $this->field->get_tooltip(); + $this->assertIsString( $tooltip ); + $this->assertNotEmpty( $tooltip ); + } + + /** + * Test get_icon returns dashicon class. + */ + public function test_get_icon(): void { + $icon = $this->field->get_icon(); + $this->assertIsString( $icon ); + $this->assertStringContainsString( 'dashicons', $icon ); + } + + /** + * Test defaults returns tou_name key with non-empty string. + */ + public function test_defaults(): void { + $defaults = $this->field->defaults(); + $this->assertIsArray( $defaults ); + $this->assertArrayHasKey( 'tou_name', $defaults ); + $this->assertIsString( $defaults['tou_name'] ); + $this->assertNotEmpty( $defaults['tou_name'] ); + } + + /** + * Test default_fields returns empty array. + */ + public function test_default_fields(): void { + $fields = $this->field->default_fields(); + $this->assertIsArray( $fields ); + $this->assertEmpty( $fields ); + } + + /** + * Test force_attributes returns id = terms_of_use and name. + */ + public function test_force_attributes(): void { + $attrs = $this->field->force_attributes(); + $this->assertIsArray( $attrs ); + $this->assertArrayHasKey( 'id', $attrs ); + $this->assertEquals( 'terms_of_use', $attrs['id'] ); + $this->assertArrayHasKey( 'name', $attrs ); + $this->assertIsString( $attrs['name'] ); + } + + /** + * Test get_fields returns array with tou_name and tou_url keys. + */ + public function test_get_fields(): void { + $fields = $this->field->get_fields(); + $this->assertIsArray( $fields ); + $this->assertArrayHasKey( 'tou_name', $fields ); + $this->assertArrayHasKey( 'tou_url', $fields ); + } + + /** + * Test get_fields tou_name is text type. + */ + public function test_get_fields_tou_name_is_text(): void { + $fields = $this->field->get_fields(); + $this->assertEquals( 'text', $fields['tou_name']['type'] ); + } + + /** + * Test get_fields tou_url is url type. + */ + public function test_get_fields_tou_url_is_url(): void { + $fields = $this->field->get_fields(); + $this->assertEquals( 'url', $fields['tou_url']['type'] ); + } + + /** + * Test to_fields_array returns terms_of_use checkbox field. + */ + public function test_to_fields_array_returns_checkbox(): void { + $attributes = array( + 'id' => 'terms_of_use', + 'name' => 'Terms of Use', + 'tou_name' => 'I agree with the terms of use.', + 'tou_url' => 'https://example.com/terms', + 'element_classes' => '', + ); + + $this->field->set_attributes( $attributes ); + $fields = $this->field->to_fields_array( $attributes ); + + $this->assertIsArray( $fields ); + $this->assertArrayHasKey( 'terms_of_use', $fields ); + $this->assertEquals( 'checkbox', $fields['terms_of_use']['type'] ); + } + + /** + * Test to_fields_array checkbox is required. + */ + public function test_to_fields_array_checkbox_is_required(): void { + $attributes = array( + 'id' => 'terms_of_use', + 'name' => 'Terms of Use', + 'tou_name' => 'I agree with the terms of use.', + 'tou_url' => 'https://example.com/terms', + 'element_classes' => '', + ); + + $this->field->set_attributes( $attributes ); + $fields = $this->field->to_fields_array( $attributes ); + + $this->assertTrue( $fields['terms_of_use']['required'] ); + } + + /** + * Test to_fields_array desc contains tou_url link. + */ + public function test_to_fields_array_desc_contains_tou_url(): void { + $attributes = array( + 'id' => 'terms_of_use', + 'name' => 'Terms of Use', + 'tou_name' => 'I agree with the terms of use.', + 'tou_url' => 'https://example.com/terms', + 'element_classes' => '', + ); + + $this->field->set_attributes( $attributes ); + $fields = $this->field->to_fields_array( $attributes ); + + $this->assertStringContainsString( 'https://example.com/terms', $fields['terms_of_use']['desc'] ); + } + + /** + * Test to_fields_array name contains tou_name value. + */ + public function test_to_fields_array_name_contains_tou_name(): void { + $attributes = array( + 'id' => 'terms_of_use', + 'name' => 'Terms of Use', + 'tou_name' => 'I agree with the terms of use.', + 'tou_url' => 'https://example.com/terms', + 'element_classes' => '', + ); + + $this->field->set_attributes( $attributes ); + $fields = $this->field->to_fields_array( $attributes ); + + $this->assertStringContainsString( 'I agree with the terms of use.', $fields['terms_of_use']['name'] ); + } + + /** + * Test field is instance of Base_Signup_Field. + */ + public function test_field_is_instance_of_base(): void { + $this->assertInstanceOf( Base_Signup_Field::class, $this->field ); + } +} From ce49a1f880ba43ebbdf968e9a8ab2550948023c8 Mon Sep 17 00:00:00 2001 From: David Stone Date: Sun, 29 Mar 2026 00:46:29 -0600 Subject: [PATCH 2/2] test(signup-fields): rename misleading test in Pricing_Table_Test Rename test_to_fields_array_returns_empty_when_hidden to test_to_fields_array_returns_empty_when_no_products to accurately reflect what is being tested (no products configured, not the hide-when-pre-selected path). Addresses CodeRabbit review feedback. --- .../Signup_Fields/Signup_Field_Pricing_Table_Test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Pricing_Table_Test.php b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Pricing_Table_Test.php index f6b0c10b9..39b37f781 100644 --- a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Pricing_Table_Test.php +++ b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Pricing_Table_Test.php @@ -183,9 +183,9 @@ public function test_get_pricing_table_templates(): void { } /** - * Test to_fields_array returns empty array when hide_when_pre_selected applies. + * Test to_fields_array returns empty array when no products are configured. */ - public function test_to_fields_array_returns_empty_when_hidden(): void { + public function test_to_fields_array_returns_empty_when_no_products(): void { $attributes = array( 'id' => 'pricing_table', 'type' => 'pricing_table', @@ -201,7 +201,7 @@ public function test_to_fields_array_returns_empty_when_hidden(): void { $this->field->set_attributes( $attributes ); $fields = $this->field->to_fields_array( $attributes ); - // With no products, the result should be an array (possibly empty after filtering). + // With no valid products, the result should be an array with one note field (template rendered). $this->assertIsArray( $fields ); }