From 29335cb190dad5229e59506b3e2a337318e49bad Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Tue, 27 Feb 2024 08:43:59 +0900 Subject: [PATCH] =?UTF-8?q?fix=20#3148=20=E3=80=905.1=E3=80=91=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8?= =?UTF-8?q?=E3=81=AB100=E3=81=BE=E3=81=A7=E3=81=AE=E6=95=B0=E5=80=A4?= =?UTF-8?q?=E3=81=A7=E5=85=A5=E5=8A=9B=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E6=8C=87=E7=A4=BA=E3=81=8C=E3=81=82=E3=81=A3=E3=81=9F?= =?UTF-8?q?=E3=81=8C=E3=80=81=E5=AE=9F=E9=9A=9B=E3=81=AB=E3=81=AF101?= =?UTF-8?q?=E3=81=BE=E3=81=A7=E5=85=A5=E5=8A=9B=E3=81=A7=E3=81=8D=E3=82=8B?= =?UTF-8?q?=E3=80=90=E3=82=B3=E3=83=B3=E3=83=86=E3=83=B3=E3=83=84=E7=AE=A1?= =?UTF-8?q?=E7=90=86=EF=BC=9E=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=A0=E3=82=B3?= =?UTF-8?q?=E3=83=B3=E3=83=86=E3=83=B3=E3=83=84=E8=A8=AD=E5=AE=9A=E7=B7=A8?= =?UTF-8?q?=E9=9B=86=E3=80=91=20(#3159)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- .../src/Model/Table/CustomContentsTable.php | 4 +- .../Model/Table/CustomContentsTableTest.php | 37 ++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/plugins/bc-custom-content/src/Model/Table/CustomContentsTable.php b/plugins/bc-custom-content/src/Model/Table/CustomContentsTable.php index 2498db7af5..916960e7ef 100644 --- a/plugins/bc-custom-content/src/Model/Table/CustomContentsTable.php +++ b/plugins/bc-custom-content/src/Model/Table/CustomContentsTable.php @@ -30,6 +30,7 @@ class CustomContentsTable extends AppTable * @param array $config テーブル設定 * @checked * @noTodo + * @unitTest */ public function initialize(array $config): void { @@ -48,13 +49,14 @@ public function initialize(array $config): void * @return Validator * @checked * @noTodo + * @unitTest */ public function validationWithTable(Validator $validator): Validator { $validator->setProvider('bc', 'BaserCore\Model\Validation\BcValidation'); $validator->requirePresence('list_count', 'update') ->notEmptyString('list_count', __d('baser_core', '一覧表示件数は必須項目です。')) - ->range('list_count', [0, 101], __d('baser_core', '一覧表示件数は100までの数値で入力してください。')) + ->range('list_count', [0, 100], __d('baser_core', '一覧表示件数は100までの数値で入力してください。')) ->add('list_count', 'halfText', [ 'provider' => 'bc', 'rule' => 'halfText', diff --git a/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomContentsTableTest.php b/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomContentsTableTest.php index 8ee5a249ba..facd835119 100644 --- a/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomContentsTableTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomContentsTableTest.php @@ -12,9 +12,11 @@ namespace BcCustomContent\Test\TestCase\Model\Table; use BaserCore\TestSuite\BcTestCase; +use BcCustomContent\Model\Table\CustomContentsTable; /** * CustomContentsTableTest + * @property CustomContentsTable $CustomContentsTable */ class CustomContentsTableTest extends BcTestCase { @@ -25,6 +27,7 @@ class CustomContentsTableTest extends BcTestCase public function setUp(): void { parent::setUp(); + $this->CustomContentsTable = $this->getTableLocator()->get('BcCustomContent.CustomContents'); } /** @@ -32,6 +35,7 @@ public function setUp(): void */ public function tearDown(): void { + unset($this->CustomContentsTable); parent::tearDown(); } @@ -40,7 +44,10 @@ public function tearDown(): void */ public function test_initialize() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $this->assertTrue($this->CustomContentsTable->hasBehavior('BcContents')); + $this->assertTrue($this->CustomContentsTable->hasBehavior('Timestamp')); + $this->assertTrue($this->CustomContentsTable->hasBehavior('BcContents')); + $this->assertTrue($this->CustomContentsTable->hasAssociation('CustomTables')); } /** @@ -48,6 +55,32 @@ public function test_initialize() */ public function test_validationWithTable() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + //全角文字を入力した場合 + $validator = $this->CustomContentsTable->getValidator('withTable'); + $errors = $validator->validate([ + 'list_count' => '漢字' + ]); + $this->assertEquals([ + 'range' => '一覧表示件数は100までの数値で入力してください。', + 'halfText' => '一覧表示件数は半角で入力してください。' + ], $errors['list_count']); + + //101を入力した場合 + $validator = $this->CustomContentsTable->getValidator('withTable'); + $errors = $validator->validate([ + 'list_count' => '101' + ]); + $this->assertEquals([ + 'range' => '一覧表示件数は100までの数値で入力してください。', + ], $errors['list_count']); + + //何も入力しない場合 + $validator = $this->CustomContentsTable->getValidator('withTable'); + $errors = $validator->validate([ + 'list_count' => '' + ]); + $this->assertEquals([ + '_empty' => '一覧表示件数は必須項目です。', + ], $errors['list_count']); } }