assertCount(2, $rows); $this->assertSame('a@example.com', $rows[0]['rcpt']); $this->assertSame('b@example.com', $rows[1]['rcpt']); foreach ($rows as $r) { $this->assertSame('Hello', $r['subject']); $this->assertSame("Body\ntext", $r['body']); $this->assertSame(5, (int)$r['configid']); } } public function testFlushQueueDropsTooOldMailsAndDeletesWithoutSending(): void { $tooOld = time() - 50000; // older than 12h cutoff used in flushQueue Database::exec('INSERT INTO mail_queue (configid, rcpt, subject, body, dateline, nexttry) VALUES (:configid, :rcpt, :subject, :body, :dateline, 0)', [ 'configid' => 1, 'rcpt' => 'user@example.org', 'subject' => 'Old Notice', 'body' => 'Old body', 'dateline' => $tooOld, ]); Mailer::flushQueue(); $cnt = Database::queryFirst('SELECT COUNT(*) AS c FROM mail_queue'); $this->assertSame(0, (int)$cnt['c'], 'Too-old mails should be deleted'); // EventLog::info should contain the drop message $this->assertNotEmpty(EventLog::$info); $this->assertStringContainsString('Dropping queued mail', EventLog::$info[0][0]); } public function testFlushQueueWithInvalidConfigLogsFailureAndDeletes(): void { $recent = time(); // Insert one recent mail referencing a non-existent config (42) Database::exec('INSERT INTO mail_queue (configid, rcpt, subject, body, dateline, nexttry) VALUES (:configid, :rcpt, :subject, :body, :dateline, 0)', [ 'configid' => 42, 'rcpt' => 'rcpt@example.org', 'subject' => 'Test Subject', 'body' => 'First body', 'dateline' => $recent, ]); Mailer::flushQueue(); // Should log one failure about invalid config id $this->assertNotEmpty(EventLog::$failure); $this->assertStringContainsString('Invalid mailer config id', EventLog::$failure[0]); $cnt = Database::queryFirst('SELECT COUNT(*) AS c FROM mail_queue'); $this->assertSame(0, (int)$cnt['c'], 'Mail should be deleted when config is invalid'); } }