Skip to content

Commit

Permalink
fix #3141 【5.1】必須項目を入力せずに保存ボタンを押下すると保存されてしまう【アクセスルールグループ>アクセスルールグループ新…
Browse files Browse the repository at this point in the history
…規登録】 (#3150)

Co-authored-by: Đỗ Văn Hùng <[email protected]>
  • Loading branch information
HungDV2022 and dovanhung authored Feb 25, 2024
1 parent 55e8a14 commit 16e6519
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
25 changes: 25 additions & 0 deletions plugins/baser-core/src/Model/Table/PermissionGroupsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use BaserCore\Annotation\UnitTest;
use BaserCore\Annotation\NoTodo;
use BaserCore\Annotation\Checked;
use Cake\Validation\Validator;

class PermissionGroupsTable extends AppTable
{
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* baserCMS : Based Website Development Project <https://basercms.net>
* Copyright (c) NPO baser foundation <https://baserfoundation.org/>
*
* @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']));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
</th>
<td class="col-input bca-form-table__input">
<?php echo $this->BcAdminForm->control('name', ['type' => 'text','size' => 60]) ?>
<?php echo $this->BcAdminForm->error('name') ?>
</td>
</tr>

Expand Down

0 comments on commit 16e6519

Please sign in to comment.