From 93b294d2f88a8627061c55bb954b44760d4da0b0 Mon Sep 17 00:00:00 2001 From: thangnn Date: Mon, 28 Oct 2024 14:07:25 +0700 Subject: [PATCH 1/2] Add unitTest_BcContentsBehavior_getType --- .../src/Model/Behavior/BcContentsBehavior.php | 1 + .../Model/Behavior/BcContentsBehaviorTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/plugins/baser-core/src/Model/Behavior/BcContentsBehavior.php b/plugins/baser-core/src/Model/Behavior/BcContentsBehavior.php index 8bfe6cb5b0..f36de3325c 100644 --- a/plugins/baser-core/src/Model/Behavior/BcContentsBehavior.php +++ b/plugins/baser-core/src/Model/Behavior/BcContentsBehavior.php @@ -75,6 +75,7 @@ public function initialize(array $config): void * @return string * @checked * @noTodo + * @unitTest */ public function getType(): string { diff --git a/plugins/baser-core/tests/TestCase/Model/Behavior/BcContentsBehaviorTest.php b/plugins/baser-core/tests/TestCase/Model/Behavior/BcContentsBehaviorTest.php index a484fa1418..ec6f77908c 100644 --- a/plugins/baser-core/tests/TestCase/Model/Behavior/BcContentsBehaviorTest.php +++ b/plugins/baser-core/tests/TestCase/Model/Behavior/BcContentsBehaviorTest.php @@ -49,6 +49,8 @@ public function setUp(): void $this->table->setPrimaryKey(['id']); $this->table->addBehavior('BaserCore.BcContents'); $this->contentService = new ContentsService(); + + $this->BcContentsBehavior = new BcContentsBehavior($this->table); } /** @@ -200,4 +202,15 @@ public function testAfterDelete() } + /** + * test getType + */ + public function testGetType() + { + $this->table->setTable('baser_contents'); + $rs = $this->BcContentsBehavior->getType(); + + $this->assertEquals('BaserContent', $rs); + } + } From 69d85a1d95e23a29262ffb819f2d8eda97a33137 Mon Sep 17 00:00:00 2001 From: thangnn Date: Thu, 7 Nov 2024 10:40:03 +0700 Subject: [PATCH 2/2] modified --- .../Model/Behavior/BcContentsBehaviorTest.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/baser-core/tests/TestCase/Model/Behavior/BcContentsBehaviorTest.php b/plugins/baser-core/tests/TestCase/Model/Behavior/BcContentsBehaviorTest.php index cc093eb00d..e3552ab2b1 100644 --- a/plugins/baser-core/tests/TestCase/Model/Behavior/BcContentsBehaviorTest.php +++ b/plugins/baser-core/tests/TestCase/Model/Behavior/BcContentsBehaviorTest.php @@ -13,6 +13,8 @@ use ArrayObject; use BaserCore\Test\Scenario\ContentFoldersScenario; use BaserCore\Test\Scenario\ContentsScenario; +use BaserCore\Utility\BcUtil; +use Cake\Database\Connection; use Cake\ORM\Entity; use BaserCore\TestSuite\BcTestCase; use BaserCore\Service\ContentsService; @@ -219,9 +221,21 @@ public function testOnAlias() */ public function testGetType() { - $this->table->setTable('baser_contents'); + //prefix = "" + $this->table->setTable('unittest_baser_contents'); $rs = $this->BcContentsBehavior->getType(); + //戻り確認 + $this->assertEquals('UnittestBaserContent', $rs); + //prefix = "unittest_" + $dbConfig = BcUtil::getCurrentDbConfig(); + $dbConfig['prefix'] = 'unittest_'; + $connection = new Connection($dbConfig); + $this->table->setConnection($connection); + $this->table->setTable('unittest_baser_contents'); + + $rs = $this->BcContentsBehavior->getType(); + //戻り確認 $this->assertEquals('BaserContent', $rs); }