@@ -200,6 +200,122 @@ public function test_comment_form_field_comment_appends_fields() {
200200 $ this ->assertStringContainsString ( $ html , $ result , 'Should contain original html ' );
201201 }
202202
203+ /**
204+ * Test admin_enqueue_scripts returns early on non-comment pages.
205+ */
206+ public function test_admin_enqueue_scripts_bails_on_wrong_page () {
207+ $ form_comment = new acf_form_comment ();
208+
209+ // Set pagenow to a non-comment page.
210+ global $ pagenow ;
211+ $ pagenow = 'edit.php ' ; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Test requires setting global.
212+
213+ $ form_comment ->admin_enqueue_scripts ();
214+
215+ // On wrong page, admin_footer action should NOT be added.
216+ $ this ->assertFalse (
217+ has_action ( 'admin_footer ' , array ( $ form_comment , 'admin_footer ' ) ),
218+ 'admin_footer action should not be added on non-comment pages '
219+ );
220+ }
221+
222+ /**
223+ * Test admin_enqueue_scripts adds actions on comment.php.
224+ */
225+ public function test_admin_enqueue_scripts_adds_actions_on_comment_page () {
226+ $ form_comment = new acf_form_comment ();
227+
228+ // Set pagenow to comment.php.
229+ global $ pagenow ;
230+ $ pagenow = 'comment.php ' ; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Test requires setting global.
231+
232+ $ form_comment ->admin_enqueue_scripts ();
233+
234+ // On comment page, admin_footer action should be added.
235+ $ this ->assertNotFalse (
236+ has_action ( 'admin_footer ' , array ( $ form_comment , 'admin_footer ' ) ),
237+ 'admin_footer action should be added on comment.php '
238+ );
239+
240+ // edit_comment action should be added.
241+ $ this ->assertNotFalse (
242+ has_action ( 'add_meta_boxes_comment ' , array ( $ form_comment , 'edit_comment ' ) ),
243+ 'add_meta_boxes_comment action should be added on comment.php '
244+ );
245+ }
246+
247+ /**
248+ * Test edit_comment stores correct form data.
249+ */
250+ public function test_edit_comment_renders_nothing_without_field_groups () {
251+ $ form_comment = new acf_form_comment ();
252+
253+ // Create a mock comment object.
254+ $ comment = new stdClass ();
255+ $ comment ->comment_ID = 123 ;
256+ $ comment ->comment_post_ID = 1 ;
257+
258+ // Ensure no field groups match to avoid rendering.
259+ add_filter (
260+ 'acf/get_field_groups ' ,
261+ function () {
262+ return array ();
263+ }
264+ );
265+
266+ ob_start ();
267+ $ form_comment ->edit_comment ( $ comment );
268+ $ output = ob_get_clean ();
269+
270+ // No output should be generated when no field groups match.
271+ $ this ->assertEmpty ( $ output , 'edit_comment should render nothing without field groups ' );
272+ }
273+
274+ /**
275+ * Test edit_comment uses correct post_id format.
276+ *
277+ * When field groups exist, edit_comment should store form data with
278+ * post_id formatted as "comment_{comment_ID}".
279+ */
280+ public function test_edit_comment_uses_correct_post_id_format () {
281+ $ form_comment = new acf_form_comment ();
282+
283+ // Create a mock comment object.
284+ $ comment = new stdClass ();
285+ $ comment ->comment_ID = 456 ;
286+ $ comment ->comment_post_ID = 1 ;
287+
288+ // Register a real field group to trigger the rendering path.
289+ $ field_group = acf_update_field_group (
290+ array (
291+ 'key ' => 'group_comment_test ' ,
292+ 'title ' => 'Comment Test Group ' ,
293+ 'location ' => array (
294+ array (
295+ array (
296+ 'param ' => 'comment ' ,
297+ 'operator ' => '== ' ,
298+ 'value ' => 'all ' ,
299+ ),
300+ ),
301+ ),
302+ 'instruction_placement ' => 'label ' ,
303+ )
304+ );
305+
306+ // Capture output to prevent it from polluting test output.
307+ ob_start ();
308+ $ form_comment ->edit_comment ( $ comment );
309+ ob_get_clean ();
310+
311+ // Verify form data was stored with correct post_id format.
312+ $ form_data = acf_get_form_data ( 'post_id ' );
313+ $ this ->assertEquals ( 'comment_456 ' , $ form_data , 'post_id should be formatted as comment_{id} ' );
314+
315+ // Cleanup: delete the field group.
316+ acf_delete_field_group ( $ field_group ['ID ' ] );
317+ }
318+
203319 /**
204320 * Test admin_footer outputs spinner JavaScript.
205321 */
0 commit comments