Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unitTest BlogHelper::getCurrentBlogTag #3151

Merged
merged 10 commits into from
Mar 4, 2024
9 changes: 3 additions & 6 deletions plugins/bc-blog/src/Model/Table/BlogTagsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,12 @@ public function hasNewTagAddablePermission($userGroupId, $blogContentId)
/**
* 指定した名称のブログタグ情報を取得する
*
* @param string $name
* @return array
* @param $name
* @return EntityInterface
*/
public function getByName($name)
{
return $this->find('first',
conditions: ['BlogTag.name' => $name],
recursive: -1,
callbacks: false);
return $this->find()->where(['BlogTags.name' => $name])->first();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions plugins/bc-blog/src/View/Helper/BlogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2050,14 +2050,15 @@ public function getPostCount()
* 現在のブログタグアーカイブのブログタグ情報を取得する
*
* @return array
* @unitTest
*/
public function getCurrentBlogTag()
{
$blogTag = [];
if ($this->isTag()) {
$pass = $this->_View->getRequest()->getParam('pass');
$name = isset($pass[1])? $pass[1] : '';
$BlogTagModel = ClassRegistry::init('Blog.BlogTag');
$name = isset($pass[1]) ? $pass[1] : '';
$BlogTagModel = TableRegistry::getTableLocator()->get('BcBlog.BlogTags');
$blogTag = $BlogTagModel->getByName(rawurldecode($name));
}
return $blogTag;
Expand Down
8 changes: 5 additions & 3 deletions plugins/bc-blog/tests/TestCase/Model/BlogTagsTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ public static function findCustomParamsDataProvider()
*/
public function testGetByName($name, $expects)
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$result = $this->BlogTag->getByName($name);
$this->assertEquals($expects, (bool)$result);
BlogTagFactory::make(['id' => 1, 'name' => 'タグ1'])->persist();
BlogTagFactory::make(['id' => 2, 'name' => 'タグ2'])->persist();
HungDV2022 marked this conversation as resolved.
Show resolved Hide resolved
$rs = $this->BlogTagsTable->getByName($name);
//戻る値を確認
HungDV2022 marked this conversation as resolved.
Show resolved Hide resolved
$this->assertEquals($expects, (bool)$rs);
}

public static function getByNameDataProvider()
Expand Down
31 changes: 20 additions & 11 deletions plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1768,28 +1768,37 @@ public static function isTagDataProvider()
*/
public function testGetCurrentBlogTag($url, $type, $isTag, $expects)
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$this->Blog->request = $this->_getRequest($url);
$this->View->set('blogArchiveType', $type);
//create data test
BlogTagFactory::make([
'name' => '新製品',
'id' => '1',
'created' => '2015-08-10 18:57:47',
HungDV2022 marked this conversation as resolved.
Show resolved Hide resolved
])->persist();

SiteFactory::make(['id' => 1])->persist();
$this->Blog->getView()->setRequest($this->getRequest($url)->withAttribute('currentSite', SiteFactory::get(1)));
$this->Blog->getView()->set('blogArchiveType', $type);
//check blog isTag
$result = $this->Blog->isTag();
$this->assertEquals($isTag, $result);

//check data expects
$result = $this->Blog->getCurrentBlogTag();
$this->assertEquals($expects, $result);
$actual = (!empty($result)) ? $result->toArray() : [];
unset($actual['created']);
unset($actual['modified']);
$this->assertEquals($expects, $actual);
}

public static function getCurrentBlogTagDataProvider()
{
return [
['/news/archives/tag/新製品', 'tag', true, [
'BlogTag' => [
'name' => '新製品',
['/news/archives/tag/新製品', 'tag', true,
[
'id' => '1',
'created' => '2015-08-10 18:57:47',
'modified' => null,
],
]],
'name' => '新製品',
]
],
['/news/archives/tag/test1', 'tag', true, []],
['/news/archives/category/test2', 'category', false, []],
];
Expand Down
Loading