@@ -202,6 +202,52 @@ public function test_send_summary_notifications_records_history_and_throttles():
202202 $ this ->assertSame ('throttled ' , $ history [3 ]['status ' ]);
203203 }
204204
205+ public function test_send_summary_notifications_records_failed_email_when_wp_mail_returns_false (): void
206+ {
207+ $ testCase = $ this ;
208+
209+ Functions \when ('wp_mail ' )->alias (static function ($ recipients , $ subject , $ message ) use ($ testCase ) {
210+ $ testCase ->sentEmails [] = array (
211+ 'recipients ' => $ recipients ,
212+ 'subject ' => $ subject ,
213+ 'message ' => $ message ,
214+ );
215+
216+ return false ;
217+ });
218+
219+ $ manager = new NotificationManager (static function () {
220+ return 1500 ;
221+ });
222+
223+ $ summary = array (
224+ 'subject ' => 'Résumé ' ,
225+ 'message ' => 'Contenu ' ,
226+ 'dataset_label ' => 'Analyse des liens ' ,
227+ );
228+
229+ $ recipients = array ('admin@example.test ' );
230+ $ settings = array ('url ' => 'https://hooks.example.test ' , 'channel ' => 'slack ' );
231+
232+ $ result = $ manager ->sendSummaryNotifications ('link ' , $ summary , $ recipients , array (
233+ 'context ' => 'scan ' ,
234+ 'webhook_settings ' => $ settings ,
235+ ));
236+
237+ $ failureMessage = 'Échec de l’envoi de l’e-mail pour l’analyse Analyse des liens. ' ;
238+
239+ $ this ->assertSame ('failed ' , $ result ['email ' ]['status ' ]);
240+ $ this ->assertSame ($ failureMessage , $ result ['email ' ]['error ' ]);
241+ $ this ->assertCount (1 , $ this ->errorLogs );
242+ $ this ->assertStringContainsString ('Failed to send link summary email ' , $ this ->errorLogs [0 ]);
243+
244+ $ history = $ manager ->getHistoryEntries ();
245+ $ this ->assertCount (2 , $ history );
246+ $ this ->assertSame ('failed ' , $ history [0 ]['status ' ]);
247+ $ this ->assertSame ('email ' , $ history [0 ]['channel ' ]);
248+ $ this ->assertSame ($ failureMessage , $ history [0 ]['error ' ]);
249+ }
250+
205251 public function test_send_webhook_only_returns_wp_error_on_failure_and_logs_history (): void
206252 {
207253 $ this ->throttleWindow = 0 ;
0 commit comments