Skip to content

Commit

Permalink
fix #2403 アップロードファイルのAPIについてフルパスを取得する仕組み
Browse files Browse the repository at this point in the history
  • Loading branch information
dovanhung committed Sep 28, 2023
1 parent 4bc5658 commit 9047087
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 5 deletions.
4 changes: 2 additions & 2 deletions plugins/baser-core/src/Utility/BcFileUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -909,12 +909,12 @@ public function getUniqueFileName(array $setting, array $file, EntityInterface $
* 保存先のフォルダを設定し、取得する
* @param bool $isTheme
* @param bool $limited
* @return string
* @return string|bool
* @checked
* @noTodo
* @unitTest
*/
public function getSaveDir(bool $isTheme = false, bool $limited = false): string
public function getSaveDir(bool $isTheme = false, bool $limited = false): bool|string
{
if (!$isTheme) {
$basePath = WWW_ROOT . 'files' . DS;
Expand Down
10 changes: 8 additions & 2 deletions plugins/baser-core/src/Utility/BcUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -1175,8 +1175,14 @@ public static function getCurrentTheme()
$theme = Inflector::camelize(Inflector::underscore(Configure::read('BcApp.coreFrontTheme')));
if (!BcUtil::isInstalled()) return $theme;
$request = Router::getRequest();
/** @var Site $site */
$site = $request->getAttribute('currentSite');

if (is_null($request))
$site = null;
else{
/** @var Site $site */
$site = $request->getAttribute('currentSite');
}

if ($site) {
if($site->theme) {
return $site->theme;
Expand Down
12 changes: 11 additions & 1 deletion plugins/bc-blog/src/Model/Entity/BlogPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,18 @@ class BlogPost extends Entity
'id' => false
];


/**
* アイキャッチのフルパス
*/
protected $_virtual = ['_eyecatch'];

/**
* アイキャッチのフルパスを取得
* @return string
* @checked
* @noTodo
* @unitTest
*/
protected function _get_eyecatch(){
$BlogHelper = new BlogHelper(new View());
return $BlogHelper->getEyeCatch($this, ['output' => 'url']);
Expand Down
75 changes: 75 additions & 0 deletions plugins/bc-blog/tests/TestCase/Model/Entity/BlogPostTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?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 BcBlog\Test\TestCase\Model\Entity;

use BaserCore\Test\Factory\ContentFactory;
use BaserCore\TestSuite\BcTestCase;
use BcBlog\Model\Entity\BlogPost;
use BcBlog\Test\Scenario\BlogContentScenario;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
* Class BlogPostTest
*/
class BlogPostTest extends BcTestCase
{
/**
* Trait
*/
use ScenarioAwareTrait;

/**
* @var BlogPost
*/
public $BlogPost;

/**
* Set Up
*
* @return void
*/
public function setUp(): void
{
parent::setUp();
$this->BlogPost = $this->getTableLocator()->get('BlogPost.BlogPosts');
}

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

/**
* test _get_eyecatch
*/
public function test_get_eyecatch()
{
$this->loadFixtureScenario(BlogContentScenario::class, 1, 1, null, 'test', '/test');
$blogPost = new BlogPost([
'id' => 1,
'blog_content_id' => 1,
'no' => 1,
'title' => 'blog post title',
'status' => true,
'eye_catch' => 'test.png'
]);
$_eyecatch = $this->execPrivateMethod($blogPost, '_get_eyecatch', []);
$this->assertTextContains('/files/blog/1/blog_posts/test.png', $_eyecatch);
}

}

0 comments on commit 9047087

Please sign in to comment.