From 0963f949ff368b33927dadc843315e8c418befcc Mon Sep 17 00:00:00 2001 From: thangnn Date: Fri, 1 Mar 2024 11:06:29 +0700 Subject: [PATCH 1/3] add unitTest_BlogHelper_isSingle --- .../bc-blog/src/View/Helper/BlogHelper.php | 4 ++-- .../TestCase/View/Helper/BlogHelperTest.php | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/plugins/bc-blog/src/View/Helper/BlogHelper.php b/plugins/bc-blog/src/View/Helper/BlogHelper.php index f16352a58f..ebfb6caff2 100755 --- a/plugins/bc-blog/src/View/Helper/BlogHelper.php +++ b/plugins/bc-blog/src/View/Helper/BlogHelper.php @@ -1198,6 +1198,7 @@ public function isYear() * @return boolean 現在のページが個別ページの場合は true を返す * @checked * @noTodo + * @unitTest */ public function isSingle() { @@ -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()); } /** diff --git a/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php b/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php index 8775c5bf4f..0c5da20bdf 100755 --- a/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php +++ b/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php @@ -1749,6 +1749,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/2016/02/10/post-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 [ From 0da73d469f401ff884cb0271b9b66343cdd444db Mon Sep 17 00:00:00 2001 From: thangnn Date: Tue, 5 Mar 2024 09:57:24 +0700 Subject: [PATCH 2/3] change url --- plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php b/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php index 0c5da20bdf..81786dd315 100755 --- a/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php +++ b/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php @@ -1761,12 +1761,12 @@ public function test_isSingle() $this->assertFalse($result); //param is not empty - $this->Blog->getView()->setRequest($this->getRequest('/news/archives/2016/02/10/post-1')->withAttribute('currentSite', SiteFactory::get(1))); + $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()->setRequest($this->getRequest('/news/archives/1')->withAttribute('currentSite', SiteFactory::get(1))); $this->Blog->getView()->set('blogArchiveType', 'daily'); $result = $this->Blog->isSingle(); $this->assertFalse($result); From 1c35055f20c07a501a0cd4ca3d2b40e02347d078 Mon Sep 17 00:00:00 2001 From: thangnn Date: Wed, 6 Mar 2024 22:47:27 +0700 Subject: [PATCH 3/3] add unitTest_BlogHelper_isSingle --- plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php b/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php index 81786dd315..add647d7d1 100755 --- a/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php +++ b/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php @@ -1766,7 +1766,7 @@ public function test_isSingle() $this->assertTrue($result); //BlogArchiveType is not empty - $this->Blog->getView()->setRequest($this->getRequest('/news/archives/1')->withAttribute('currentSite', SiteFactory::get(1))); + $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);