From 16bc14fc629d5a1d4a60adf3a95e435f3f1be0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Thu, 15 Feb 2024 10:31:46 +0900 Subject: [PATCH] =?UTF-8?q?BlogHelper::isArchive=20=E3=81=AE=E3=83=A6?= =?UTF-8?q?=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bc-blog/src/View/Helper/BlogHelper.php | 3 +- .../TestCase/View/Helper/BlogHelperTest.php | 29 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/plugins/bc-blog/src/View/Helper/BlogHelper.php b/plugins/bc-blog/src/View/Helper/BlogHelper.php index 9363245739..8c024306d6 100755 --- a/plugins/bc-blog/src/View/Helper/BlogHelper.php +++ b/plugins/bc-blog/src/View/Helper/BlogHelper.php @@ -1118,10 +1118,11 @@ public function getBlogArchiveType() * @return boolean 現在のページがアーカイブページの場合は true を返す * @checked * @noTodo + * @unitTest */ public function isArchive() { - return ($this->getBlogArchiveType()); + return ($this->getBlogArchiveType() == 'archive'); } /** diff --git a/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php b/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php index b8cf296b2e..9cc959e6ef 100755 --- a/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php +++ b/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php @@ -1533,7 +1533,7 @@ public function testIsTag($type, $expects) /** - * test isArchive + * test isCategory * @dataProvider isCategoryDataProvider * */ @@ -1559,6 +1559,33 @@ public static function isCategoryDataProvider() ]; } + /** + * test isArchive + * @dataProvider isArchiveDataProvider + */ + public function test_isArchive($type, $expects) + { + SiteFactory::make(['id' => 1, 'status' => true])->persist(); + $this->Blog->getView()->setRequest($this->getRequest()->withAttribute('currentSite', SiteFactory::get(1))); + $this->Blog->getView()->set('blogArchiveType', $type); + $result = $this->Blog->isArchive(); + $this->assertEquals($expects, $result); + } + + public static function isArchiveDataProvider() + { + return [ + ['archive', true], + ['category', false], + ['tag', false], + ['yearly', false], + ['monthly', false], + ['daily', false], + ['hoge', false], // 存在しないアーカイブの場合 + ['', false], // アーカイブ指定がない場合 + ]; + } + /** * test isDate