From fb9f8f38a8f14fa03e5f09804d174af3da39464f Mon Sep 17 00:00:00 2001 From: nghiem-mb <127474186+nghiem-mb@users.noreply.github.com> Date: Wed, 27 Sep 2023 06:47:42 +0700 Subject: [PATCH] =?UTF-8?q?fix=20#2744=20=E3=83=90=E3=83=AA=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=82=92=E8=A1=A8=E7=A4=BA=E3=81=99=E3=82=8B=20(#2754)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nghiem --- .../src/Model/Validation/BcValidation.php | 16 ++++++++++++++++ .../Model/Validation/BcValidationTest.php | 16 ++++++++++++++++ .../src/Model/Table/CustomFieldsTable.php | 8 ++++++++ 3 files changed, 40 insertions(+) diff --git a/plugins/baser-core/src/Model/Validation/BcValidation.php b/plugins/baser-core/src/Model/Validation/BcValidation.php index 8e471daa86..f32e673a4c 100644 --- a/plugins/baser-core/src/Model/Validation/BcValidation.php +++ b/plugins/baser-core/src/Model/Validation/BcValidation.php @@ -583,4 +583,20 @@ public static function reserved($value): bool return true; } + /** + * 選択リストに同じ項目を複数登録するかをチェック + * + * @param $value + * @return bool + * @checked + * @notodo + * @unitTest + */ + public static function checkSelectList($value): bool + { + $data = preg_split("/\r\n|\n|\r/", $value); + $result = max(array_count_values($data)); + return ($result < 2); + } + } diff --git a/plugins/baser-core/tests/TestCase/Model/Validation/BcValidationTest.php b/plugins/baser-core/tests/TestCase/Model/Validation/BcValidationTest.php index 8f33070ca2..f41450c54d 100644 --- a/plugins/baser-core/tests/TestCase/Model/Validation/BcValidationTest.php +++ b/plugins/baser-core/tests/TestCase/Model/Validation/BcValidationTest.php @@ -584,4 +584,20 @@ public function testCheckHiragana() $this->assertEquals($result, false); } + /** + * test checkSelectList + */ + public function test_checkSelectList() + { + //戻り=falseケース + $str = "あ\rべ\r\nあ\nべ\ntest"; + $result = $this->BcValidation->checkSelectList($str); + $this->assertFalse($result); + //戻り=trueケース + $str = "あa\nべ\nあ"; + $result = $this->BcValidation->checkSelectList($str); + $this->assertTrue($result); + } + + } diff --git a/plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php b/plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php index 2cb17867d8..c7bdbdc684 100644 --- a/plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php +++ b/plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php @@ -72,6 +72,14 @@ public function validationDefault(Validator $validator): Validator $validator ->scalar('type') ->notEmptyString('type', __d('baser_core', 'タイプを入力してください。')); + $validator + ->add('source', [ + 'checkSelectList' => [ + 'provider' => 'bc', + 'rule' => ['checkSelectList'], + 'message' => __d('baser_core', '選択リストに同じ項目を複数登録できません。') + ] + ]); return $validator; }