From 3ac8a07a1e99ead7e144261361b7a54ff460d1a2 Mon Sep 17 00:00:00 2001 From: kato Date: Wed, 23 Apr 2025 14:13:28 +0900 Subject: [PATCH] =?UTF-8?q?fix=20#4158=20=E3=80=90=E3=83=A1=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=80=91=E3=83=A1=E3=83=BC=E3=83=AB=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=BC=E3=83=A0=E9=80=81=E4=BF=A1=E5=AE=8C=E4=BA=86=E7=94=BB?= =?UTF-8?q?=E9=9D=A2=E3=83=86=E3=82=AD=E3=82=B9=E3=83=88=E3=82=92=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=8F=AF=E8=83=BD=E3=81=A8=E3=81=99=E3=82=8B=E6=A9=9F?= =?UTF-8?q?=E8=83=BD=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/element/MailContents/form.php | 34 ++++ .../plugin/BcMail/Mail/default/submit.php | 8 +- .../plugin/BcMail/Mail/default/unpublish.php | 8 +- .../20221117021240_CreateMailContents.php | 10 + .../bc-mail/config/Seeds/MailContentsSeed.php | 2 + .../bc-mail/src/Model/Entity/MailContent.php | 2 + .../src/Model/Table/MailContentsTable.php | 24 +++ .../src/View/Helper/BcMailBaserHelper.php | 4 + .../bc-mail/src/View/Helper/MailHelper.php | 82 +++++++++ .../tests/Scenario/MailContentsScenario.php | 4 + .../Api/Admin/MailContentsControllerTest.php | 2 + .../View/Helper/BcMailBaserHelperTest.php | 6 +- .../TestCase/View/Helper/MailHelperTest.php | 174 ++++++++++++++++++ 13 files changed, 356 insertions(+), 4 deletions(-) diff --git a/plugins/bc-admin-third/templates/plugin/BcMail/Admin/element/MailContents/form.php b/plugins/bc-admin-third/templates/plugin/BcMail/Admin/element/MailContents/form.php index de8d8c1f3d..9035138d31 100644 --- a/plugins/bc-admin-third/templates/plugin/BcMail/Admin/element/MailContents/form.php +++ b/plugins/bc-admin-third/templates/plugin/BcMail/Admin/element/MailContents/form.php @@ -39,6 +39,40 @@ +
+ + + BcAdminForm->ckeditor('thanks', [ + 'editorWidth' => 'auto', + 'editorHeight' => '120px', + 'editorToolType' => 'simple', + 'editorEnterBr' => $editorEnterBr + ]) + ?> + BcAdminForm->error('thanks') ?> + +
+ +
+ + + BcAdminForm->ckeditor('unpublish', [ + 'editorWidth' => 'auto', + 'editorHeight' => '120px', + 'editorToolType' => 'simple', + 'editorEnterBr' => $editorEnterBr + ]) + ?> + BcAdminForm->error('unpublish') ?> + +
+
diff --git a/plugins/bc-front/templates/plugin/BcMail/Mail/default/submit.php b/plugins/bc-front/templates/plugin/BcMail/Mail/default/submit.php index 55a8225761..f556955b98 100755 --- a/plugins/bc-front/templates/plugin/BcMail/Mail/default/submit.php +++ b/plugins/bc-front/templates/plugin/BcMail/Mail/default/submit.php @@ -34,8 +34,12 @@

-

-

+ BcBaser->mailFormThanksExists()): ?> + BcBaser->mailFormThanks() ?> + +

+

+ BcBaser->isDebug() && $mailContent->redirect_url): ?>

diff --git a/plugins/bc-front/templates/plugin/BcMail/Mail/default/unpublish.php b/plugins/bc-front/templates/plugin/BcMail/Mail/default/unpublish.php index f41a865f07..27d34b59eb 100755 --- a/plugins/bc-front/templates/plugin/BcMail/Mail/default/unpublish.php +++ b/plugins/bc-front/templates/plugin/BcMail/Mail/default/unpublish.php @@ -23,4 +23,10 @@

-

+
+ BcBaser->mailFormUnpublishExists()): ?> + BcBaser->mailFormUnpublish() ?> + +

+ +
diff --git a/plugins/bc-mail/config/Migrations/20221117021240_CreateMailContents.php b/plugins/bc-mail/config/Migrations/20221117021240_CreateMailContents.php index df72c33386..e55ac8feb9 100644 --- a/plugins/bc-mail/config/Migrations/20221117021240_CreateMailContents.php +++ b/plugins/bc-mail/config/Migrations/20221117021240_CreateMailContents.php @@ -22,6 +22,16 @@ public function up() 'limit' => null, 'null' => true, ]) + ->addColumn('thanks', 'text', [ + 'default' => null, + 'limit' => null, + 'null' => true, + ]) + ->addColumn('unpublish', 'text', [ + 'default' => null, + 'limit' => null, + 'null' => true, + ]) ->addColumn('sender_1', 'text', [ 'default' => null, 'limit' => null, diff --git a/plugins/bc-mail/config/Seeds/MailContentsSeed.php b/plugins/bc-mail/config/Seeds/MailContentsSeed.php index 0ddb8b8224..41865b1659 100644 --- a/plugins/bc-mail/config/Seeds/MailContentsSeed.php +++ b/plugins/bc-mail/config/Seeds/MailContentsSeed.php @@ -24,6 +24,8 @@ public function run(): void [ 'id' => 1, 'description' => '

このコンテンツはメールフォーム機能により作られており、この文章については管理画面の [お問い合わせ] → [設定] より更新ができます。また、メールフォームは [コンテンツ管理] よりいくつでも作成することができます。

', + 'thanks' => '

お問い合わせ頂きありがとうございました。
確認次第、ご連絡させて頂きます。

', + 'unpublish' => '

現在、受付を中止しています。

', 'sender_1' => '', 'sender_2' => '', 'sender_name' => 'baserCMSサンプル', diff --git a/plugins/bc-mail/src/Model/Entity/MailContent.php b/plugins/bc-mail/src/Model/Entity/MailContent.php index 5babb22437..4539f0586a 100755 --- a/plugins/bc-mail/src/Model/Entity/MailContent.php +++ b/plugins/bc-mail/src/Model/Entity/MailContent.php @@ -24,6 +24,8 @@ * Class MailContent * @property int $id * @property string $description + * @property string $thanks + * @property string $unpublish * @property string $sender_1 * @property string $sender_2 * @property string $sender_name diff --git a/plugins/bc-mail/src/Model/Table/MailContentsTable.php b/plugins/bc-mail/src/Model/Table/MailContentsTable.php index 854f16bb40..dba6cf2441 100755 --- a/plugins/bc-mail/src/Model/Table/MailContentsTable.php +++ b/plugins/bc-mail/src/Model/Table/MailContentsTable.php @@ -157,6 +157,30 @@ public function validationDefault(Validator $validator): Validator ] ]); + // thanks + $validator + ->scalar('thanks') + ->allowEmptyString('thanks') + ->add('thanks', [ + 'containsScript' => [ + 'rule' => ['containsScript'], + 'provider' => 'bc', + 'message' => __d('baser_core', '送信完了文でスクリプトの入力は許可されていません。') + ] + ]); + + // unpublish + $validator + ->scalar('unpublish') + ->allowEmptyString('unpublish') + ->add('unpublish', [ + 'containsScript' => [ + 'rule' => ['containsScript'], + 'provider' => 'bc', + 'message' => __d('baser_core', '受付中止文でスクリプトの入力は許可されていません。') + ] + ]); + // publish_end $validator ->add('publish_end', [ diff --git a/plugins/bc-mail/src/View/Helper/BcMailBaserHelper.php b/plugins/bc-mail/src/View/Helper/BcMailBaserHelper.php index d5e509ccf6..915e9cb5a2 100644 --- a/plugins/bc-mail/src/View/Helper/BcMailBaserHelper.php +++ b/plugins/bc-mail/src/View/Helper/BcMailBaserHelper.php @@ -49,6 +49,10 @@ public function methods(): array 'isMail' => ['Mail', 'isMail'], 'mailFormDescriptionExists' => ['Mail', 'descriptionExists'], 'mailFormDescription' => ['Mail', 'description'], + 'mailFormThanksExists' => ['Mail', 'thanksExists'], + 'mailFormThanks' => ['Mail', 'thanks'], + 'mailFormUnpublishExists' => ['Mail', 'unpublishExists'], + 'mailFormUnpublish' => ['Mail', 'unpublish'], 'freezeMailForm' => ['Mailform', 'freeze'], 'createMailForm' => ['Mailform', 'create'], 'mailFormHidden' => ['Mailform', 'hidden'], diff --git a/plugins/bc-mail/src/View/Helper/MailHelper.php b/plugins/bc-mail/src/View/Helper/MailHelper.php index 72e0fc871c..61427cd8e5 100755 --- a/plugins/bc-mail/src/View/Helper/MailHelper.php +++ b/plugins/bc-mail/src/View/Helper/MailHelper.php @@ -211,6 +211,88 @@ public function descriptionExists() return true; } + /** + * メールフォームの送信完了文を取得する + * @return string メールフォームの送信完了文 + * @checked + * @noTodo + * @unitTest + */ + public function getThanks() + { + return $this->currentMailContent->thanks; + } + + /** + * メールの送信完了文を出力する + * + * @return void + * @checked + * @noTodo + * @unitTest ラッパーのためテスト不要 + */ + public function thanks() + { + echo $this->getThanks(); + } + + /** + * メールの送信完了文が設定されているかどうかを判定する + * + * @return boolean 設定されている場合 true を返す + * @checked + * @noTodo + * @unitTest + */ + public function thanksExists() + { + if (empty($this->currentMailContent->thanks)) { + return false; + } + return true; + } + + /** + * メールフォームの受付停止文を取得する + * @return string メールフォームの受付停止文 + * @checked + * @noTodo + * @unitTest + */ + public function getUnpublish() + { + return $this->currentMailContent->unpublish; + } + + /** + * メールの受付停止文を出力する + * + * @return void + * @checked + * @noTodo + * @unitTest ラッパーのためテスト不要 + */ + public function unpublish() + { + echo $this->getUnpublish(); + } + + /** + * メールの受付停止文が設定されているかどうかを判定する + * + * @return boolean 設定されている場合 true を返す + * @checked + * @noTodo + * @unitTest + */ + public function unpublishExists() + { + if (empty($this->currentMailContent->unpublish)) { + return false; + } + return true; + } + /** * メールフォームへのリンクを生成する * $contentsNameはコンテンツ管理上の1階層のみ対応 diff --git a/plugins/bc-mail/tests/Scenario/MailContentsScenario.php b/plugins/bc-mail/tests/Scenario/MailContentsScenario.php index f07ee65e87..91830e4e97 100644 --- a/plugins/bc-mail/tests/Scenario/MailContentsScenario.php +++ b/plugins/bc-mail/tests/Scenario/MailContentsScenario.php @@ -54,6 +54,8 @@ public function load(...$args): mixed MailContentFactory::make([ 'id' => 1, 'description' => 'description test', + 'thanks' => 'thanks test', + 'unpublish' => 'unpublish test', 'sender_name' => 'baserCMSサンプル', 'subject_user' => '【baserCMS】お問い合わせ頂きありがとうございます。', 'subject_admin' => '【baserCMS】お問い合わせを受け付けました', @@ -80,6 +82,8 @@ public function load(...$args): mixed MailContentFactory::make([ 'description' => 'description test 2', + 'thanks' => 'thanks test 2', + 'unpublish' => 'unpublish test 2', 'sender_name' => '送信先名を入力してください', 'subject_user' => 'お問い合わせ頂きありがとうございます', 'subject_admin' => 'お問い合わせを頂きました', diff --git a/plugins/bc-mail/tests/TestCase/Controller/Api/Admin/MailContentsControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Api/Admin/MailContentsControllerTest.php index 47d9aa4bec..ef194e091d 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Api/Admin/MailContentsControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Api/Admin/MailContentsControllerTest.php @@ -70,6 +70,8 @@ public function testView() // 戻る値を確認 $result = json_decode((string)$this->_response->getBody()); $this->assertEquals('description test', $result->mailContent->description); + $this->assertEquals('thanks test', $result->mailContent->thanks); + $this->assertEquals('unpublish test', $result->mailContent->unpublish); $this->assertEquals('baserCMSサンプル', $result->mailContent->sender_name); $this->assertEquals('【baserCMS】お問い合わせ頂きありがとうございます。', $result->mailContent->subject_user); } diff --git a/plugins/bc-mail/tests/TestCase/View/Helper/BcMailBaserHelperTest.php b/plugins/bc-mail/tests/TestCase/View/Helper/BcMailBaserHelperTest.php index 6b67f2c921..d4522521b9 100644 --- a/plugins/bc-mail/tests/TestCase/View/Helper/BcMailBaserHelperTest.php +++ b/plugins/bc-mail/tests/TestCase/View/Helper/BcMailBaserHelperTest.php @@ -37,6 +37,10 @@ public function testMethods() $this->assertEquals(['Mail', 'isMail'], $methods['isMail']); $this->assertEquals(['Mail', 'descriptionExists'], $methods['mailFormDescriptionExists']); $this->assertEquals(['Mail', 'description'], $methods['mailFormDescription']); + $this->assertEquals(['Mail', 'thanksExists'], $methods['mailFormThanksExists']); + $this->assertEquals(['Mail', 'thanks'], $methods['mailFormThanks']); + $this->assertEquals(['Mail', 'unpublishExists'], $methods['mailFormUnpublishExists']); + $this->assertEquals(['Mail', 'unpublish'], $methods['mailFormUnpublish']); $this->assertEquals(['Mailform', 'freeze'], $methods['freezeMailForm']); $this->assertEquals(['Mailform', 'create'], $methods['createMailForm']); $this->assertEquals(['Mailform', 'hidden'], $methods['mailFormHidden']); @@ -51,4 +55,4 @@ public function testMethods() $this->assertEquals(['Mailform', 'isGroupLastField'], $methods['isMailFormGroupLastField']); $this->assertEquals(['Mailform', 'label'], $methods['mailFormLabel']); } -} \ No newline at end of file +} diff --git a/plugins/bc-mail/tests/TestCase/View/Helper/MailHelperTest.php b/plugins/bc-mail/tests/TestCase/View/Helper/MailHelperTest.php index 0779e58e28..0430768744 100644 --- a/plugins/bc-mail/tests/TestCase/View/Helper/MailHelperTest.php +++ b/plugins/bc-mail/tests/TestCase/View/Helper/MailHelperTest.php @@ -103,6 +103,112 @@ public static function descriptionExistsProvider() ]; } + /** + * 送信完了文の取得結果 + * + * public function testThank() { + * $this->markTestIncomplete('このメソッドは、同一クラス内のメソッドをラッピングしているメソッドのためスキップします。'); + * } + */ + + /** + * 送信完了文を取得する + */ + public function testGetThanks() + { + $this->markTestIncomplete('このテストは、まだ実装されていません。'); + ClassRegistry::flush(); + $this->Mail->setMailContent(1); + $expected = '

* 印の項目は必須となりますので、必ず入力してください。

'; + $result = $this->Mail->getThanks(); + $this->assertEquals($result, $expected, "送信完了文の取得結果が違います。"); + } + + /** + * 送信完了文の存在確認 + * @param $thanks + * @param $expected + * @dataProvider ThanksExistsProvider + */ + public function testThanksExists($thanks, $expected) + { + //setUp + $mailContent = new Entity([ + 'thanks' => $thanks + ]); + $this->MailHelper->currentMailContent = $mailContent; + + $result = $this->MailHelper->thanksExists(); + + $this->assertEquals($expected, $result); + } + + + public static function thanksExistsProvider() + { + return [ + ['This is a test thanks', true], + ['', false], + [null, false], + ['0', false], + [' ', true], + ['

This is a HTML thanks

', true], + ]; + } + + /** + * 受付中止文の取得結果 + * + * public function testUnpublish() { + * $this->markTestIncomplete('このメソッドは、同一クラス内のメソッドをラッピングしているメソッドのためスキップします。'); + * } + */ + + /** + * 受付中止文を取得する + */ + public function testGetUnpublish() + { + $this->markTestIncomplete('このテストは、まだ実装されていません。'); + ClassRegistry::flush(); + $this->Mail->setMailContent(1); + $expected = '

* 印の項目は必須となりますので、必ず入力してください。

'; + $result = $this->Mail->getUnpublish(); + $this->assertEquals($result, $expected, "受付中止文の取得結果が違います。"); + } + + /** + * 受付中止文の存在確認 + * @param $unpublish + * @param $expected + * @dataProvider ThanksExistsProvider + */ + public function testUnpublishExists($unpublish, $expected) + { + //setUp + $mailContent = new Entity([ + 'unpublish' => $unpublish + ]); + $this->MailHelper->currentMailContent = $mailContent; + + $result = $this->MailHelper->unpublishExists(); + + $this->assertEquals($expected, $result); + } + + + public static function unpublishExistsProvider() + { + return [ + ['This is a test unpublish', true], + ['', false], + [null, false], + ['0', false], + [' ', true], + ['

This is a HTML unpublish

', true], + ]; + } + /** * メールフォームを取得 */ @@ -236,6 +342,74 @@ public function test_getDescription() $this->assertEquals('test description', $rs); } + /** + * test thanksExists + */ + public function test_thanksExists() + { + $mailContent = new MailContent(); + $mailContent->thanks = 'test thanks'; + + //with thanks + $this->MailHelper->currentMailContent = $mailContent; + $rs = $this->MailHelper->thanksExists(); + $this->assertTrue($rs); + + //with empty thanks + $mailContent->thanks = ''; + $this->MailHelper->currentMailContent = $mailContent; + $rs = $this->MailHelper->thanksExists(); + $this->assertFalse($rs); + } + + /** + * test testGetThanks + */ + public function test_getThanks() + { + $mailContent = new MailContent(); + $mailContent->thanks = 'test thanks'; + + $this->MailHelper->currentMailContent = $mailContent; + + $rs = $this->MailHelper->getThanks(); + $this->assertEquals('test thanks', $rs); + } + + /** + * test unpublishExists + */ + public function test_unpublishExists() + { + $mailContent = new MailContent(); + $mailContent->unpublish = 'test unpublish'; + + //with unpublish + $this->MailHelper->currentMailContent = $mailContent; + $rs = $this->MailHelper->unpublishExists(); + $this->assertTrue($rs); + + //with empty unpublish + $mailContent->unpublish = ''; + $this->MailHelper->currentMailContent = $mailContent; + $rs = $this->MailHelper->unpublishExists(); + $this->assertFalse($rs); + } + + /** + * test testGetUnpublish + */ + public function test_getUnpublish() + { + $mailContent = new MailContent(); + $mailContent->unpublish = 'test unpublish'; + + $this->MailHelper->currentMailContent = $mailContent; + + $rs = $this->MailHelper->getUnpublish(); + $this->assertEquals('test unpublish', $rs); + } + /** * test isMail */