@@ -910,4 +910,42 @@ public function test_checkout_plan_plus_addon_preserves_templates(): void {
910910 // Disk space should be additive
911911 $ this ->assertEquals (600 , $ limits ->disk_space ->get_limit (), 'Disk space should be summed ' );
912912 }
913+
914+ /**
915+ * Test that get_available_site_templates returns integers, not strings.
916+ *
917+ * Regression test for issue #351: When template IDs are stored as string keys
918+ * in the limit array, they must be converted to integers for proper comparison
919+ * in the Site_Template validation rule.
920+ */
921+ public function test_available_site_templates_returns_integers (): void {
922+
923+ $ limitations = new Limitations ([
924+ 'site_templates ' => [
925+ 'enabled ' => true ,
926+ 'mode ' => 'choose_available_templates ' ,
927+ 'limit ' => [
928+ '123 ' => ['behavior ' => 'available ' ],
929+ '456 ' => ['behavior ' => 'pre_selected ' ],
930+ '789 ' => ['behavior ' => 'not_available ' ],
931+ ],
932+ ],
933+ ]);
934+
935+ $ available = $ limitations ->site_templates ->get_available_site_templates ();
936+
937+ // Should return integers, not strings
938+ $ this ->assertContains (123 , $ available , 'Template 123 should be in available array as integer ' );
939+ $ this ->assertContains (456 , $ available , 'Template 456 should be in available array as integer ' );
940+ $ this ->assertNotContains (789 , $ available , 'Template 789 should not be available ' );
941+
942+ // Verify strict type checking
943+ foreach ($ available as $ template_id ) {
944+ $ this ->assertIsInt ($ template_id , 'All template IDs should be integers ' );
945+ }
946+
947+ // Verify in_array works with strict comparison
948+ $ this ->assertTrue (in_array (123 , $ available , true ), 'in_array with strict=true should find integer 123 ' );
949+ $ this ->assertTrue (in_array (456 , $ available , true ), 'in_array with strict=true should find integer 456 ' );
950+ }
913951}
0 commit comments