@@ -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