diff --git a/plugins/baser-core/src/Model/Table/SitesTable.php b/plugins/baser-core/src/Model/Table/SitesTable.php index 51f2799a5d..e980776fbd 100644 --- a/plugins/baser-core/src/Model/Table/SitesTable.php +++ b/plugins/baser-core/src/Model/Table/SitesTable.php @@ -116,6 +116,16 @@ public function validationDefault(Validator $validator): Validator 'provider' => 'bc', 'message' => __d('baser_core', '識別名称は、半角英数・ハイフン(-)・アンダースコア(_)で入力してください。') ]]); + $validator + ->scalar('alias') + ->maxLength('alias', 50, __d('baser_core', 'エイリアスは50文字以内で入力してください。')) + ->notEmptyString('alias', __d('baser_core', 'エイリアスを入力してください。')) + ->add('alias', [ + 'nameAlphaNumericPlus' => [ + 'rule' => ['alphaNumericPlus'], + 'provider' => 'bc', + 'message' => __d('baser_core', 'エイリアスは、半角英数・ハイフン(-)・アンダースコア(_)で入力してください。') + ]]); $validator ->scalar('display_name') ->maxLength('display_name', 50, __d('baser_core', 'サイト名は50文字以内で入力してください。')) @@ -742,7 +752,7 @@ public function save( ): EntityInterface|false { $success = parent::save($entity, $options); $request = Router::getRequest(); - if($request) { + if($success && $request) { $session = Router::getRequest()->getSession(); $currentSite = $session->read('BcApp.Admin.currentSite'); if ($currentSite && $success->id === $currentSite->id) { diff --git a/plugins/baser-core/src/Service/Admin/SitesAdminService.php b/plugins/baser-core/src/Service/Admin/SitesAdminService.php index d989da311f..4d9bd15390 100644 --- a/plugins/baser-core/src/Service/Admin/SitesAdminService.php +++ b/plugins/baser-core/src/Service/Admin/SitesAdminService.php @@ -19,6 +19,7 @@ use BaserCore\Annotation\Checked; use Cake\Core\Configure; use Cake\Datasource\EntityInterface; +use Cake\Datasource\Paging\PaginatedInterface; use Cake\Routing\Router; use Cake\Utility\Inflector; @@ -35,7 +36,7 @@ class SitesAdminService extends SitesService implements SitesAdminServiceInterfa /** * 一覧画面用のデータを取得する - * @param \Cake\ORM\ResultSet|\Cake\Datasource\ResultSetInterface $sites + * @param \Cake\ORM\ResultSet|\Cake\Datasource\ResultSetInterface|PaginatedInterface $sites * @return array * @checked * @noTodo diff --git a/plugins/baser-core/src/Service/Admin/SitesAdminServiceInterface.php b/plugins/baser-core/src/Service/Admin/SitesAdminServiceInterface.php index 57b922cd90..0c398e3af8 100644 --- a/plugins/baser-core/src/Service/Admin/SitesAdminServiceInterface.php +++ b/plugins/baser-core/src/Service/Admin/SitesAdminServiceInterface.php @@ -14,6 +14,7 @@ use BaserCore\Annotation\NoTodo; use BaserCore\Annotation\Checked; use Cake\Datasource\EntityInterface; +use Cake\Datasource\Paging\PaginatedInterface; /** * SitesAdminServiceInterface @@ -23,7 +24,7 @@ interface SitesAdminServiceInterface /** * 一覧画面用のデータを取得する - * @param \Cake\ORM\ResultSet|\Cake\Datasource\ResultSetInterface $sites + * @param \Cake\ORM\ResultSet|\Cake\Datasource\ResultSetInterface|PaginatedInterface $sites * @return array * @checked * @noTodo diff --git a/plugins/baser-core/tests/Factory/UserFactory.php b/plugins/baser-core/tests/Factory/UserFactory.php index 3f97302419..563d128201 100644 --- a/plugins/baser-core/tests/Factory/UserFactory.php +++ b/plugins/baser-core/tests/Factory/UserFactory.php @@ -47,8 +47,8 @@ protected function setDefaultTemplate(): void $this->setDefaultData(function (Generator $faker) { return [ 'name' => $faker->text(255), - 'real_name_1' => $faker->text(50), - 'real_name_2' => $faker->text(50), + 'real_name_1' => $faker->text(5), + 'real_name_2' => $faker->text(5), 'password' => 'password', 'email' => $faker->email(), 'nickname' => '', diff --git a/plugins/baser-core/tests/TestCase/Model/Table/SitesTableTest.php b/plugins/baser-core/tests/TestCase/Model/Table/SitesTableTest.php index 09426048ce..92e2acd8d0 100644 --- a/plugins/baser-core/tests/TestCase/Model/Table/SitesTableTest.php +++ b/plugins/baser-core/tests/TestCase/Model/Table/SitesTableTest.php @@ -60,6 +60,32 @@ public function tearDown(): void parent::tearDown(); } + /** + * test validationDefault alias + */ + public function testValidationDefault_alias() + { + //バリデーションを発生した場合 + $validator = $this->Sites->getValidator('default'); + $errors = $validator->validate([ + 'alias' => '漢字' + ]); + $this->assertEquals('エイリアスは、半角英数・ハイフン(-)・アンダースコア(_)で入力してください。', current($errors['alias'])); + + $validator = $this->Sites->getValidator('default'); + $errors = $validator->validate([ + 'alias' => str_repeat('a', 51) + ]); + $this->assertEquals('エイリアスは50文字以内で入力してください。', current($errors['alias'])); + + //バリデーションを発生しない場合 + $validator = $this->Sites->getValidator('default'); + $errors = $validator->validate([ + 'alias' => 'aaaaaaa' + ]); + $this->assertArrayNotHasKey('alias', $errors); + } + /** * 公開されている全てのサイトを取得する */