diff --git a/plugins/bc-custom-content/src/Model/Table/CustomTablesTable.php b/plugins/bc-custom-content/src/Model/Table/CustomTablesTable.php index f5ea4dcf06..5f902987b8 100644 --- a/plugins/bc-custom-content/src/Model/Table/CustomTablesTable.php +++ b/plugins/bc-custom-content/src/Model/Table/CustomTablesTable.php @@ -31,6 +31,7 @@ class CustomTablesTable extends AppTable * @param array $config * @checked * @noTodo + * @unitTest */ public function initialize(array $config): void { @@ -51,6 +52,9 @@ public function initialize(array $config): void /** * ツリー構造形式の関連フィールドを hasMany で設定する + * @checked + * @noTodo + * @unitTest */ public function setHasManyLinksByThreaded() { @@ -65,6 +69,9 @@ public function setHasManyLinksByThreaded() /** * ツリー構造形式ではない通常一覧の関連フィールドを hasMany で設定する + * @checked + * @noTodo + * @unitTest */ public function setHasManyLinksByAll() { @@ -81,6 +88,9 @@ public function setHasManyLinksByAll() * * @param Validator $validator * @return Validator + * @checked + * @noTodo + * @unitTest */ public function validationDefault(Validator $validator): Validator { diff --git a/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomTablesTableTest.php b/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomTablesTableTest.php index 14660993a2..4595152ea1 100644 --- a/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomTablesTableTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomTablesTableTest.php @@ -12,9 +12,11 @@ namespace BcCustomContent\Test\TestCase\Model\Table; use BaserCore\TestSuite\BcTestCase; +use BcCustomContent\Model\Table\CustomTablesTable; /** * CustomTablesTableTest + * @property CustomTablesTable $CustomTablesTable */ class CustomTablesTableTest extends BcTestCase { @@ -25,6 +27,7 @@ class CustomTablesTableTest extends BcTestCase public function setUp(): void { parent::setUp(); + $this->CustomTablesTable = new CustomTablesTable(); } /** @@ -35,4 +38,74 @@ public function tearDown(): void parent::tearDown(); } + /** + * test initialize + */ + public function test_initialize() + { + $this->assertTrue($this->CustomTablesTable->hasBehavior('Timestamp')); + $this->assertTrue($this->CustomTablesTable->hasAssociation('CustomEntries')); + $this->assertTrue($this->CustomTablesTable->hasAssociation('CustomContents')); + $this->assertTrue($this->CustomTablesTable->hasAssociation('CustomLinks')); + } + + /** + * test setHasManyLinksByThreaded + */ + public function test_setHasManyLinksByThreaded() + { + $association = $this->CustomTablesTable->getAssociation('CustomLinks'); + $this->assertEquals('threaded', $association->getFinder()); + $this->assertEquals('custom_table_id', $association->getForeignKey()); + $this->assertEquals(['CustomLinks.lft' => 'ASC'], $association->getSort()); + } + + /** + * test setHasManyLinksByAll + */ + public function test_setHasManyLinksByAll() + { + $this->CustomTablesTable->setHasManyLinksByAll(); + $association = $this->CustomTablesTable->getAssociation('CustomLinks'); + $this->assertEquals('all', $association->getFinder()); + $this->assertEquals('custom_table_id', $association->getForeignKey()); + $this->assertEquals(['CustomLinks.lft' => 'ASC'], $association->getSort()); + } + + /** + * test validationDefault + */ + public function test_validationDefault() + { + $validator = $this->CustomTablesTable->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'])); + //入力フィールドのデータが異常な記号含める + $errors = $validator->validate([ + 'name' => 'あ', + ]); + $this->assertEquals('識別名は半角英数字とアンダースコアのみで入力してください。', current($errors['name'])); + //正常系実行 + $errors = $validator->validate([ + 'name' => 'test', + 'title' => 'test', + ]); + $this->assertEmpty($errors); + } + + + }