From 3f4451a5b98b62d053fa03bb7580bdfb2a92abdc Mon Sep 17 00:00:00 2001 From: thangnn Date: Tue, 27 Feb 2024 13:04:42 +0700 Subject: [PATCH] add unitTest_BlogCategoriesTable_getByName --- .../src/Model/Table/BlogCategoriesTable.php | 16 ++++++---------- .../TestCase/Model/BlogCategoriesTableTest.php | 5 +++-- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/plugins/bc-blog/src/Model/Table/BlogCategoriesTable.php b/plugins/bc-blog/src/Model/Table/BlogCategoriesTable.php index 92898b2762..356afa1c8b 100755 --- a/plugins/bc-blog/src/Model/Table/BlogCategoriesTable.php +++ b/plugins/bc-blog/src/Model/Table/BlogCategoriesTable.php @@ -355,19 +355,15 @@ public function hasChild($id) * @param int $blogContentId * @param string $name * @param array $options - * @return array|null + * @return EntityInterface */ public function getByName($blogContentId, $name, $options = []) { - $options = array_merge([ - 'conditions' => [ - 'BlogCategory.blog_content_id' => $blogContentId, - 'BlogCategory.name' => urlencode($name), - ], - 'recursive' => -1 - ], $options); - $this->unbindModel(['hasMany' => ['BlogPost']]); - return $this->find('first', $options); + return $this->find()->where([ + 'BlogCategories.blog_content_id' => $blogContentId, + 'BlogCategories.name' => urlencode($name) + ] + )->first(); } /** diff --git a/plugins/bc-blog/tests/TestCase/Model/BlogCategoriesTableTest.php b/plugins/bc-blog/tests/TestCase/Model/BlogCategoriesTableTest.php index 87d1d725a1..ef50e0d730 100755 --- a/plugins/bc-blog/tests/TestCase/Model/BlogCategoriesTableTest.php +++ b/plugins/bc-blog/tests/TestCase/Model/BlogCategoriesTableTest.php @@ -505,8 +505,9 @@ public function testHasChild() */ public function testGetByName($blogCategoryId, $name, $expects) { - $this->markTestIncomplete('こちらのテストはまだ未確認です'); - $result = $this->BlogCategory->getByName($blogCategoryId, $name); + //データ生成 + BlogCategoryFactory::make(['blog_content_id' => 1, 'name' => 'child'])->persist(); + $result = $this->BlogCategoriesTable->getByName($blogCategoryId, $name); $this->assertEquals($expects, (bool)$result); }