Skip to content

Commit

Permalink
Merge branch 'dev-5' into fix#2403
Browse files Browse the repository at this point in the history
  • Loading branch information
dovanhung committed Sep 28, 2023
2 parents 84001ea + fc15731 commit 6b28a6a
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 8 deletions.
16 changes: 16 additions & 0 deletions plugins/baser-core/src/Model/Validation/BcValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,4 +583,20 @@ public static function reserved($value): bool
return true;
}

/**
* 選択リストに同じ項目を複数登録するかをチェック
*
* @param $value
* @return bool
* @checked
* @notodo
* @unitTest
*/
public static function checkSelectList($value): bool
{
$data = preg_split("/\r\n|\n|\r/", $value);
$result = max(array_count_values($data));
return ($result < 2);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,20 @@ public function testCheckHiragana()
$this->assertEquals($result, false);
}

/**
* test checkSelectList
*/
public function test_checkSelectList()
{
//戻り=falseケース
$str = "\r\r\n\n\ntest";
$result = $this->BcValidation->checkSelectList($str);
$this->assertFalse($result);
//戻り=trueケース
$str = "あa\n\n";
$result = $this->BcValidation->checkSelectList($str);
$this->assertTrue($result);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ public function createSearchDetail(CustomEntry $entity): string
*
* @param int $tableId
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function setUp(int $tableId, array $postData = [])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ public function validationDefault(Validator $validator): Validator
$validator
->scalar('type')
->notEmptyString('type', __d('baser_core', 'タイプを入力してください。'));
$validator
->add('source', [
'checkSelectList' => [
'provider' => 'bc',
'rule' => ['checkSelectList'],
'message' => __d('baser_core', '選択リストに同じ項目を複数登録できません。')
]
]);
return $validator;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public function initialize(array $config): void
*
* @param Validator $validator
* @return Validator
* @noTodo
* @checked
* @unitTest
*/
public function validationDefault(Validator $validator): Validator
{
Expand Down Expand Up @@ -88,6 +91,9 @@ public function validationDefault(Validator $validator): Validator
* scope の設定のため、TreeBehavior より優先度を高くする
*
* @return array
* @noTodo
* @checked
* @unitTest
*/
public function implementedEvents(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function getIndex(array $queryParams = [])
'limit' => null,
'direction' => '', // 並び方向
'order' => '', // 並び順対象のフィールド
'contain' => ['CustomTables' => ['CustomContents' => ['Contents']]],
'contain' => [],
'status' => '',
'use_api' => null
], $queryParams);
Expand All @@ -146,6 +146,10 @@ public function getIndex(array $queryParams = [])
->select($this->createSelect($options))
->contain($options['contain']);

if(array_key_exists('CustomTables', $options['contain']) || in_array('CustomTables', $options['contain'])) {
$query->select($this->CustomEntries->CustomTables);
}

if ($options['order']) {
$query->order($this->createOrder($options['order'], $options['direction']));
}
Expand Down Expand Up @@ -222,7 +226,7 @@ public function createIndexConditions(Query $query, array $params)
// 公開状態
if ($params['status'] === 'publish') {
$conditions = $this->CustomEntries->getConditionAllowPublish();
$params['contain'] = ['CustomTables' => ['CustomContents' => ['Contents']]];
$query->contain(['CustomTables' => ['CustomContents' => ['Contents']]]);
$fields = $this->CustomEntries->getSchema()->columns();
$query->select($fields);
$conditions = array_merge_recursive(
Expand Down
18 changes: 17 additions & 1 deletion plugins/bc-custom-content/tests/Factory/CustomFieldFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,23 @@ protected function getRootTableRegistryName(): string
protected function setDefaultTemplate(): void
{
$this->setDefaultData(function (Generator $faker) {
return [];
return [
'title' => 'test',
'status' => 1,
'default_value' => '',
'validate' => '',
'regex' => '',
'regex_error_message' => '',
'counter' => 0,
'auto_convert' => '',
'placeholder' => '',
'size' => NULL,
'max_length' => NULL,
'source' => '',
'created' => '2023-01-30 06:22:47',
'modified' => '2023-02-20 11:18:32',
'line' => NULL
];
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,34 @@ public function test_createSearchDetail()
public function test_setUp()
{
//準備

$dataBaseService = $this->getService(BcDatabaseServiceInterface::class);
$customTable = $this->getService(CustomTablesServiceInterface::class);
CustomFieldFactory::make([
'name' => 'test',
'type' => 'text',
])->persist();
CustomLinkFactory::make([
'custom_table_id' => 1,
'custom_field_id' => 1,
'name' => 'recruit_category',
'title' => '求人分類',
'display_admin_list' => 1,
'status' => 1,
])->persist();
$customTable->create([
'id' => 1,
'name' => 'recruit',
'title' => '求人情報',
'type' => '1',
'display_field' => 'title',
]);
//正常系実行

//異常系実行

$result = $this->CustomEntriesTable->setUp(1, []);
$this->assertTrue($result);
$this->assertEquals(1, $this->CustomEntriesTable->tableId);
$this->assertEquals('recruit_category', $this->CustomEntriesTable->links[0]->name);
//不要なテーブルを削除
$dataBaseService->dropTable('custom_entry_1_recruit');

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use BaserCore\TestSuite\BcTestCase;
use BcCustomContent\Model\Table\CustomLinksTable;
use BcCustomContent\Test\Factory\CustomLinkFactory;

/**
* CustomTablesTableTest
Expand Down Expand Up @@ -54,6 +55,39 @@ public function test_initialize()
*/
public function test_validationDefault()
{
$validator = $this->CustomLinksTable->getValidator('default');
//入力フィールドのデータが超えた場合、
$errors = $validator->validate([
'name' => str_repeat('a', 256),
'title' => str_repeat('a', 256),
]);
$this->assertEquals('255文字以内で入力してください。', current($errors['name']));
$this->assertEquals('255文字以内で入力してください。', current($errors['title']));
//入力フィールドのデータがない
$errors = $validator->validate([
'name' => '',
'title' => '',
]);
$this->assertEquals('フィールド名を入力してください。', current($errors['name']));
$this->assertEquals('タイトルを入力してください。', current($errors['title']));
//nameは半角英数字以外の記号が含めるケース
$errors = $validator->validate([
'name' => 'aこんにちは',
]);
$this->assertEquals('フィールド名は半角英数字とアンダースコアのみで入力してください。', current($errors['name']));
//システム予約名称のケース
$errors = $validator->validate([
'name' => 'option',
]);
$this->assertEquals('group, rows, option はシステム予約名称のため利用できません。', current($errors['name']));
//既に登録のケース
CustomLinkFactory::make([
'name' => 'recruit_category',
])->persist();
$errors = $validator->validate([
'name' => 'recruit_category',
]);
$this->assertEquals('既に登録のあるフィールド名です。', current($errors['name']));

}

Expand All @@ -62,7 +96,9 @@ public function test_validationDefault()
*/
public function test_implementedEvents()
{

$result = $this->CustomLinksTable->implementedEvents();
$this->assertArrayHasKey('Model.beforeSave', $result);
$this->assertArrayHasKey('Model.beforeDelete', $result);
}

/**
Expand Down

0 comments on commit 6b28a6a

Please sign in to comment.