Skip to content

Commit

Permalink
BlogHelper::isArchive のユニットテスト (#3122)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <[email protected]>
  • Loading branch information
HungDV2022 and dovanhung authored Feb 17, 2024
1 parent b132c18 commit 508b2af
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugins/bc-blog/src/View/Helper/BlogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ public function getBlogArchiveType()
* @return boolean 現在のページがアーカイブページの場合は true を返す
* @checked
* @noTodo
* @unitTest
*/
public function isArchive()
{
Expand Down
28 changes: 27 additions & 1 deletion plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ public function testIsTag($type, $expects)


/**
* test isArchive
* test isCategory
* @dataProvider isCategoryDataProvider
*
*/
Expand All @@ -1584,6 +1584,32 @@ 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 [
['category', true],
['tag', true],
['yearly', true],
['monthly', true],
['daily', true],
['hoge', true], // 存在しないアーカイブの場合
['', false], // アーカイブ指定がない場合
];
}


/**
* test isDate
Expand Down

0 comments on commit 508b2af

Please sign in to comment.