diff --git a/plugins/bc-blog/src/Model/Table/BlogCategoriesTable.php b/plugins/bc-blog/src/Model/Table/BlogCategoriesTable.php index a5190507a1..6b5cac670a 100755 --- a/plugins/bc-blog/src/Model/Table/BlogCategoriesTable.php +++ b/plugins/bc-blog/src/Model/Table/BlogCategoriesTable.php @@ -358,21 +358,23 @@ public function hasChild($id) * @param int $blogContentId * @param string $name * @param array $options - * @return array|null + * @return EntityInterface + * @checked + * @noTodo + * @unitTest */ public function getByName($blogContentId, $name, $options = []) { $options = array_merge([ 'conditions' => [ - 'BlogCategory.blog_content_id' => $blogContentId, - 'BlogCategory.name' => urlencode($name), + 'BlogCategories.blog_content_id' => $blogContentId, + 'BlogCategories.name' => urlencode($name), ], 'recursive' => -1 ], $options); - $this->unbindModel(['hasMany' => ['BlogPost']]); - return $this->find('first', $options); - } + return $this->find('all', $options)->first(); + } /** * コピーする * diff --git a/plugins/bc-blog/src/View/Helper/BlogHelper.php b/plugins/bc-blog/src/View/Helper/BlogHelper.php index 058db0e8dd..82d8560e1e 100755 --- a/plugins/bc-blog/src/View/Helper/BlogHelper.php +++ b/plugins/bc-blog/src/View/Helper/BlogHelper.php @@ -2024,15 +2024,20 @@ public function isSameSiteBlogContent($blogContentId) * @param int $blogContentId * @param string $categoryName * @param array $options - * @return array + * @return EntityInterface + * @checked + * @noTodo + * @unitTest */ + public function getCategoryByName($blogContentId, $categoryName = '', $options = []) { if (!$categoryName && $this->getBlogArchiveType() === 'category') { $pass = $this->_View->getRequest()->getParam('pass'); $categoryName = $pass[count($pass) - 1]; } - return ClassRegistry::init('Blog.BlogCategory')->getByName($blogContentId, $categoryName, $options); + $blogCategoriesTable = TableRegistry::getTableLocator()->get('BcBlog.BlogCategories'); + return $blogCategoriesTable->getByName($blogContentId, $categoryName, $options); } /** diff --git a/plugins/bc-blog/tests/TestCase/Model/BlogCategoriesTableTest.php b/plugins/bc-blog/tests/TestCase/Model/BlogCategoriesTableTest.php index 4ee4020461..fd6bd576af 100755 --- a/plugins/bc-blog/tests/TestCase/Model/BlogCategoriesTableTest.php +++ b/plugins/bc-blog/tests/TestCase/Model/BlogCategoriesTableTest.php @@ -504,8 +504,11 @@ public function testHasChild() */ public function testGetByName($blogCategoryId, $name, $expects) { - $this->markTestIncomplete('こちらのテストはまだ未確認です'); - $result = $this->BlogCategory->getByName($blogCategoryId, $name); + //データ生成 + BlogCategoryFactory::make(['name' => 'child', 'blog_content_id' => 1])->persist(); + BlogCategoryFactory::make(['name' => 'name', 'blog_content_id' => 2])->persist(); + $result = $this->BlogCategoriesTable->getByName($blogCategoryId, $name); + //戻り値を確認 $this->assertEquals($expects, (bool)$result); } diff --git a/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php b/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php index 4cc4e57db9..365db7005e 100755 --- a/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php +++ b/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php @@ -1532,23 +1532,33 @@ public function testIsSameSiteBlogContent() } /** - * testGetCategoryByName - * @dataProvider getCategoryByName + * getCategoryByName + * @dataProvider getCategoryByNameDataprovider */ public function testGetCategoryByName($blogCategoryId, $type, $pass, $name, $expects) { - $this->markTestIncomplete('こちらのテストはまだ未確認です'); - $this->Blog->request = $this->_getRequest('/'); - $this->View->set('blogArchiveType', $type); - $this->Blog->request->params['pass'][1] = $pass; + //データ生成 + BlogCategoryFactory::make([ + 'blog_content_id' => 1, + 'name' => 'child', + ])->persist(); + + SiteFactory::make(['id' => 1])->persist(); + $this->Blog->getView()->setRequest($this->getRequest('/')->withAttribute('currentSite', SiteFactory::get(1))); + $this->Blog->getView()->set('blogArchiveType', $type); + + //pass param + $this->Blog->getView()->setRequest($this->getRequest()->withParam('pass', $pass)); $result = $this->Blog->getCategoryByName($blogCategoryId, $name); + + //check result $this->assertEquals($expects, (bool)$result); } - public static function getCategoryByName() + public static function getCategoryByNameDataprovider() { return [ - [1, 'category', 'child', '', true], + [1, 'category', ['child'], '', true], [1, 'hoge', '', 'child', true], [1, 'hoge', '', '', false] ];