diff --git a/plugins/bc-front/templates/plugin/BcMail/element/mail_input.php b/plugins/bc-front/templates/plugin/BcMail/element/mail_input.php
index a1dca16235..7a6610a4f8 100755
--- a/plugins/bc-front/templates/plugin/BcMail/element/mail_input.php
+++ b/plugins/bc-front/templates/plugin/BcMail/element/mail_input.php
@@ -95,7 +95,7 @@
}
/* 説明欄 */
- $isGroupValidComplate = in_array('VALID_GROUP_COMPLATE', explode(',', $field->valid_ex));
+ $isGroupValidComplate = in_array('VALID_GROUP_COMPLATE', explode(',', (string) $field->valid_ex));
if(!$isGroupValidComplate) {
echo $this->BcBaser->mailFormError("MailMessage." . $field->field_name);
}
diff --git a/plugins/bc-mail/src/Controller/MailController.php b/plugins/bc-mail/src/Controller/MailController.php
index 1efcc57fbe..06860febc7 100755
--- a/plugins/bc-mail/src/Controller/MailController.php
+++ b/plugins/bc-mail/src/Controller/MailController.php
@@ -281,7 +281,7 @@ public function submit(
$entity = $mailMessagesService->create($mailContent, $this->getRequest()->getData());
} catch (PersistenceFailedException $e) {
$entity = $e->getEntity();
- $mailMessage->auth_captcha = '';
+ $entity->auth_captcha = '';
$this->BcMessage->setError(__d('baser_core', '入力内容を確認し、再度送信してください。'));
$this->set($service->getViewVarsForConfirm($mailContent, $entity));
return $this->render($service->getConfirmTemplate($mailContent));
diff --git a/plugins/bc-mail/src/Model/Table/MailMessagesTable.php b/plugins/bc-mail/src/Model/Table/MailMessagesTable.php
index 209b58d903..e4b3c1158a 100755
--- a/plugins/bc-mail/src/Model/Table/MailMessagesTable.php
+++ b/plugins/bc-mail/src/Model/Table/MailMessagesTable.php
@@ -252,7 +252,7 @@ protected function setupValidate(array $postData)
// ### 拡張バリデーション
if ($mailField->valid_ex && !empty($mailField->use_field)) {
- $valids = explode(',', $mailField->valid_ex);
+ $valids = explode(',', (string) $mailField->valid_ex);
foreach($valids as $valid) {
$options = preg_split('/(?options);
/**
@@ -449,7 +449,7 @@ protected function _validGroupComplete(EntityInterface $entity)
$dists = [];
foreach($this->mailFields as $mailField) {
// 対象フィールドがあれば、バリデートグループごとに配列に格納する
- $valids = explode(',', $mailField->valid_ex);
+ $valids = explode(',', (string) $mailField->valid_ex);
if (in_array('VALID_GROUP_COMPLATE', $valids)) {
$dists[$mailField->group_valid][] = [
'name' => $mailField->field_name,
@@ -522,9 +522,9 @@ public function convertDatasToMail($data, $options)
foreach($mailFields as $key => $value) {
$fieldName = $value->field_name;
- $value->before_attachment = strip_tags($value->before_attachment);
- $value->after_attachment = str_replace(["
", "
"], "\n", strip_tags($value->after_attachment, "
"));
- $value->head = str_replace(["
", "
"], "", strip_tags($value->head, "
"));
+ $value->before_attachment = strip_tags((string) $value->before_attachment);
+ $value->after_attachment = str_replace(["
", "
"], "\n", strip_tags((string) $value->after_attachment, "
"));
+ $value->head = str_replace(["
", "
"], "", strip_tags((string) $value->head, "
"));
if ($value->no_send) {
unset($message->{$fieldName});
}
diff --git a/plugins/bc-mail/src/Service/Admin/MailFieldsAdminService.php b/plugins/bc-mail/src/Service/Admin/MailFieldsAdminService.php
index 90380721cd..158a5a897e 100644
--- a/plugins/bc-mail/src/Service/Admin/MailFieldsAdminService.php
+++ b/plugins/bc-mail/src/Service/Admin/MailFieldsAdminService.php
@@ -88,7 +88,7 @@ public function getViewVarsForEdit(int $mailContentId, EntityInterface $mailFiel
{
/* @var \BcMail\Service\MailContentsService $mailContentsService */
$mailContentsService = $this->getService(MailContentsServiceInterface::class);
- $mailField->valid_ex = explode(',', $mailField->valid_ex);
+ $mailField->valid_ex = explode(',', (string) $mailField->valid_ex);
$mailContent = $mailContentsService->get($mailContentId);
return [
'mailContent' => $mailContent,
diff --git a/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php
index c63052b3f3..c9bc5c15fa 100644
--- a/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php
+++ b/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php
@@ -151,7 +151,6 @@ public function testConfirm()
*/
public function testSubmit()
{
- $this->markTestIncomplete('このテストは未確認です');
//準備
$this->enableSecurityToken();
$this->enableCsrfToken();
@@ -159,7 +158,8 @@ public function testSubmit()
SiteConfigFactory::make(['name' => 'email', 'value' => 'abc@gmail.com'])->persist();
SiteConfigFactory::make(['name' => 'admin-theme', 'value' => 'test theme'])->persist();
SiteFactory::make(['id' => 1])->persist();
- MailFieldsFactory::make(['mail_content_id' => 1, 'field_name' => 'sex'])->persist();
+ MailFieldsFactory::make(['mail_content_id' => 1, 'field_name' => 'sex', 'valid' => 0, 'use_field' => 1])->persist();
+ MailFieldsFactory::make(['mail_content_id' => 1, 'field_name' => 'name_1', 'valid' => 1, 'use_field' => 1])->persist();
ContentFactory::make(['id' => 1, 'plugin' => 'BcMail', 'type' => 'MailContent', 'entity_id' => 1, 'url' => '/contact/', 'site_id' => 1, 'lft' => 1, 'rght' => 2])->persist();
MailContentFactory::make([
'id' => 1,
@@ -170,10 +170,15 @@ public function testSubmit()
'sender_1' => 't@gm.com'
])->persist();
+ // 回帰テスト: バリデーションエラー時に 500 にならず確認画面を再表示する
$this->session(['BcMail' => ['valid' => true]]);
- $this->post('/contact/submit/', ['sex' => 1]);
- $this->assertResponseCode(302);
- $this->assertRedirect('/contact/thanks');
+ $this->post('/contact/submit/', ['sex' => 1, 'name_1' => '']);
+ $this->assertResponseCode(200);
+ $vars = $this->_controller->viewBuilder()->getVars();
+ $this->assertNotNull($vars['mailContent']);
+ $this->assertNotNull($vars['mailFields']);
+ $this->assertNotNull($vars['mailMessage']);
+ $this->assertArrayHasKey('name_1', $vars['mailMessage']->getErrors());
}
/**