Skip to content

Commit dc3d887

Browse files
committed
ユニットテストを追加
1 parent 00aa016 commit dc3d887

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

plugins/bc-blog/src/View/Helper/BlogHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,7 @@ private function _mergePostCountToTagsData(ResultSetInterface $tags, $options)
17041704
* - `autoSetCurrentBlog` : $contentsName を指定していない場合、現在のコンテンツより自動でブログを指定する(初期値:true)
17051705
* - `data` : エレメントに渡したい変数(初期値 : array)
17061706
* - `return` : 出力結果を echo せずに返す場合に true を指定(初期値 : false)
1707-
* @return void
1707+
* @return void|string
17081708
* @checked
17091709
* @noTodo
17101710
* @unitTest

plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace BcBlog\Test\TestCase\View\Helper;
1313

1414
use BaserCore\Test\Factory\ContentFactory;
15-
use BaserCore\Test\Factory\SiteConfigFactory;
15+
use BaserCore\Test\Factory\PluginFactory;
1616
use BaserCore\Test\Factory\SiteFactory;
1717
use BaserCore\Test\Scenario\InitAppScenario;
1818
use BaserCore\Test\Scenario\RootContentScenario;
@@ -67,6 +67,7 @@ public function setUp(): void
6767
'/news/', // url
6868
'test title'
6969
);
70+
PluginFactory::make(['id' => 'BcBlog', 'name' => 'BcBlog', 'status' => true])->persist();
7071
$view = new BlogFrontAppView($this->getRequest());
7172
$blogContent = BlogContentFactory::get(1);
7273
$blogContent->content = ContentFactory::get(1);
@@ -1322,6 +1323,7 @@ public function testPosts($currentUrl, $contentsName, $num, $options, $expected,
13221323
BlogPostFactory::make(['blog_content_id' => 1, 'blog_category_id' => 1, 'posted' => '2017-03-27 12:57:59'])->persist();
13231324
BlogTagFactory::make(['id' => 1, 'name' => '新製品'])->persist();
13241325
BlogPostBlogTagFactory::make(['blog_post_id' => 1, 'blog_tag_id' => 1])->persist();
1326+
SiteFactory::make(['id' => 1])->persist();
13251327

13261328
$this->expectOutputRegex($expected);
13271329

@@ -1367,6 +1369,33 @@ public static function postsDataProvider()
13671369
];
13681370
}
13691371

1372+
/**
1373+
* test posts with return
1374+
* @return void
1375+
*/
1376+
public function testPostsWithReturn()
1377+
{
1378+
$this->truncateTable('contents');
1379+
$this->truncateTable('blog_contents');
1380+
$this->truncateTable('blog_posts');
1381+
1382+
// データ生成
1383+
$this->loadFixtureScenario(
1384+
BlogContentScenario::class,
1385+
1, // id
1386+
1, // siteId
1387+
1, // parentId
1388+
'news', // name
1389+
'/news/', // url,
1390+
'News 1' // title
1391+
);
1392+
SiteFactory::make(['id' => 1])->persist();
1393+
BlogPostFactory::make(['id' => 1, 'blog_content_id' => 1, 'title' => 'title test'])->persist();
1394+
1395+
$result = $this->Blog->posts('/news/', 5, ['return' => true]);
1396+
$this->assertTextContains('title test', $result);
1397+
}
1398+
13701399
/**
13711400
* ブログ記事を取得する
13721401
*/

0 commit comments

Comments
 (0)