From 23b072172b9a89a68c508ff68af92c1c8e8f44d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Thu, 22 Feb 2024 12:56:12 +0900 Subject: [PATCH] =?UTF-8?q?fix=20#3141=20=E3=80=905.1=E3=80=91=E5=BF=85?= =?UTF-8?q?=E9=A0=88=E9=A0=85=E7=9B=AE=E3=82=92=E5=85=A5=E5=8A=9B=E3=81=9B?= =?UTF-8?q?=E3=81=9A=E3=81=AB=E4=BF=9D=E5=AD=98=E3=83=9C=E3=82=BF=E3=83=B3?= =?UTF-8?q?=E3=82=92=E6=8A=BC=E4=B8=8B=E3=81=99=E3=82=8B=E3=81=A8=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E3=81=95=E3=82=8C=E3=81=A6=E3=81=97=E3=81=BE=E3=81=86?= =?UTF-8?q?=E3=80=90=E3=82=A2=E3=82=AF=E3=82=BB=E3=82=B9=E3=83=AB=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=82=B0=E3=83=AB=E3=83=BC=E3=83=97=EF=BC=9E=E3=82=A2?= =?UTF-8?q?=E3=82=AF=E3=82=BB=E3=82=B9=E3=83=AB=E3=83=BC=E3=83=AB=E3=82=B0?= =?UTF-8?q?=E3=83=AB=E3=83=BC=E3=83=97=E6=96=B0=E8=A6=8F=E7=99=BB=E9=8C=B2?= =?UTF-8?q?=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Model/Table/PermissionGroupsTable.php | 25 ++++++ .../Table/PermissionsGroupsTableTest.php | 85 +++++++++++++++++++ .../Admin/element/PermissionGroups/form.php | 1 + 3 files changed, 111 insertions(+) create mode 100644 plugins/baser-core/tests/TestCase/Model/Table/PermissionsGroupsTableTest.php diff --git a/plugins/baser-core/src/Model/Table/PermissionGroupsTable.php b/plugins/baser-core/src/Model/Table/PermissionGroupsTable.php index b2a49c51ee..0960da42da 100644 --- a/plugins/baser-core/src/Model/Table/PermissionGroupsTable.php +++ b/plugins/baser-core/src/Model/Table/PermissionGroupsTable.php @@ -14,6 +14,7 @@ use BaserCore\Annotation\UnitTest; use BaserCore\Annotation\NoTodo; use BaserCore\Annotation\Checked; +use Cake\Validation\Validator; class PermissionGroupsTable extends AppTable { @@ -43,4 +44,28 @@ public function initialize(array $config): void ]); } + /** + * Validation Default + * + * @param Validator $validator + * @return Validator + * @checked + * @noTodo + * @unitTest + */ + public function validationDefault(Validator $validator): Validator + { + // id + $validator + ->integer('id') + ->allowEmptyString('id', null, 'create'); + + $validator + ->scalar('name') + ->maxLength('name', 60, __d('baser_core', 'ルールグループ名は60文字以内で入力してください。')) + ->notEmptyString('name', __d('baser_core', 'ルールグループ名を入力してください。')); + + return $validator; + } + } diff --git a/plugins/baser-core/tests/TestCase/Model/Table/PermissionsGroupsTableTest.php b/plugins/baser-core/tests/TestCase/Model/Table/PermissionsGroupsTableTest.php new file mode 100644 index 0000000000..da5b2381e0 --- /dev/null +++ b/plugins/baser-core/tests/TestCase/Model/Table/PermissionsGroupsTableTest.php @@ -0,0 +1,85 @@ + + * Copyright (c) NPO baser foundation + * + * @copyright Copyright (c) NPO baser foundation + * @link https://basercms.net baserCMS Project + * @since 5.0.0 + * @license https://basercms.net/license/index.html MIT License + */ + +namespace BaserCore\Test\TestCase\Model\Table; + +use BaserCore\Model\Table\PermissionGroupsTable; +use BaserCore\TestSuite\BcTestCase; +use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; + +/** + * Class PermissionGroupsTableTest + * @property PermissionGroupsTable $PermissionGroupsTable + */ +class PermissionsGroupsTableTest extends BcTestCase +{ + /** + * ScenarioAwareTrait + */ + use ScenarioAwareTrait; + + /** + * Set Up + * + * @return void + */ + public function setUp(): void + { + parent::setUp(); + $this->PermissionGroupsTable = $this->getTableLocator()->get('BaserCore.PermissionGroups'); + } + + /** + * Tear Down + * + * @return void + */ + public function tearDown(): void + { + unset($this->PermissionGroupsTable); + parent::tearDown(); + } + + /** + * Test initialize + */ + public function testInitialize() + { + $this->assertEquals('permission_groups', $this->PermissionGroupsTable->getTable()); + $this->assertEquals('name', $this->PermissionGroupsTable->getDisplayField()); + $this->assertEquals('id', $this->PermissionGroupsTable->getPrimaryKey()); + $this->assertIsBool($this->PermissionGroupsTable->hasBehavior('Timestamp')); + $this->assertEquals('Permissions', $this->PermissionGroupsTable->getAssociation('Permissions')->getName()); + } + + /** + * Test validationDefault + * + * @return void + */ + public function testValidationDefault() + { + $validator = $this->PermissionGroupsTable->getValidator('default'); + $errors = $validator->validate([ + 'name' => '', + ]); + + $this->assertEquals('ルールグループ名を入力してください。', current($errors['name'])); + + $validator = $this->PermissionGroupsTable->getValidator('default'); + $errors = $validator->validate([ + 'name' => str_repeat('a', 61), + ]); + + $this->assertEquals('ルールグループ名は60文字以内で入力してください。', current($errors['name'])); + } + +} diff --git a/plugins/bc-admin-third/templates/Admin/element/PermissionGroups/form.php b/plugins/bc-admin-third/templates/Admin/element/PermissionGroups/form.php index 743c56f580..5a6a1a1097 100644 --- a/plugins/bc-admin-third/templates/Admin/element/PermissionGroups/form.php +++ b/plugins/bc-admin-third/templates/Admin/element/PermissionGroups/form.php @@ -50,6 +50,7 @@ BcAdminForm->control('name', ['type' => 'text','size' => 60]) ?> + BcAdminForm->error('name') ?>