@@ -95,6 +95,74 @@ public function test_webhook_post_no_url() {
9595 $ this ->assertNull ( $ response );
9696 }
9797
98+ /**
99+ * Test formscrm_send_webhook ID extraction from different formats.
100+ *
101+ * Test that the function correctly extracts numeric ID from:
102+ * - Plain number: '22222'
103+ * - Pipe-separated with text: 'Lead 32132|Deal 22222'
104+ * - Text prefix: 'Deal 22222'
105+ * - Spanish text prefix: 'Oportunidad 22222'
106+ */
107+ public function test_webhook_id_extraction () {
108+ $ settings = array ( 'fc_crm_webhook ' => 'https://webhook.com/test ' );
109+
110+ // Test Case 1: Plain numeric ID.
111+ $ response_api = array (
112+ 'status ' => 'ok ' ,
113+ 'message ' => 'success ' ,
114+ 'module ' => 'deal ' ,
115+ 'id ' => '22222 ' ,
116+ );
117+ $ response = formscrm_send_webhook ( $ settings , $ response_api );
118+ $ this ->assertEquals ( 22222 , $ response ['request ' ]['data ' ]['id ' ] );
119+ $ this ->assertIsInt ( $ response ['request ' ]['data ' ]['id ' ] );
120+
121+ // Test Case 2: Pipe-separated IDs with text prefix (Lead 32132|Deal 22222).
122+ $ response_api = array (
123+ 'status ' => 'ok ' ,
124+ 'message ' => 'success ' ,
125+ 'module ' => 'deal ' ,
126+ 'id ' => 'Lead 32132|Deal 22222 ' ,
127+ );
128+ $ response = formscrm_send_webhook ( $ settings , $ response_api );
129+ $ this ->assertEquals ( 22222 , $ response ['request ' ]['data ' ]['id ' ] );
130+ $ this ->assertIsInt ( $ response ['request ' ]['data ' ]['id ' ] );
131+
132+ // Test Case 3: Single ID with text prefix (Deal 22222).
133+ $ response_api = array (
134+ 'status ' => 'ok ' ,
135+ 'message ' => 'success ' ,
136+ 'module ' => 'deal ' ,
137+ 'id ' => 'Deal 22222 ' ,
138+ );
139+ $ response = formscrm_send_webhook ( $ settings , $ response_api );
140+ $ this ->assertEquals ( 22222 , $ response ['request ' ]['data ' ]['id ' ] );
141+ $ this ->assertIsInt ( $ response ['request ' ]['data ' ]['id ' ] );
142+
143+ // Test Case 4: Spanish text prefix (Oportunidad 22222).
144+ $ response_api = array (
145+ 'status ' => 'ok ' ,
146+ 'message ' => 'success ' ,
147+ 'module ' => 'deal ' ,
148+ 'id ' => 'Oportunidad 22222 ' ,
149+ );
150+ $ response = formscrm_send_webhook ( $ settings , $ response_api );
151+ $ this ->assertEquals ( 22222 , $ response ['request ' ]['data ' ]['id ' ] );
152+ $ this ->assertIsInt ( $ response ['request ' ]['data ' ]['id ' ] );
153+
154+ // Test Case 5: Multiple pipe-separated with different numbers.
155+ $ response_api = array (
156+ 'status ' => 'ok ' ,
157+ 'message ' => 'success ' ,
158+ 'module ' => 'deal ' ,
159+ 'id ' => 'Contact 11111|Lead 99999|Deal 22222 ' ,
160+ );
161+ $ response = formscrm_send_webhook ( $ settings , $ response_api );
162+ $ this ->assertEquals ( 22222 , $ response ['request ' ]['data ' ]['id ' ] );
163+ $ this ->assertIsInt ( $ response ['request ' ]['data ' ]['id ' ] );
164+ }
165+
98166 /**
99167 * Test formscrm_debug_message with WP_DEBUG enabled.
100168 */
0 commit comments