Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions plugins/bc-mail/src/Model/Table/MailFieldsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function initialize(array $config): void
*/
public function validationDefault(Validator $validator): Validator
{
$validator->setProvider('bc', 'BaserCore\Model\Validation\BcValidation');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant provider registration already set at bootstrap

Low Severity

The setProvider('bc', 'BaserCore\Model\Validation\BcValidation') call is redundant — the bc provider is already registered as a default provider via Validator::addDefaultProvider('bc', ...) in plugins/baser-core/config/bootstrap.php. Notably, the CustomFieldsTable that this PR says it's modeled after does not include this explicit setProvider call yet uses 'provider' => 'bc' for its reserved rule without issue. This inconsistency with the stated reference implementation adds unnecessary code.

Fix in Cursor Fix in Web

$validator
->integer('id')
->allowEmptyString('id', null, 'create');
Expand All @@ -80,6 +81,12 @@ public function validationDefault(Validator $validator): Validator
'rule' => 'duplicateMailField',
'provider' => 'table',
'message' => __d('baser_core', '既に登録のあるフィールド名です。')
]])
->add('field_name', [
'reserved' => [
'rule' => ['reserved'],
'provider' => 'bc',
'message' => __d('baser_core', 'システム予約名称のため利用できません。')
]]);
$validator
->scalar('type')
Expand Down
29 changes: 29 additions & 0 deletions plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,35 @@ public function test_validationDefaultDuplicate()
$this->assertEquals('既に登録のあるフィールド名です。', current($errors['field_name']));
}

/**
* test validationDefault reserved word check
* @dataProvider validationDefaultReservedDataProvider
*/
public function test_validationDefaultReserved($fieldName, $expected)
{
$validator = $this->MailFieldsTable->getValidator('default');
$errors = $validator->validate([
'mail_content_id' => 999,
'field_name' => $fieldName,
]);
if ($expected) {
$this->assertArrayNotHasKey('reserved', $errors['field_name'] ?? []);
} else {
$this->assertArrayHasKey('reserved', $errors['field_name']);
$this->assertEquals('システム予約名称のため利用できません。', $errors['field_name']['reserved']);
}
}

public static function validationDefaultReservedDataProvider()
{
return [
['test_field', true],
['select', false],
['insert', false],
['update', false],
];
}

/**
* コントロールソースを取得する
*/
Expand Down
Loading