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/Utilities/log_maintenance.php b/plugins/bc-admin-third/templates/Admin/Utilities/log_maintenance.php index 9a7cd8d2d0..ecd7f9420f 100755 --- a/plugins/bc-admin-third/templates/Admin/Utilities/log_maintenance.php +++ b/plugins/bc-admin-third/templates/Admin/Utilities/log_maintenance.php @@ -17,7 +17,7 @@ * @noTodo * @unitTest */ -$this->BcAdmin->setTitle(__d('baser_core', 'データメンテナンス')); +$this->BcAdmin->setTitle(__d('baser_core', 'ログメンテナンス')); $this->BcAdmin->setHelp('tools_log'); ?> 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') ?> diff --git a/plugins/bc-content-link/src/Model/Table/ContentLinksTable.php b/plugins/bc-content-link/src/Model/Table/ContentLinksTable.php index 77b0761081..c8ebbacf21 100644 --- a/plugins/bc-content-link/src/Model/Table/ContentLinksTable.php +++ b/plugins/bc-content-link/src/Model/Table/ContentLinksTable.php @@ -64,8 +64,10 @@ public function validationDefault(Validator $validator): Validator ->requirePresence('id', 'update'); $validator - ->scalar('url') - ->notEmptyString('url', __d('baser_core', 'リンク先URLを入力してください。'), 'update'); + ->scalar('url') + ->notEmptyString('url', __d('baser_core', 'リンク先URLを入力してください。'), 'update') + ->regex('url', '/^http|^\/.*/', __d('baser_core', 'リンク先URLはURLの形式を入力してください。')) + ->maxLength('url', 255, __d('baser_core', 'リンク先URLは255文字以内で入力してください。')); return $validator; } diff --git a/plugins/bc-content-link/tests/TestCase/Model/Table/ContentLinksTableTest.php b/plugins/bc-content-link/tests/TestCase/Model/Table/ContentLinksTableTest.php index d957639513..0c4d79a475 100644 --- a/plugins/bc-content-link/tests/TestCase/Model/Table/ContentLinksTableTest.php +++ b/plugins/bc-content-link/tests/TestCase/Model/Table/ContentLinksTableTest.php @@ -79,6 +79,47 @@ public function testValidationDefault() ], $contentLink->getErrors()); } + /** + * Test testValidationURL + */ + public function testValidationURL() + { + $validator = $this->ContentLinks->getValidator('default'); + //エラー場合、 + //スペースだけ入力 + $errors = $validator->validate([ + 'url' => ' ' + ]); + //戻り値を確認 + $this->assertEquals('リンク先URLはURLの形式を入力してください。', current($errors['url'])); + //スラッシュがない場合 + $errors = $validator->validate([ + 'url' => 'あああああ' + ]); + //戻り値を確認 + $this->assertEquals('リンク先URLはURLの形式を入力してください。', current($errors['url'])); + + //長いURLを入力場合 + $errors = $validator->validate([ + 'url' => '/' . str_repeat('a', 255) + ]); + //戻り値を確認 + $this->assertEquals('リンク先URLは255文字以内で入力してください。', current($errors['url'])); + + //正常場合、 + $errors = $validator->validate([ + 'url' => '/test' + ]); + //戻り値を確認 + $this->assertCount(0, $errors); + + $errors = $validator->validate([ + 'url' => 'https://basercms.net/' + ]); + //戻り値を確認 + $this->assertCount(0, $errors); + } + /** * test beforeCopyEvent */ @@ -88,13 +129,13 @@ public function testBeforeCopyEvent() //イベントをコル $this->entryEventToMock(self::EVENT_LAYER_MODEL, 'BcContentLink.ContentLinks.beforeCopy', function (Event $event) { $data = $event->getData('data'); - $data['url'] = 'beforeCopy'; + $data['url'] = '/beforeCopy'; $event->setData('data', $data); }); $this->ContentLinks->copy(1, 1, 'new title', 1, 1); //イベントに入るかどうか確認 $contentLinks = $this->getTableLocator()->get('BcContentLink.ContentLinks'); - $query = $contentLinks->find()->where(['url' => 'beforeCopy']); + $query = $contentLinks->find()->where(['url' => '/beforeCopy']); $this->assertEquals(1, $query->count()); } @@ -108,13 +149,13 @@ public function testAfterCopyEvent() $this->entryEventToMock(self::EVENT_LAYER_MODEL, 'BcContentLink.ContentLinks.afterCopy', function (Event $event) { $data = $event->getData('data'); $contentLinks = TableRegistry::getTableLocator()->get('BcContentLink.ContentLinks'); - $data->url = 'AfterCopy'; + $data->url = '/AfterCopy'; $contentLinks->save($data); }); $this->ContentLinks->copy(1, 1, 'new title', 1, 1); //イベントに入るかどうか確認 $contentLinks = $this->getTableLocator()->get('BcContentLink.ContentLinks'); - $query = $contentLinks->find()->where(['url' => 'AfterCopy']); + $query = $contentLinks->find()->where(['url' => '/AfterCopy']); $this->assertEquals(1, $query->count()); }