Skip to content

Commit

Permalink
BlogHelper::isArchive のユニットテスト
Browse files Browse the repository at this point in the history
  • Loading branch information
dovanhung committed Feb 15, 2024
1 parent 7e30e2f commit 16bc14f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
3 changes: 2 additions & 1 deletion plugins/bc-blog/src/View/Helper/BlogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1118,10 +1118,11 @@ public function getBlogArchiveType()
* @return boolean 現在のページがアーカイブページの場合は true を返す
* @checked
* @noTodo
* @unitTest
*/
public function isArchive()
{
return ($this->getBlogArchiveType());
return ($this->getBlogArchiveType() == 'archive');
}

/**
Expand Down
29 changes: 28 additions & 1 deletion plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ public function testIsTag($type, $expects)


/**
* test isArchive
* test isCategory
* @dataProvider isCategoryDataProvider
*
*/
Expand All @@ -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
Expand Down

0 comments on commit 16bc14f

Please sign in to comment.