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::getBlogTemplates のユニットテスト #3113

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
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 @@ -900,8 +900,9 @@ public function hasNextLink($post)
* @return array ブログテンプレート一覧
* @checked
* @noTodo
* @unitTest
*/
public function getBlogTemplates($siteId = 0)
public function getBlogTemplates($siteId = 1)
{
$templatesPaths = BcUtil::getFrontTemplatePaths($siteId, 'BcBlog');
$_templates = [];
Expand Down
13 changes: 9 additions & 4 deletions plugins/bc-blog/tests/TestCase/Controller/BlogControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use BaserCore\Test\Factory\SiteConfigFactory;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcFile;
use BaserCore\Utility\BcFolder;
use BcBlog\Controller\BlogController;
use BcBlog\Service\BlogContentsServiceInterface;
use BcBlog\Service\BlogPostsServiceInterface;
Expand Down Expand Up @@ -96,17 +97,17 @@ public function test_index()
'description' => 'description test 1'])->persist();
BlogPostFactory::make(['id' => '1', 'blog_content_id' => '1', 'title' => 'blog post'])->persist();
ContentFactory::make(['plugin' => 'BcBlog',
'entity_id' => 1,
'entity_id' => 1,
'status' => true,
'lft' => 1,
'rght' => 2,
'type' => 'BlogContent'])
->treeNode(1, 1, null, 'test', '/test/', 1, true)->persist();
$fullPath = BASER_PLUGINS . 'bc-front/templates/Blog/Blog/default';
if (!file_exists($fullPath)){
if (!file_exists($fullPath)) {
mkdir($fullPath, recursive: true);
}
$file = new BcFile($fullPath .DS. 'index.php');
$file = new BcFile($fullPath . DS . 'index.php');
$file->write('html');
//正常系実行
$request = $this->getRequest()->withAttribute('currentContent', ContentFactory::get(1));
Expand All @@ -117,8 +118,12 @@ public function test_index()

$controller->index($blogFrontService, $blogContentsService, $blogPostsService);
$vars = $controller->viewBuilder()->getVars();
unlink($fullPath.DS.'index.php');
unlink($fullPath . DS . 'index.php');
$this->assertEquals('description test 1', $vars['blogContent']->description);

//不要フォルダを削除
(new BcFolder(BASER_PLUGINS . 'bc-front/templates/Blog'))->delete();

//異常系実行
$request = $this->getRequest()->withAttribute('currentContent', null);
$controller = new BlogController($request);
Expand Down
12 changes: 7 additions & 5 deletions plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace BcBlog\Test\TestCase\View\Helper;

use BaserCore\Test\Factory\ContentFactory;
use BaserCore\Test\Factory\SiteConfigFactory;
use BaserCore\Test\Factory\SiteFactory;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\Test\Scenario\RootContentScenario;
Expand All @@ -27,7 +28,6 @@
use BcBlog\Test\Factory\BlogTagFactory;
use BcBlog\Test\Scenario\BlogContentScenario;
use BcBlog\Test\Scenario\BlogTagsScenario;
use BcBlog\Test\Scenario\MultiBlogPostScenario;
use BcBlog\Test\Scenario\MultiSiteBlogPostScenario;
use BcBlog\Test\Scenario\MultiSiteBlogScenario;
use BcBlog\View\BlogFrontAppView;
Expand Down Expand Up @@ -716,16 +716,18 @@ public static function nextLinkDataProvider()
*/
public function testGetBlogTemplates($theme, $expected)
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$this->Blog->BcBaser->siteConfig['theme'] = $theme;
SiteFactory::make([
'id' => 1,
'theme' => $theme
])->persist();
$result = $this->Blog->getBlogTemplates();
$this->assertEquals($result, $expected, 'ブログテンプレートを正しく取得できません');
$this->assertEquals($expected, $result);
}

public static function getBlogTemplatesDataProvider()
{
return [
['nada-icons', ['default' => 'default']]
['BcThemeSample', ['default' => 'default']]
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function test_getViewVarsForIndex()
//対象メソッドをコール
$rs = $this->ThemeFilesAdminService->getViewVarsForIndex($param);
//戻る値を確認
$this->assertCount(12, $rs['themeFiles']);
$this->assertCount(11, $rs['themeFiles']);
ryuring marked this conversation as resolved.
Show resolved Hide resolved
$this->assertNotNull($rs['currentPath']);
$this->assertNotNull($rs['path']);
$this->assertNotNull($rs['plugin']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function test_getIndex()
$param['fullpath'] = '/var/www/html/plugins/bc-front/templates';
$param['type'] = 'folder';
$themeFiles = $this->ThemeFoldersService->getIndex($param);
$this->assertCount(12, $themeFiles);
$this->assertCount(11, $themeFiles);

//typeはetcかつpathは指定しない場合、
$param['type'] = 'etc';
Expand Down
Loading