Skip to content

Commit

Permalink
add unitTest_BlogHelper_isSingle (#3187)
Browse files Browse the repository at this point in the history
Co-authored-by: thangnn <[email protected]>
  • Loading branch information
thangnnmd and thangnn authored Mar 13, 2024
1 parent 112087e commit 7f0c634
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions plugins/bc-blog/src/View/Helper/BlogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,7 @@ public function isYear()
* @return boolean 現在のページが個別ページの場合は true を返す
* @checked
* @noTodo
* @unitTest
*/
public function isSingle()
{
Expand All @@ -1206,8 +1207,7 @@ public function isSingle()
}
return ($this->_View->getRequest()->getParam('plugin') == 'BcBlog' &&
$this->_View->getRequest()->getParam('controller') == 'Blog' &&
$this->_View->getRequest()->getParam('action') == 'archives' &&
!$this->getBlogArchiveType());
$this->_View->getRequest()->getParam('action') == 'archives' && !$this->getBlogArchiveType());
}

/**
Expand Down
24 changes: 24 additions & 0 deletions plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,30 @@ public static function isYearDataProvider()
];
}

/**
* test isSingle
*/
public function test_isSingle()
{
SiteFactory::make(['id' => 1])->persist();
//param is empty
$this->Blog->getView()->setRequest($this->getRequest()->withAttribute('currentSite', SiteFactory::get(1)));
$result = $this->Blog->isSingle();
$this->assertFalse($result);

//param is not empty
$this->Blog->getView()->setRequest($this->getRequest('/news/archives/1')->withAttribute('currentSite', SiteFactory::get(1)));
$result = $this->Blog->isSingle();
$this->assertTrue($result);

//BlogArchiveType is not empty
$this->Blog->getView()->setRequest($this->getRequest('/news/archives/2016/02/10/post-1')->withAttribute('currentSite', SiteFactory::get(1)));
$this->Blog->getView()->set('blogArchiveType', 'daily');
$result = $this->Blog->isSingle();
$this->assertFalse($result);

}

public static function isTagDataProvider()
{
return [
Expand Down

0 comments on commit 7f0c634

Please sign in to comment.