Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Merge branch 'dev-5' into dev-baserproject#2773-dev5-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
nghiem-mb committed Nov 21, 2023
2 parents 190c78e + 2a38c16 commit 11fabd1
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 14 deletions.
13 changes: 13 additions & 0 deletions plugins/bc-blog/src/Service/BlogContentsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,19 @@ public function getContentsTemplateRelativePath(array $options): string
return 'BcBlog...' . DS . 'Blog' . DS . $options['contentsTemplate'] . DS . $options['template'];
}

/**
* コンテンツ名よりブログコンテンツを取得する
*
* Contents を含む
*
* @param string $name
* @return array|EntityInterface|null
*/
public function findByName(string $name)
{
return $this->BlogContents->find()->where(['Contents.name' => $name])->contain('Contents')->first();
}

/**
* 検索インデックスの再構築が必要か判定
*
Expand Down
40 changes: 29 additions & 11 deletions plugins/bc-blog/src/View/Helper/BlogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ public function blogName()
*
* @return string
* @checked
* @noTodo
*/
public function getBlogName()
{
// TODO $this->currentContent に変更する
return $this->_View->getRequest()->getAttribute('currentContent')->name;
return $this->currentContent->name;
}

/**
Expand All @@ -250,11 +250,11 @@ public function title()
*
* @return string
* @checked
* @noTodo
*/
public function getTitle()
{
// TODO $this->currentContent に変更する
return $this->_View->getRequest()->getAttribute('currentContent')->title;
return $this->currentContent->title;
}

/**
Expand Down Expand Up @@ -992,7 +992,7 @@ public function getPostImg($post, $options = [])
}
$img = $this->BcBaser->getImg($url, $options);
if ($link) {
return $this->BcBaser->getLink($img, $this->_View->getRequest()->getAttribute('currentContent')->url . 'archives/' . $post->no);
return $this->BcBaser->getLink($img, $this->currentContent->url . 'archives/' . $post->no);
} else {
return $img;
}
Expand Down Expand Up @@ -1684,7 +1684,24 @@ public function posts($contentsName = [], $num = 5, $options = [])
} else {
$data = ['posts' => $blogPosts];
}

if(is_array($contentsName)) {
$blogContent = $blogContentsService->findByName($contentsName[0]);
} else {
$blogContent = $blogContentsService->findByName($contentsName);
}

$currentBlogContentId = null;
if($this->currentBlogContent) {
$currentBlogContentId = $this->currentBlogContent->id;
}

$this->setContent($blogContent->id);
$this->BcBaser->element($template, $data);

if($currentBlogContentId) {
$this->setContent($currentBlogContentId);
}
}

/**
Expand Down Expand Up @@ -1741,7 +1758,7 @@ public function parseContentName($contentsName, $options)
}
}
if ($options['autoSetCurrentBlog'] && empty($options['contentUrl']) && empty($options['contentId'])) {
$currentContent = $this->_View->getRequest()->getAttribute('currentContent');
$currentContent = $this->currentContent;
if ($this->isBlog() && !empty($currentContent->entity_id)) {
$options['contentId'] = $currentContent->entity_id;
}
Expand Down Expand Up @@ -1878,11 +1895,11 @@ private function _mergePostCountToBlogsData(array $blogsData)
*
* @return bool
* @checked
* @noTodo
*/
public function isBlog()
{
// TODO $this->currentContent に変更
return (!empty($this->_View->getRequest()->getAttribute('currentContent')->plugin) && $this->_View->getRequest()->getAttribute('currentContent')->plugin == 'BcBlog');
return (!empty($this->currentContent->plugin) && $this->currentContent->plugin == 'BcBlog');
}

/**
Expand All @@ -1909,6 +1926,7 @@ public function getContentsUrl(int $blogContentId, $base = true)
* @param int $blogContentId ブログコンテンツID
* @return bool
* @checked
* @noTodo
*/
public function isSameSiteBlogContent($blogContentId)
{
Expand All @@ -1919,9 +1937,9 @@ public function isSameSiteBlogContent($blogContentId)
])->first();
$siteId = $content->site_id;
$currentSiteId = 0;
// TODO $this->currentContent に変更
if (!empty($this->_View->getRequest()->getAttribute('currentContent')->alias_id)) {
$content = $contentsTable->get($this->_View->getRequest()->getAttribute('currentContent')->alias_id);

if (!empty($this->currentContent->alias_id)) {
$content = $contentsTable->get($this->currentContent->alias_id);
$currentSiteId = $content->site_id;
} elseif ($this->_View->getRequest()->getAttribute('currentSite')->id) {
$currentSiteId = $this->_View->getRequest()->getAttribute('currentSite')->id;
Expand Down
13 changes: 13 additions & 0 deletions plugins/bc-blog/tests/TestCase/Service/BlogContentsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,17 @@ public function test_getContentsTemplateRelativePath()
$this->assertEquals($rs, 'BcBlog.../Blog/default/posts');

}

/**
* test findByName
* @return void
*/
public function testFindByName()
{
$this->loadFixtureScenario(BlogContentScenario::class, 1, 1, null, 'test', '/test');
$blogContent = $this->BlogContentsService->findByName('test');
$this->assertEquals($blogContent->id, 1);
$this->assertEquals($blogContent->content->url, '/test');
$this->assertNull($this->BlogContentsService->findByName('non'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ public function getTagLinkDataProvider()
* @param expected string 期待値
* @param message string テスト失敗時に表示されるメッセージ
* @dataProvider postsDataProvider
* @todo $this->currentContent が初期状態で固定ページになっている場合に正常に動作するテストを追加する
*/
public function testPosts($currentUrl, $contentsName, $num, $options, $expected, $message = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ public function img(ThemeFilesAdminServiceInterface $service)
* @param ThemeFilesAdminService $service
* @checked
* @noTodo
* @unitTest
*/
public function img_thumb(ThemeFilesAdminServiceInterface $service)
{
Expand Down Expand Up @@ -598,6 +599,7 @@ public function img_thumb(ThemeFilesAdminServiceInterface $service)
* @return array
* @checked
* @noTodo
* @unitTest
*/
protected function parseArgs($args)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class BcThemeFileServiceProvider extends ServiceProvider
* @param \Cake\Core\ContainerInterface $container
* @checked
* @noTodo
* @unitTest
*/
public function services($container): void
{
Expand Down
1 change: 1 addition & 0 deletions plugins/bc-theme-file/src/Utility/BcThemeFileUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BcThemeFileUtil
* @return false|mixed
* @checked
* @noTodo
* @unitTest
*/
public static function getTemplateTypeName(string $type)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,14 +577,64 @@ public function test_img()
*/
public function test_img_thumb()
{
$this->markTestIncomplete('このテストは未実装です。');
$this->enableSecurityToken();
$this->enableCsrfToken();

//GETメソッドを検証場合
$this->get('/baser/admin/bc-theme-file/theme_files/img_thumb/BcColumn/img/logo.png');
//取得データを確認
$this->assertNotNull($this->_controller->getResponse());
}

/**
* test parseArgs
* @dataProvider parseArgsDataProvider
*/
public function test_parseArgs()
public function test_parseArgs($args, $expected)
{
$this->markTestIncomplete('このテストは未実装です。');
$rs = $this->execPrivateMethod($this->ThemeFilesController, 'parseArgs', [$args]);
$this->assertEquals($rs['fullpath'], $expected);
}

public function parseArgsDataProvider()
{
return [
[
[
'BcThemeSample',
'layout',
'new_folder',
],
'/var/www/html/plugins/BcThemeSample/templates/layout/new_folder'
],
[
[
'BaserCore',
'BcThemeSample',
'layout',
'new_folder',
],
'/var/www/html/plugins/BcThemeSample/templates/layout/new_folder'
],
[
[
'BcBlog',
'BcThemeSample',
'layout',
'new_folder',
],
'/var/www/html/plugins/BcThemeSample/templates/layout/new_folder'
],
[
[
'BaserCore',
'BcThemeSample',
'layout',
'new_folder',
'default.php',
],
'/var/www/html/plugins/BcThemeSample/templates/layout/new_folder/default.php'
]
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* baserCMS : Based Website Development Project <https://basercms.net>
* Copyright (c) NPO baser foundation <https://baserfoundation.org/>
*
* @copyright Copyright (c) NPO baser foundation
* @link https://basercms.net baserCMS Project
* @since 5.0.0
* @license https://basercms.net/license/index.html MIT License
*/

namespace BcThemeFile\Test\TestCase\ServiceProvider;

use BaserCore\TestSuite\BcTestCase;
use BcThemeFile\ServiceProvider\BcThemeFileServiceProvider;
use Cake\Core\Container;

/**
* Class BcThemeFileServiceProviderTest
* @property BcThemeFileServiceProvider $Provider
*/
class BcThemeFileServiceProviderTest extends BcTestCase
{
/**
* Set Up
*
* @return void
*/
public function setUp(): void
{
parent::setUp();
$this->Provider = new BcThemeFileServiceProvider();
}

/**
* Tear Down
*
* @return void
*/
public function tearDown(): void
{
unset($this->Provider);
parent::tearDown();
}

/**
* Test services
*/
public function testServices()
{
$container = new Container();
$this->Provider->services($container);
$themeFilesService = $container->get('BcThemeFile\Service\ThemeFilesServiceInterface');
$themeFilesAdminService = $container->get('BcThemeFile\Service\Admin\ThemeFilesAdminServiceInterface');
$themeFoldersService = $container->get('BcThemeFile\Service\ThemeFoldersServiceInterface');
$themeFoldersAdminService = $container->get('BcThemeFile\Service\Admin\ThemeFoldersAdminServiceInterface');

$this->assertEquals('BcThemeFile\Service\ThemeFilesService', get_class($themeFilesService));
$this->assertEquals('BcThemeFile\Service\Admin\ThemeFilesAdminService', get_class($themeFilesAdminService));

$this->assertEquals('BcThemeFile\Service\ThemeFoldersService', get_class($themeFoldersService));
$this->assertEquals('BcThemeFile\Service\Admin\ThemeFoldersAdminService', get_class($themeFoldersAdminService));

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* baserCMS : Based Website Development Project <https://basercms.net>
* Copyright (c) NPO baser foundation <https://baserfoundation.org/>
*
* @copyright Copyright (c) NPO baser foundation
* @link https://basercms.net baserCMS Project
* @since 5.0.0
* @license https://basercms.net/license/index.html MIT License
*/

namespace BcThemeFile\Test\TestCase\Utility;

use App\Application;
use BaserCore\Service\UsersService;
use BaserCore\Service\UsersServiceInterface;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use BcThemeFile\Utility\BcThemeFileUtil;

/**
* Class BcThemeFileUtilTest
* @property BcThemeFileUtil $BcThemeFileUtil
*/
class BcThemeFileUtilTest extends BcTestCase
{
/**
* Trait
*/
use BcContainerTrait;

/**
* set up
*/
public function setUp(): void
{
parent::setUp();
}

/**
* tearDown
*
* @return void
*/
public function tearDown(): void
{
parent::tearDown();
}

/**
* test getTemplateTypeName
* @dataProvider getTemplateTypeNameProvider
*/
public function test_getTemplateTypeName($type, $expected)
{
$rs = BcThemeFileUtil::getTemplateTypeName($type);
$this->assertEquals($expected, $rs);
}

public function getTemplateTypeNameProvider()
{

return [
['layout', 'レイアウトテンプレート'],
['element', 'エレメントテンプレート'],
['email', 'Eメールテンプレート'],
['etc', 'コンテンツテンプレート'],
['css', 'スタイルシート'],
['js', 'Javascript'],
['img', 'イメージ'],
['other', false],
];
}
}

0 comments on commit 11fabd1

Please sign in to comment.