Skip to content

Commit

Permalink
fix #2951 メール基本設定で各項目にスペースが登録できてしまう (#3355)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <dovanhungk57@gmail.com>
  • Loading branch information
HungDV2022 and dovanhung authored Apr 20, 2024
1 parent 60c75f4 commit 132129a
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 1 deletion.
9 changes: 8 additions & 1 deletion plugins/bc-mail/src/Model/Table/MailConfigsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ public function validationKeyValue(Validator $validator): Validator
{
$validator
->scalar('site_name')
->notEmptyString('site_name', __d('baser_core', 'Webサイト名を入力してください。'));
->notEmptyString('site_name', __d('baser_core', 'Webサイト名を入力してください。'))
->add('site_name', [
'notBlankOnlyString' => [
'rule' => ['notBlankOnlyString'],
'provider' => 'bc',
'message' => __d('baser_core', 'Webサイト名を入力してください。')
]
]);
return $validator;
}

Expand Down
100 changes: 100 additions & 0 deletions plugins/bc-mail/tests/TestCase/Model/Table/MailConfigsTableTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
/**
* baserCMS : Based Website Development Project <https://basercms.net>
* Copyright (c) baserCMS Users Community <https://basercms.net/community/>
*
* @copyright Copyright (c) baserCMS Users Community
* @link https://basercms.net baserCMS Project
* @since baserCMS v 3.0.0
* @license https://basercms.net/license/index.html
*/

namespace BcMail\Test\TestCase\Model\Table;

use BaserCore\TestSuite\BcTestCase;
use BcMail\Model\Table\MailConfigsTable;

/**
* @property MailConfigsTable $MailConfigsTable
*/
class MailConfigsTableTest extends BcTestCase
{
/**
* Set Up
*
* @return void
*/
public function setUp(): void
{
parent::setUp();
$this->MailConfigsTable = $this->getTableLocator()->get('BcMail.MailConfigs');
}

/**
* Tear Down
*
* @return void
*/
public function tearDown(): void
{
unset($this->MailConfigsTable);
parent::tearDown();
}

/**
* test initialize
*/
public function test_initialize()
{
$this->assertTrue($this->MailConfigsTable->hasBehavior('BcKeyValue'));
}

/**
* test validationDefault
*/
public function test_validationDefault()
{
$validator = $this->MailConfigsTable->getValidator('default');

//設定名が指定しない場合、
$errors = $validator->validate([
'name' => ''
]);
//戻り値を確認
$this->assertEquals('設定名を入力してください。', current($errors['name']));

//maxLength テスト、
$errors = $validator->validate([
'name' => str_repeat('a', 256),
'value' => str_repeat('a', 65536)
]);
//戻り値を確認
$this->assertEquals('255文字以内で入力してください。', current($errors['name']));
$this->assertEquals('65535文字以内で入力してください。', current($errors['value']));
}

/**
* test validationKeyValue
*/
public function test_validationKeyValue()
{
$validator = $this->MailConfigsTable->getValidator('keyValue');
//入力しない場合、
$errors = $validator->validate([
'site_name' => '',
]);
$this->assertEquals('Webサイト名を入力してください。', current($errors['site_name']));

//スペースだけ入力する場合、
$errors = $validator->validate([
'site_name' => ' ',
]);
$this->assertEquals('Webサイト名を入力してください。', current($errors['site_name']));

//文字を入力する場合、
$errors = $validator->validate([
'site_name' => ' a',
]);
$this->assertArrayNotHasKey('site_name', $errors);
}
}

0 comments on commit 132129a

Please sign in to comment.