Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BlogHelper::prevLink() のユニットテスト #3134

Merged
merged 4 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/bc-blog/src/View/Helper/BlogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ public function getCategoryList($categories, $depth = 3, $count = false, $option
* @return void
* @checked
* @noTodo
* @unitTest ラッパーメソッドのためユニットテストはスキップする
* @unitTest
*/
public function prevLink(BlogPost $post, string $title = '', array $htmlAttributes = [])
{
Expand Down
51 changes: 40 additions & 11 deletions plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,23 +609,52 @@ public static function getCategoryListDataProvider()
*/
public function testPrevLink($blogContentId, $id, $posts_date, $expected)
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$this->expectOutputString($expected);
$post = ['BlogPost' => [
//データ生成
ContentFactory::make(['plugin' => 'BcBlog', 'type' => 'BlogContent', 'alias_id' => 1])
->treeNode($blogContentId, 1, 3, 'news-2', '/news/', $blogContentId)->persist();
BlogContentFactory::make(['id' => $blogContentId])->persist();
SiteFactory::make()->main()->persist();

BlogPostFactory::make([
'id' => 1,
'no' => 1,
'blog_content_id' => $blogContentId,
'id' => $id,
'posts_date' => $posts_date
]];
$this->Blog->prevLink($post);
'title' => 'title 1',
'posted' => $posts_date
])->persist();
BlogPostFactory::make([
'id' => 2,
'no' => 2,
'blog_content_id' => $blogContentId,
'title' => 'title 2',
'posted' => $posts_date
])->persist();
BlogPostFactory::make([
'id' => 3,
'no' => 3,
'blog_content_id' => 30,
'title' => 'title 3',
'posted' => $posts_date
])->persist();

//currentContentをリセット
$view = new BlogFrontAppView($this->getRequest());
$blogContent = BlogContentFactory::get($blogContentId);
$blogContent->content = ContentFactory::get($blogContentId);
$view->set('blogContent', $blogContent);
$this->Blog = new BlogHelper($view);

$this->expectOutputString($expected);
$this->Blog->prevLink(BlogPostFactory::get($id));
}

public static function prevLinkDataProvider()
{
return [
[1, 4, '9000-08-10 18:58:07', '<a href="/news/archives/4" class="prev-link">≪ 4記事目</a>'],
[1, 3, '1000-08-10 18:58:07', ''],
[2, 2, '9000-08-10 18:58:07', '<a href="/" class="prev-link">≪ 8記事目</a>'], // 存在しないブログコンテンツ
[2, 1, '1000-08-10 18:58:07', ''],
[4, 2, '9000-08-10 18:58:07', '<a href="/news/archives/1" class="prev-link">≪ title 1</a>'],
[4, 1, '1000-08-10 18:58:07', ''],
[3, 3, '9000-08-10 18:58:07', ''],
[3, 2, '1000-08-10 18:58:07', '<a href="/news/archives/1" class="prev-link">≪ title 1</a>'],
];
}

Expand Down
Loading