From dab6039f060345c417f0d7efcc9b900fe5146fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Thu, 4 Apr 2024 10:22:24 +0900 Subject: [PATCH 1/9] =?UTF-8?q?fix=20#3249=20=E3=82=AB=E3=82=B9=E3=82=BF?= =?UTF-8?q?=E3=83=A0=E3=82=B3=E3=83=B3=E3=83=86=E3=83=B3=E3=83=84=EF=BC=9A?= =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E3=80=80=E3=83=90?= =?UTF-8?q?=E3=83=AA=E3=83=87=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E4=B8=8D?= =?UTF-8?q?=E5=85=B7=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Model/Validation/BcValidation.php | 25 +++++++ .../Model/Validation/BcValidationTest.php | 26 ++++++++ .../Admin/element/CustomFields/form.php | 9 +++ .../src/Model/Table/CustomFieldsTable.php | 10 +++ .../Model/Table/CustomFieldsTableTest.php | 65 +++++++++++++++++++ 5 files changed, 135 insertions(+) diff --git a/plugins/baser-core/src/Model/Validation/BcValidation.php b/plugins/baser-core/src/Model/Validation/BcValidation.php index 0bc3d07ee7..a809ede285 100644 --- a/plugins/baser-core/src/Model/Validation/BcValidation.php +++ b/plugins/baser-core/src/Model/Validation/BcValidation.php @@ -600,4 +600,29 @@ public static function notBlankOnlyString($string): bool return (preg_replace("/( | )/", '', $string) !== ''); } + /** + * Jsonをバリデーション + * 半角小文字英数字とアンダースコアを許容 + * @param $string + * @param $key + * @return bool + * @checked + * @noTodo + * @unitTest + */ + public static function checkAlphaNumericWithJson($string, $key) + { + $value = json_decode($string, true); + $keys = explode('.', $key); + + foreach ($keys as $k) { + $value = $value[$k]; + } + + if (preg_match("/^[a-z0-9_]+$/", $value)) { + return true; + } else { + return false; + } + } } diff --git a/plugins/baser-core/tests/TestCase/Model/Validation/BcValidationTest.php b/plugins/baser-core/tests/TestCase/Model/Validation/BcValidationTest.php index 750e827b68..b3b743a282 100644 --- a/plugins/baser-core/tests/TestCase/Model/Validation/BcValidationTest.php +++ b/plugins/baser-core/tests/TestCase/Model/Validation/BcValidationTest.php @@ -617,5 +617,31 @@ public function test_notBlankOnlyString() $result = $this->BcValidation->notBlankOnlyString($str); $this->assertTrue($result); } + /** + * test checkAlphaNumericWithJson + */ + public function test_checkAlphaNumericWithJson() + { + //戻り=falseケース:全角文字 + $key = 'BcCustomContent.email_confirm'; + $str = '{"BcCustomContent":{"email_confirm":"ああ","max_file_size":"","file_ext":""}}'; + $result = $this->BcValidation->checkAlphaNumericWithJson($str, $key); + $this->assertFalse($result); + + //戻り=falseケース:半角スペース + $str = '{"BcCustomContent":{"email_confirm":" ","max_file_size":"","file_ext":""}}'; + $result = $this->BcValidation->checkAlphaNumericWithJson($str, $key); + $this->assertFalse($result); + + //戻り=falseケース:半角・全角 + $str = '{"BcCustomContent":{"email_confirm":"ああaaa","max_file_size":"","file_ext":""}}'; + $result = $this->BcValidation->checkAlphaNumericWithJson($str, $key); + $this->assertFalse($result); + + //戻り=trueケース + $str = '{"BcCustomContent":{"email_confirm":"aaaa_bbb","max_file_size":"","file_ext":""}}'; + $result = $this->BcValidation->checkAlphaNumericWithJson($str, $key); + $this->assertTrue($result); + } } diff --git a/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/element/CustomFields/form.php b/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/element/CustomFields/form.php index d1c7e6d32c..a381bc0b22 100644 --- a/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/element/CustomFields/form.php +++ b/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/element/CustomFields/form.php @@ -132,11 +132,19 @@ + BcAdminForm->error('meta'))) { + $emailConfirmClass = 'bca-textbox__input form-error'; + } + ?> + BcAdminForm->label('meta.BcCustomContent.email_confirm', __d('baser_core', 'Eメール比較先フィールド名')) ?>  BcAdminForm->control('meta.BcCustomContent.email_confirm', [ 'type' => 'text', 'size' => 20, + 'class' => $emailConfirmClass ]) ?>
@@ -170,6 +178,7 @@ BcAdminForm->error('validate') ?> + BcAdminForm->error('meta') ?> diff --git a/plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php b/plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php index 7e8b844dc2..2424a0edd5 100644 --- a/plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php +++ b/plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php @@ -51,6 +51,7 @@ public function initialize(array $config): void * @return Validator * @checked * @noTodo + * @unitTest */ public function validationDefault(Validator $validator): Validator { @@ -82,6 +83,15 @@ public function validationDefault(Validator $validator): Validator 'message' => __d('baser_core', '選択リストに同じ項目を複数登録できません。') ] ]); + $validator + ->scalar('meta.BcCustomContent.email_confirm') + ->add('meta', [ + 'checkAlphaNumericWithJson' => [ + 'rule' => ['checkAlphaNumericWithJson', 'BcCustomContent.email_confirm'], + 'provider' => 'bc', + 'message' => __d('baser_core', 'Eメール比較先フィールド名は半角小文字英数字とアンダースコアのみで入力してください。') + ] + ]); return $validator; } diff --git a/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomFieldsTableTest.php b/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomFieldsTableTest.php index a58fe3ac95..a3fb1b8c6d 100644 --- a/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomFieldsTableTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomFieldsTableTest.php @@ -12,6 +12,7 @@ namespace BcCustomContent\Test\TestCase\Model\Table; use BaserCore\TestSuite\BcTestCase; +use BcCustomContent\Model\Table\CustomFieldsTable; /** * CustomFieldsTableTest @@ -19,12 +20,18 @@ class CustomFieldsTableTest extends BcTestCase { + /** + * @var CustomFieldsTable + */ + public $CustomFieldsTable; + /** * Set up */ public function setUp(): void { parent::setUp(); + $this->CustomFieldsTable = $this->getTableLocator()->get('BcCustomContent.CustomFields'); } /** @@ -32,7 +39,65 @@ public function setUp(): void */ public function tearDown(): void { + unset($this->CustomFieldsTable); parent::tearDown(); } + public function test_validationDefault() + { + $validator = $this->CustomFieldsTable->getValidator('default'); + //入力フィールドのデータが超えた場合、 + $errors = $validator->validate([ + 'name' => str_repeat('a', 256), + 'title' => str_repeat('a', 256) + ]); + //戻り値を確認 + $this->assertEquals('フィールド名は255文字以内で入力してください。', current($errors['name'])); + $this->assertEquals('項目見出しは255文字以内で入力してください。', current($errors['title'])); + + //入力フィールドのデータがNULL場合、 + $errors = $validator->validate([ + 'name' => '', + 'title' => '', + 'type' => '', + ]); + //戻り値を確認 + $this->assertEquals('フィールド名を入力してください。', current($errors['name'])); + $this->assertEquals('項目見出しを入力してください。', current($errors['title'])); + $this->assertEquals('タイプを入力してください。', current($errors['type'])); + + //フィールド名は半角小文字英数字とアンダースコアのみ利用可能 + $errors = $validator->validate([ + 'name' => 'test sss', + ]); + //戻り値を確認 + $this->assertEquals('フィールド名は半角小文字英数字とアンダースコアのみで入力してください。', current($errors['name'])); + $errors = $validator->validate([ + 'name' => 'ひらがな', + ]); + //戻り値を確認 + $this->assertEquals('フィールド名は半角小文字英数字とアンダースコアのみで入力してください。', current($errors['name'])); + + //trueを返す + $errors = $validator->validate([ + 'name' => 'test_test', + ]); + //戻り値を確認 + $this->assertArrayNotHasKey('name', $errors); + + //Eメール比較先フィールド名のバリデーション + //trueを返す + $errors = $validator->validate([ + 'meta' => '{"BcCustomContent":{"email_confirm":"aaaa_bbb","max_file_size":"","file_ext":""}}' + ]); + //戻り値を確認 + $this->assertArrayNotHasKey('meta', $errors); + + //全角文字 + $errors = $validator->validate([ + 'meta' => '{"BcCustomContent":{"email_confirm":"ああ","max_file_size":"","file_ext":""}}' + ]); + //戻り値を確認 + $this->assertEquals('Eメール比較先フィールド名は半角小文字英数字とアンダースコアのみで入力してください。', current($errors['meta'])); + } } From e991eeef3b5444fbc9125a7acace8643ce5c90a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Thu, 4 Apr 2024 10:23:18 +0900 Subject: [PATCH 2/9] =?UTF-8?q?fix=20#3249=20=E3=82=AB=E3=82=B9=E3=82=BF?= =?UTF-8?q?=E3=83=A0=E3=82=B3=E3=83=B3=E3=83=86=E3=83=B3=E3=83=84=EF=BC=9A?= =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E3=80=80=E3=83=90?= =?UTF-8?q?=E3=83=AA=E3=83=87=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E4=B8=8D?= =?UTF-8?q?=E5=85=B7=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php b/plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php index 2424a0edd5..3270636277 100644 --- a/plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php +++ b/plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php @@ -84,7 +84,6 @@ public function validationDefault(Validator $validator): Validator ] ]); $validator - ->scalar('meta.BcCustomContent.email_confirm') ->add('meta', [ 'checkAlphaNumericWithJson' => [ 'rule' => ['checkAlphaNumericWithJson', 'BcCustomContent.email_confirm'], From c77206810ec4f4901bdeec4363d116fc4cabc92d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Thu, 4 Apr 2024 11:05:42 +0900 Subject: [PATCH 3/9] =?UTF-8?q?fix=20#3249=20=E3=82=AB=E3=82=B9=E3=82=BF?= =?UTF-8?q?=E3=83=A0=E3=82=B3=E3=83=B3=E3=83=86=E3=83=B3=E3=83=84=EF=BC=9A?= =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E3=80=80=E3=83=90?= =?UTF-8?q?=E3=83=AA=E3=83=87=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E4=B8=8D?= =?UTF-8?q?=E5=85=B7=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/baser-core/src/Model/Validation/BcValidation.php | 2 +- .../tests/TestCase/Service/CustomFieldsServiceTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/baser-core/src/Model/Validation/BcValidation.php b/plugins/baser-core/src/Model/Validation/BcValidation.php index a809ede285..125d094151 100644 --- a/plugins/baser-core/src/Model/Validation/BcValidation.php +++ b/plugins/baser-core/src/Model/Validation/BcValidation.php @@ -619,7 +619,7 @@ public static function checkAlphaNumericWithJson($string, $key) $value = $value[$k]; } - if (preg_match("/^[a-z0-9_]+$/", $value)) { + if (empty($value) || preg_match("/^[a-z0-9_]+$/", $value)) { return true; } else { return false; diff --git a/plugins/bc-custom-content/tests/TestCase/Service/CustomFieldsServiceTest.php b/plugins/bc-custom-content/tests/TestCase/Service/CustomFieldsServiceTest.php index ac54d254ad..7b406ce0f4 100644 --- a/plugins/bc-custom-content/tests/TestCase/Service/CustomFieldsServiceTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Service/CustomFieldsServiceTest.php @@ -157,6 +157,7 @@ public function test_update() //異常系をテスト $customField->title = null; + $customField->meta = ['BcCustomContent' => ['email_confirm' => 'aa']]; $this->expectException(PersistenceFailedException::class); $this->expectExceptionMessage('Entity save failure. Found the following errors (title._empty: "項目見出しを入力してください。")'); $this->CustomFieldsService->update($customField, $customField->toArray()); From 67721be8a2e63fa1f5a4847db42a34f46a645dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Thu, 4 Apr 2024 11:32:55 +0900 Subject: [PATCH 4/9] =?UTF-8?q?fix=20#3249=20=E3=82=AB=E3=82=B9=E3=82=BF?= =?UTF-8?q?=E3=83=A0=E3=82=B3=E3=83=B3=E3=83=86=E3=83=B3=E3=83=84=EF=BC=9A?= =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E3=80=80=E3=83=90?= =?UTF-8?q?=E3=83=AA=E3=83=87=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E4=B8=8D?= =?UTF-8?q?=E5=85=B7=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestCase/Controller/Admin/CustomFieldsControllerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/bc-custom-content/tests/TestCase/Controller/Admin/CustomFieldsControllerTest.php b/plugins/bc-custom-content/tests/TestCase/Controller/Admin/CustomFieldsControllerTest.php index 96db8a807c..657574350c 100644 --- a/plugins/bc-custom-content/tests/TestCase/Controller/Admin/CustomFieldsControllerTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Controller/Admin/CustomFieldsControllerTest.php @@ -180,6 +180,7 @@ public function testEdit() //Postデータを生成 $data = CustomFieldFactory::get(1); $data['title'] = 'test edit title'; + $data['meta'] = ['BcCustomContent' => ['email_confirm' => 'aa']]; //対象URLをコル $this->post('/baser/admin/bc-custom-content/custom_fields/edit/1', $data->toArray()); $this->assertResponseCode(302); @@ -191,7 +192,7 @@ public function testEdit() $this->assertEquals(1, $query->count()); //タイトルを指定しない場合、 - $this->post('/baser/admin/bc-custom-content/custom_fields/edit/1', ['title' => '']); + $this->post('/baser/admin/bc-custom-content/custom_fields/edit/1', ['title' => '', ]); $this->assertResponseCode(200); //エラーを確認 $vars = $this->_controller->viewBuilder()->getVars(); From 100e6eb7092174284d1c91478c50ebe4366ea18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Thu, 4 Apr 2024 11:51:59 +0900 Subject: [PATCH 5/9] =?UTF-8?q?fix=20#3249=20=E3=82=AB=E3=82=B9=E3=82=BF?= =?UTF-8?q?=E3=83=A0=E3=82=B3=E3=83=B3=E3=83=86=E3=83=B3=E3=83=84=EF=BC=9A?= =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E3=80=80=E3=83=90?= =?UTF-8?q?=E3=83=AA=E3=83=87=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E4=B8=8D?= =?UTF-8?q?=E5=85=B7=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestCase/Controller/Admin/CustomFieldsControllerTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/bc-custom-content/tests/TestCase/Controller/Admin/CustomFieldsControllerTest.php b/plugins/bc-custom-content/tests/TestCase/Controller/Admin/CustomFieldsControllerTest.php index 657574350c..167ac0f607 100644 --- a/plugins/bc-custom-content/tests/TestCase/Controller/Admin/CustomFieldsControllerTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Controller/Admin/CustomFieldsControllerTest.php @@ -220,6 +220,7 @@ public function testBeforeEditEvent() //Postデータを生成 $data = CustomFieldFactory::get(1); $data['title'] = 'test edit title'; + $data['meta'] = ['BcCustomContent' => ['email_confirm' => 'aa']]; //対象URLをコル $this->post('/baser/admin/bc-custom-content/custom_fields/edit/1', $data->toArray()); //イベントに入るかどうか確認 @@ -247,6 +248,7 @@ public function testAfterEditEvent() //Postデータを生成 $data = CustomFieldFactory::get(1); $data['title'] = 'test edit title'; + $data['meta'] = ['BcCustomContent' => ['email_confirm' => 'aa']]; //対象URLをコル $this->post('/baser/admin/bc-custom-content/custom_fields/edit/1', $data->toArray()); //イベントに入るかどうか確認 From 1773d4f7916b83ce5fc5513489d31da1f78cc1b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Thu, 4 Apr 2024 12:13:56 +0900 Subject: [PATCH 6/9] =?UTF-8?q?fix=20#3249=20=E3=82=AB=E3=82=B9=E3=82=BF?= =?UTF-8?q?=E3=83=A0=E3=82=B3=E3=83=B3=E3=83=86=E3=83=B3=E3=83=84=EF=BC=9A?= =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E3=80=80=E3=83=90?= =?UTF-8?q?=E3=83=AA=E3=83=87=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E4=B8=8D?= =?UTF-8?q?=E5=85=B7=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/TestCase/Service/CustomFieldsServiceTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/bc-custom-content/tests/TestCase/Service/CustomFieldsServiceTest.php b/plugins/bc-custom-content/tests/TestCase/Service/CustomFieldsServiceTest.php index 7b406ce0f4..e7b8d27c7b 100644 --- a/plugins/bc-custom-content/tests/TestCase/Service/CustomFieldsServiceTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Service/CustomFieldsServiceTest.php @@ -150,6 +150,7 @@ public function test_update() $this->loadFixtureScenario(CustomFieldsScenario::class); $customField = $this->CustomFieldsService->get(1); $customField->title = 'test edit title'; + $customField->meta = ['BcCustomContent' => ['email_confirm' => 'aa']]; //正常系をテスト $rs = $this->CustomFieldsService->update($customField, $customField->toArray()); //戻る値を確認 From a7a04fd69c682cbbe971559158163c9023a76b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Thu, 4 Apr 2024 13:07:10 +0900 Subject: [PATCH 7/9] =?UTF-8?q?fix=20#3249=20=E3=82=AB=E3=82=B9=E3=82=BF?= =?UTF-8?q?=E3=83=A0=E3=82=B3=E3=83=B3=E3=83=86=E3=83=B3=E3=83=84=EF=BC=9A?= =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E3=80=80=E3=83=90?= =?UTF-8?q?=E3=83=AA=E3=83=87=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E4=B8=8D?= =?UTF-8?q?=E5=85=B7=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestCase/Controller/Admin/Api/CustomFieldsControllerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/bc-custom-content/tests/TestCase/Controller/Admin/Api/CustomFieldsControllerTest.php b/plugins/bc-custom-content/tests/TestCase/Controller/Admin/Api/CustomFieldsControllerTest.php index 8b81d74047..8e84e9f26c 100644 --- a/plugins/bc-custom-content/tests/TestCase/Controller/Admin/Api/CustomFieldsControllerTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Controller/Admin/Api/CustomFieldsControllerTest.php @@ -147,6 +147,7 @@ public function test_edit() $this->loadFixtureScenario(CustomFieldsScenario::class); $data = CustomFieldFactory::get(1); $data['title'] = 'test edit title'; + $data['meta'] = ['BcCustomContent' => ['email_confirm' => 'aa']]; //APIを呼ぶ $this->post('/baser/api/admin/bc-custom-content/custom_fields/edit/1.json?token=' . $this->accessToken, $data->toArray()); //ステータスを確認 From 380a4bb9480d46f6eeb927eb7bcc129d93594322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Tue, 23 Apr 2024 10:11:13 +0900 Subject: [PATCH 8/9] =?UTF-8?q?fix=20#3079=20=E3=80=90=E3=82=AB=E3=82=B9?= =?UTF-8?q?=E3=82=BF=E3=83=A0=E3=82=B3=E3=83=B3=E3=83=86=E3=83=B3=E3=83=84?= =?UTF-8?q?=E3=80=91=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E5=90=8D?= =?UTF-8?q?=E9=83=A8=E5=88=86=E3=81=AE=E4=B8=8D=E5=85=B7=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BcCustomContent/Admin/element/CustomFields/form.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/element/CustomFields/form.php b/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/element/CustomFields/form.php index de0d020e59..04c7847dd4 100644 --- a/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/element/CustomFields/form.php +++ b/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/element/CustomFields/form.php @@ -133,10 +133,11 @@
BcAdminForm->error('meta'))) { - $emailConfirmClass = 'bca-textbox__input form-error'; - } + $metaErrors = $entity->getError('meta'); + $emailConfirmClass = 'bca-textbox__input'; + if (isset($metaErrors['checkAlphaNumericWithJson'])) { + $emailConfirmClass = 'bca-textbox__input form-error'; + } ?> From 664ab74fc3612470f567ece7fa338101ed82f13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Tue, 7 May 2024 12:34:52 +0900 Subject: [PATCH 9/9] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/element/CustomFields/form.php | 13 ++---------- .../src/Model/Table/CustomFieldsTable.php | 21 +++++++++++++++++++ .../Model/Table/CustomFieldsTableTest.php | 13 ++++++++++++ 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/element/CustomFields/form.php b/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/element/CustomFields/form.php index 04c7847dd4..45801c12d0 100644 --- a/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/element/CustomFields/form.php +++ b/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/element/CustomFields/form.php @@ -132,26 +132,18 @@ - getError('meta'); - $emailConfirmClass = 'bca-textbox__input'; - if (isset($metaErrors['checkAlphaNumericWithJson'])) { - $emailConfirmClass = 'bca-textbox__input form-error'; - } - ?> - BcAdminForm->label('meta.BcCustomContent.email_confirm', __d('baser_core', 'Eメール比較先フィールド名')) ?>  BcAdminForm->control('meta.BcCustomContent.email_confirm', [ 'type' => 'text', - 'size' => 20, - 'class' => $emailConfirmClass + 'size' => 20 ]) ?>
Eメール比較チェックの対象となる、フィールド名を入力します。
利用しているテーブルに紐づく関連フィールドのフィールド名となりますので注意が必要です。
+ BcAdminForm->error('meta.BcCustomContent.email_confirm') ?>
@@ -179,7 +171,6 @@ BcAdminForm->error('validate') ?> - BcAdminForm->error('meta') ?> diff --git a/plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php b/plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php index 4c1bd21e44..9b464a7893 100644 --- a/plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php +++ b/plugins/bc-custom-content/src/Model/Table/CustomFieldsTable.php @@ -116,6 +116,27 @@ public function beforeMarshal(EventInterface $event, ArrayObject $content, Array $this->encodeEntity($content); } + /** + * afterMarshal + * + * @param EventInterface $event + * @param EntityInterface $entity + * @param ArrayObject $data + * @param ArrayObject $options + * @return void + * + * @checked + * @noTodo + * @unitTest + */ + public function afterMarshal(EventInterface $event, EntityInterface $entity, ArrayObject $data, ArrayObject $options) + { + $metaErrors = $entity->getError('meta'); + if (isset($metaErrors['checkAlphaNumericWithJson'])) { + $entity->setError('meta.BcCustomContent.email_confirm', ['checkAlphaNumericWithJson' => $metaErrors['checkAlphaNumericWithJson']]); + } + } + /** * Find all * diff --git a/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomFieldsTableTest.php b/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomFieldsTableTest.php index a3fb1b8c6d..1116803b37 100644 --- a/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomFieldsTableTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomFieldsTableTest.php @@ -100,4 +100,17 @@ public function test_validationDefault() //戻り値を確認 $this->assertEquals('Eメール比較先フィールド名は半角小文字英数字とアンダースコアのみで入力してください。', current($errors['meta'])); } + + /** + * test afterMarshal + */ + public function test_afterMarshal() + { + $customFields = $this->CustomFieldsTable->newEntity(['meta' => ['BcCustomContent' => ['email_confirm' => '全角文字']]]); + $result = $this->CustomFieldsTable->dispatchEvent('Model.afterMarshal', ['entity' => $customFields, 'data' => new \ArrayObject(), 'options' => new \ArrayObject()]); + $customFields = $result->getData('entity'); + //エラー情報を正しい状態に戻すことを確認 + $errors = $customFields->getErrors(); + $this->assertEquals('Eメール比較先フィールド名は半角小文字英数字とアンダースコアのみで入力してください。', $errors['meta.BcCustomContent.email_confirm']['checkAlphaNumericWithJson']); + } }