Skip to content

Commit

Permalink
Merge branch 'dev-5' into dev-cake45
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Oct 28, 2023
2 parents d9cc211 + 9a22188 commit ce1486c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 43 deletions.
2 changes: 1 addition & 1 deletion plugins/baser-core/config/bc_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
'radioWrapper' => '<span class="{{class}}">{{label}}</span>',
'radioFormGroup' => '<span class="{{groupClass}}">{{input}}</span>',
// Textarea input element,
'textarea' => '<textarea name="{{name}}"{{attrs}}>{{value}}</textarea>',
'textarea' => "<textarea name=\"{{name}}\"{{attrs}}>\n{{value}}\n</textarea>",
// Container for submit buttons.
// 'submitContainer' => '<div class="submit">{{content}}</div>' NOTE: formAfterCreateにてデザインが崩れるため一旦コメントアウト
'submitContainer' => '{{content}}',
Expand Down
17 changes: 15 additions & 2 deletions plugins/bc-blog/src/View/Helper/BlogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Datasource\ResultSetInterface;
use Cake\Filesystem\Folder;
use Cake\ORM\TableRegistry;
Expand Down Expand Up @@ -114,6 +115,8 @@ class BlogHelper extends Helper
public function __construct(View $view, array $config = [])
{
parent::__construct($view, $config);
// インストールが完了している場合のみ実行
// インストール時に呼び出された際にサービスが利用できないため
if(BcUtil::isInstalled()) {
$this->BlogContentsService = $this->getService(BlogContentsServiceInterface::class);
$this->setContent();
Expand All @@ -139,18 +142,28 @@ public function setContent($blogContentId = null)

if($blogContentId) {
if(!$this->BlogContentsService) return;
$this->currentBlogContent = $this->BlogContentsService->get($blogContentId);
try {
$this->currentBlogContent = $this->BlogContentsService->get($blogContentId);
} catch(RecordNotFoundException) {
$this->currentBlogContent = null;
$this->currentContent = null;
return;
} catch(\Throwable $e) {
throw $e;
}
$contentTable = TableRegistry::getTableLocator()->get('BaserCore.Contents');
// 現在のサイトにエイリアスが存在するのであればそちらを優先する
$site = $this->_View->getRequest()->getAttribute('currentSite');
$content = null;
if (!empty($site->id)) {
$content = $contentTable->find()->where([
'Contents.entity_id' => $this->currentBlogContent->id,
'Contents.type' => 'BlogContent',
'Contents.alias_id IS NOT' => null,
'Contents.site_id' => $site->id
])->first();
} else {
}
if(!$content) {
$content = $contentTable->find()->where([
'Contents.entity_id' => $this->currentBlogContent->id,
'Contents.type' => 'BlogContent',
Expand Down
42 changes: 2 additions & 40 deletions plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,46 +83,6 @@ public function test__construct()
$this->assertEquals(1, $this->Blog->currentContent->id);
}

/**
* ブログコンテンツデータをセットする
*
* @param int $blogContentId ブログコンテンツID
* @param bool $viewVars viewVarsを設定
* @dataProvider setContentDataProvider
*/
public function testSetContent($blogContentId, $viewVars, $expected)
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
// if ($viewVars) {
// $View = new View();
// $View->viewVars = ['blogContent' => [
// 'BlogContent' => [
// 'id' => 3,
// 'name' => 'test',
// ]
// ]];
// $View->request = $this->_getRequest('/');
// $View->request->params['Content']['type'] = 'BlogContent';
// $this->Blog = new BlogHelper($View);
// }
// $this->Blog->blogContent = null;
// $this->Blog->setContent($blogContentId);
// $result = null;
// if (!empty($this->Blog->blogContent['id'])) {
// $result = $this->Blog->blogContent['id'];
// }
// $this->assertEquals($result, $expected, 'ブログコンテンツデータを正しくセットできません');
}

public function setContentDataProvider()
{
return [
[null, false, null],
[2, false, 2],
[null, true, 3],
];
}

/**
* ブログIDを取得する
*/
Expand Down Expand Up @@ -226,6 +186,7 @@ public function testGetPostLinkUrl($blogContentId, $baseUrl, $useBase, $expects)
{
$this->truncateTable('contents');
$this->truncateTable('blog_contents');
$this->truncateTable('blog_posts');

// データ生成
$this->loadFixtureScenario(MultiSiteBlogPostScenario::class);
Expand Down Expand Up @@ -431,6 +392,7 @@ public function testGetCategoryUrl($blogCategoryId, $base, $useBase, $expected)
{
$this->truncateTable('contents');
$this->truncateTable('blog_contents');
$this->truncateTable('blog_categories');
$this->loadFixtureScenario(MultiSiteBlogScenario::class);

$blogContent = BlogContentFactory::get(6);
Expand Down

0 comments on commit ce1486c

Please sign in to comment.