From 101da5cdbc661002c5bec92c1eec2f3ecb9b2898 Mon Sep 17 00:00:00 2001 From: thangnn Date: Wed, 27 Nov 2024 22:40:53 +0700 Subject: [PATCH] Add unitTest_MailMessageMailer_sendFormToUser --- .../bc-mail/src/Mailer/MailMessageMailer.php | 1 + .../TestCase/Mailer/MailMessageMailerTest.php | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/plugins/bc-mail/src/Mailer/MailMessageMailer.php b/plugins/bc-mail/src/Mailer/MailMessageMailer.php index ce71d40859..2251552ef9 100644 --- a/plugins/bc-mail/src/Mailer/MailMessageMailer.php +++ b/plugins/bc-mail/src/Mailer/MailMessageMailer.php @@ -88,6 +88,7 @@ public function sendFormToAdmin( * @param array $options * @checked * @noTodo + * @unitTest */ public function sendFormToUser( EntityInterface $mailContent, diff --git a/plugins/bc-mail/tests/TestCase/Mailer/MailMessageMailerTest.php b/plugins/bc-mail/tests/TestCase/Mailer/MailMessageMailerTest.php index a2b6873d43..3443f9ae64 100644 --- a/plugins/bc-mail/tests/TestCase/Mailer/MailMessageMailerTest.php +++ b/plugins/bc-mail/tests/TestCase/Mailer/MailMessageMailerTest.php @@ -87,7 +87,33 @@ public function testSendFormToAdmin() */ public function testSendFormToUser() { - $this->markTestIncomplete('このテストは未実装'); + //準備 + $data['message'] = 'message test'; + $data['mailContent'] = 'content test'; + $data['mailFields'] = 'fields test'; + $mailContent = MailContentFactory::make([ + 'description' => 'description test', + 'sender_1' => 'sender_1', + 'sender_name' => 'name 111', + 'subject_user' => 'subject_user 111', + 'subject_admin' => 'subject_admin 111', + 'form_template' => 'default', + 'mail_template' => 'mail_default', + 'redirect_url' => '/', + ])->getEntity(); + + //テスト + $this->MailMessageMailer->sendFormToUser($mailContent, 'abc@example.com', 'abcUser@example.com', $data, [], []); + + //戻り値を確認 + $this->assertEquals(['abc@example.com' => 'abc@example.com'], $this->MailMessageMailer->getReplyTo()); + $this->assertEquals(['abcUser@example.com' => 'abcUser@example.com'], $this->MailMessageMailer->getTo()); + + $vars = $this->MailMessageMailer->viewBuilder()->getVars(); + $this->assertEquals('message test', $vars['message']); + $this->assertEquals('content test', $vars['mailContent']); + $this->assertEquals('fields test', $vars['mailFields']); + $this->assertEquals('user', $vars['other']['mode']); } /**