Skip to content

Commit

Permalink
fix #3153 【5.1】識別名称:エイリアスに漢字カナひらがなが登録できてしまう【サイト管理>サイト編集】 (#3158)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <[email protected]>
  • Loading branch information
HungDV2022 and dovanhung authored Feb 26, 2024
1 parent 3f42aab commit 537fdc0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
10 changes: 10 additions & 0 deletions plugins/baser-core/src/Model/Table/SitesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ public function validationDefault(Validator $validator): Validator
'provider' => 'table',
'message' => __d('baser_core', '識別名称は、利用しているプラグイン名をハイフン区切りにした名称と同じ名称は利用できません。別の名称に変更してください。')
]]);
$validator
->scalar('alias')
->maxLength('alias', 50, __d('baser_core', 'エイリアスは50文字以内で入力してください。'))
->notEmptyString('alias', __d('baser_core', 'エイリアスを入力してください。'))
->add('alias', [
'nameAlphaNumericPlus' => [
'rule' => ['alphaNumericPlus'],
'provider' => 'bc',
'message' => __d('baser_core', 'エイリアスは、半角英数・ハイフン(-)・アンダースコア(_)で入力してください。')
]]);
$validator
->scalar('display_name')
->maxLength('display_name', 50, __d('baser_core', 'サイト名は50文字以内で入力してください。'))
Expand Down
3 changes: 2 additions & 1 deletion plugins/baser-core/src/Service/Admin/SitesAdminService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use BaserCore\Annotation\Checked;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\Paging\PaginatedInterface;
use Cake\Routing\Router;
use Cake\Utility\Inflector;

Expand All @@ -35,7 +36,7 @@ class SitesAdminService extends SitesService implements SitesAdminServiceInterfa

/**
* 一覧画面用のデータを取得する
* @param \Cake\ORM\ResultSet|\Cake\Datasource\ResultSetInterface $sites
* @param \Cake\ORM\ResultSet|\Cake\Datasource\ResultSetInterface|PaginatedInterface $sites
* @return array
* @checked
* @noTodo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use BaserCore\Annotation\NoTodo;
use BaserCore\Annotation\Checked;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\Paging\PaginatedInterface;

/**
* SitesAdminServiceInterface
Expand All @@ -23,7 +24,7 @@ interface SitesAdminServiceInterface

/**
* 一覧画面用のデータを取得する
* @param \Cake\ORM\ResultSet|\Cake\Datasource\ResultSetInterface $sites
* @param \Cake\ORM\ResultSet|\Cake\Datasource\ResultSetInterface|PaginatedInterface $sites
* @return array
* @checked
* @noTodo
Expand Down
4 changes: 2 additions & 2 deletions plugins/baser-core/tests/Factory/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ protected function setDefaultTemplate(): void
$this->setDefaultData(function (Generator $faker) {
return [
'name' => $faker->text(255),
'real_name_1' => $faker->text(50),
'real_name_2' => $faker->text(50),
'real_name_1' => $faker->text(5),
'real_name_2' => $faker->text(5),
'password' => 'password',
'email' => $faker->email(),
'nickname' => '',
Expand Down
26 changes: 26 additions & 0 deletions plugins/baser-core/tests/TestCase/Model/Table/SitesTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,32 @@ public function tearDown(): void
parent::tearDown();
}

/**
* test validationDefault alias
*/
public function testValidationDefault_alias()
{
//バリデーションを発生した場合
$validator = $this->Sites->getValidator('default');
$errors = $validator->validate([
'alias' => '漢字'
]);
$this->assertEquals('エイリアスは、半角英数・ハイフン(-)・アンダースコア(_)で入力してください。', current($errors['alias']));

$validator = $this->Sites->getValidator('default');
$errors = $validator->validate([
'alias' => str_repeat('a', 51)
]);
$this->assertEquals('エイリアスは50文字以内で入力してください。', current($errors['alias']));

//バリデーションを発生しない場合
$validator = $this->Sites->getValidator('default');
$errors = $validator->validate([
'alias' => 'aaaaaaa'
]);
$this->assertArrayNotHasKey('alias', $errors);
}

/**
* 公開されている全てのサイトを取得する
*/
Expand Down

0 comments on commit 537fdc0

Please sign in to comment.