Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/bc-mail/src/Controller/MailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Comment on lines 282 to 286
return $this->render($service->getConfirmTemplate($mailContent));
Expand Down
10 changes: 5 additions & 5 deletions plugins/bc-mail/src/Model/Table/MailMessagesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('/(?<!\\\)\|/', $mailField->options);
/**
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(["<br />", "<br>"], "\n", strip_tags($value->after_attachment, "<br>"));
$value->head = str_replace(["<br />", "<br>"], "", strip_tags($value->head, "<br>"));
$value->before_attachment = strip_tags((string) $value->before_attachment);
$value->after_attachment = str_replace(["<br />", "<br>"], "\n", strip_tags((string) $value->after_attachment, "<br>"));
$value->head = str_replace(["<br />", "<br>"], "", strip_tags((string) $value->head, "<br>"));
if ($value->no_send) {
unset($message->{$fieldName});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 10 additions & 5 deletions plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ public function testConfirm()
*/
public function testSubmit()
{
$this->markTestIncomplete('このテストは未確認です');
//準備
$this->enableSecurityToken();
$this->enableCsrfToken();

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,
Expand All @@ -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());
}

/**
Expand Down
Loading