Skip to content

Commit

Permalink
Merge branch 'dev-5' of github.com:baserproject/basercms into dev-5
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Oct 1, 2023
2 parents 5ba8451 + ccdc73e commit acb1d7c
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 6 deletions.
7 changes: 5 additions & 2 deletions plugins/baser-core/src/Utility/BcFileUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -909,17 +909,20 @@ 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;
} else {
$request = Router::getRequest();

if (is_null($request)) return false;

$site = $request->getAttribute('currentSite');
if ($site && $site->theme) {
$basePath = ROOT . DS . 'plugins' . DS . $site->theme . DS . 'webroot' . DS . '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
2 changes: 1 addition & 1 deletion plugins/baser-core/src/View/Helper/BcUploadHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public function uploadImage($fieldName, $entity, $options = [])
$fileUrl = $this->getBasePath($settings);;
$fileUrlInTheme = $this->getBasePath($settings, true);
$saveDir = $this->table->getSaveDir(false, $options['limited']);
$saveDirInTheme = $this->table->getSaveDir(true, $options['limited']);
$saveDirInTheme = $this->table->getSaveDir(true, $options['limited']) ?? '';

$settingField = $fieldName;
if(strpos($fieldName, '.') !== false) {
Expand Down
18 changes: 18 additions & 0 deletions plugins/bc-blog/src/Model/Entity/BlogPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
use BaserCore\Annotation\UnitTest;
use BaserCore\Annotation\NoTodo;
use BaserCore\Annotation\Checked;
use BcBlog\View\Helper\BlogHelper;
use Cake\I18n\FrozenTime;
use Cake\ORM\Entity;
use Cake\View\View;

/**
* Class BlogPost
Expand Down Expand Up @@ -53,4 +55,20 @@ 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']);
}
}
1 change: 1 addition & 0 deletions plugins/bc-blog/src/View/Helper/BlogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public function __construct(View $view, array $config = [])
public function setContent($blogContentId = null)
{
$blogContentUpdated = false;
$content = false;
if (empty($this->currentBlogContent) || ($blogContentId != $this->currentBlogContent->id)) {
if ($blogContentId) {
if ($this->_View->getRequest()->getQuery('preview') == 'default' && $this->_View->getRequest()->getData()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace BcBlog\Test\TestCase\Controller\Api;

use BaserCore\Test\Factory\ContentFactory;
use BaserCore\Test\Factory\PermissionFactory;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
Expand Down Expand Up @@ -91,7 +92,8 @@ public function test_view()
{
// データを生成
$this->loadFixtureScenario(BlogContentScenario::class, 1, 1, null, 'test', '/test');
BlogPostFactory::make(['id' => '1', 'blog_content_id' => '1', 'title' => 'blog post', 'status' => true])->persist();
BlogPostFactory::make(['id' => '1', 'blog_content_id' => '1', 'title' => 'blog post', 'eye_catch' => 'eye_catch.img', 'status' => true])->persist();
ContentFactory::make(['type' => 'BlogContent', 'entity_id' => 1])->persist();
PermissionFactory::make()->allowGuest('/baser/api/*')->persist();

// APIを呼ぶ
Expand All @@ -101,6 +103,7 @@ public function test_view()
// 戻り値を確認
$result = json_decode((string)$this->_response->getBody());
$this->assertEquals(1, $result->blogPost->id);
$this->assertTextContains('/files/blog/1/blog_posts/eye_catch.img', $result->blogPost->_eyecatch);
$this->assertEquals(1, $result->blogPost->blog_content_id);

//存在しないBlogPostIDをテスト場合、
Expand Down
74 changes: 74 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,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 BcBlog\Test\TestCase\Model\Entity;

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 acb1d7c

Please sign in to comment.