Skip to content

Commit

Permalink
Merge branch '5.1.x' of github.com:baserproject/basercms into 5.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Sep 17, 2024
2 parents 792be26 + f4cfa00 commit 5da4814
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 44 deletions.
1 change: 1 addition & 0 deletions plugins/baser-core/src/Utility/BcFileUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ public function deleteFile($setting, $file, $delImagecopy = true)
* @return boolean
* @checked
* @noTodo
* @unitTest
*/
public function moveFileSessionToTmp($data, $fieldName)
{
Expand Down
6 changes: 6 additions & 0 deletions plugins/baser-core/src/View/Helper/BcBaserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,7 @@ public function content()
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function scripts()
{
Expand Down Expand Up @@ -1987,6 +1988,7 @@ public function sitemap($siteId = 0)
* @return string サイトマップ
* @checked
* @noTodo
* @unitTest
*/
public function getSitemap($siteId = 0)
{
Expand Down Expand Up @@ -2065,6 +2067,7 @@ public function isCategoryTop()
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function page($url, $params = [], $options = [])
{
Expand Down Expand Up @@ -2123,6 +2126,7 @@ public function page($url, $params = [], $options = [])
* @return bool 同じ場合には true を返す
* @checked
* @noTodo
* @unitTest
*/
public function isCurrentUrl($url)
{
Expand Down Expand Up @@ -2235,6 +2239,7 @@ public function crumbsList($data = [], $options = [])
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function googleAnalytics($data = [], $options = [])
{
Expand Down Expand Up @@ -2473,6 +2478,7 @@ public function getContentModifiedDate($format = 'Y/m/d H:i')
* 更新情報を出力する
* @checked
* @noTodo
* @unitTest
*/
public function updateInfo(): void
{
Expand Down
29 changes: 13 additions & 16 deletions plugins/baser-core/tests/TestCase/Utility/BcFileUploaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,18 +555,13 @@ public static function saveFilesCanResizeDataProvider()
*/
public function testMoveFileSessionToTmp()
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$tmpId = 1;
$fieldName = 'fieldName';
$tmp_name = 'basercms_tmp';
$basename = 'basename';
$ext = 'png';
$namefield = 'hoge';

//—————————————————————————
// セッションを設定
//—————————————————————————

// パス情報
$tmpPath = $this->savePath . $tmp_name;

Expand All @@ -577,24 +572,26 @@ public function testMoveFileSessionToTmp()
];
$this->BcFileUploader->tmpId = $tmpId;

$this->uploadedData['eyecatch']['name'] = $basename . '.' . $ext;
$this->uploadedData['eyecatch']['tmp_name'] = $tmpPath;
$this->uploadedData['eyecatch']['type'] = 'basercms';
$this->uploadedData['eyecatch']['ext'] = $ext;

// ダミーファイルの作成
$file = new BcFile($tmpPath);
$file->create();
$file->write('dummy');

// UploadedFileオブジェクトの作成
$uploadedFile = new UploadedFile(
$tmpPath,
filesize($tmpPath),
UPLOAD_ERR_OK,
$basename . '.' . $ext,
'image/png'
);

$this->uploadedData['eyecatch'] = $uploadedFile;

// セッションを設定
$entity = $this->BcFileUploader->saveTmpFiles($this->uploadedData, $tmpId);

//—————————————————————————
// 本題
//—————————————————————————

// パス情報
$targetName = $entity->eyecatch_tmp;
$targetPath = $this->savePath . str_replace(['.', '/'], ['_', '_'], $targetName);

Expand All @@ -610,11 +607,11 @@ public function testMoveFileSessionToTmp()
$this->assertFileExists($targetPath, 'セッションに保存されたファイルデータをファイルとして保存できません');
$result = $this->BcFileUploader->getUploadingFiles($bcUploadId)[$fieldName];
$expected = [
'error' => 0,
'error' => UPLOAD_ERR_OK,
'name' => $targetName,
'tmp_name' => $targetPath,
'size' => 5,
'type' => 'basercms',
'type' => 'image/png',
'uploadable' => true,
'ext' => 'png'
];
Expand Down
86 changes: 63 additions & 23 deletions plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
use BaserCore\Test\Factory\ContentFactory;
use BaserCore\Test\Factory\PageFactory;
use BaserCore\Test\Factory\PluginFactory;
use BaserCore\Test\Factory\SiteConfigFactory;
use BaserCore\Test\Factory\SiteFactory;
use BaserCore\Test\Factory\UserFactory;
use BaserCore\Test\Factory\UserGroupFactory;
use BaserCore\Test\Factory\UsersUserGroupFactory;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\Utility\BcUtil;
use BaserCore\View\Helper\BcContentsHelper;
use BaserCore\View\Helper\BcHtmlHelper;
use Cake\Datasource\Paging\PaginatedResultSet;
use Cake\Http\Exception\NotFoundException;
use Cake\ORM\ResultSet;
Expand Down Expand Up @@ -1120,51 +1122,65 @@ public function testContent()
*/
public function testScripts()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');

$themeConfigTag = '<link rel="stylesheet" type="text/css" href="/files/theme_configs/config.css" />';

// CSS
$expected = "\n" . '<meta name="generator" content="basercms"/><link rel="stylesheet" type="text/css" href="/css/admin/layout.css"/>';
$this->BcBaser->css('admin/layout', ['inline' => false]);
$expected = '
<meta name="generator" content="basercms"/>
<link rel="stylesheet" href="/css/admin/layout.css">
';
ob_start();
$this->BcBaser->css('admin/layout', false);
$this->BcBaser->scripts();
$result = ob_get_clean();
$result = str_replace($themeConfigTag, '', $result);
$this->assertEquals($expected, $result);
$this->_View->assign('css', '');

$view = $this->BcBaser->getView();
$view->assign('css', '');
$this->BcBaser = new BcBaserHelper($view);

Configure::write('BcApp.outputMetaGenerator', false);

// Javascript
$expected = '<script type="text/javascript" src="/js/admin/startup.js"></script>';
$expected = '
<script src="/js/admin/startup.js"></script>';
$this->BcBaser->js('admin/startup', false);
ob_start();
$this->BcBaser->scripts();
$result = ob_get_clean();
$result = str_replace($themeConfigTag, '', $result);
$this->assertEquals($expected, $result);
$this->_View->assign('script', '');

$view->assign('script', '');
$this->BcBaser = new BcBaserHelper($view);

// meta
$expected = '<meta name="description" content="説明文"/>';
App::uses('BcHtmlHelper', 'View/Helper');
$BcHtml = new BcHtmlHelper($this->_View);
$expected = '<meta name="description" content="説明文">
';
$BcHtml = new BcHtmlHelper($view);
$BcHtml->meta('description', '説明文', ['inline' => false]);
$view->assign('meta',
$BcHtml->meta('description', '説明文', ['inline' => false])
);
ob_start();
$this->BcBaser->scripts();
$result = ob_get_clean();
$result = str_replace($themeConfigTag, '', $result);
$this->assertEquals($expected, $result);
$this->_View->assign('meta', '');
$view->assign('meta', '');
$this->BcBaser = new BcBaserHelper($view);

$this->loadFixtureScenario(InitAppScenario::class);
// ツールバー
$expected = '<link rel="stylesheet" type="text/css" href="/css/admin/toolbar.css"/>';
$expected = '<link rel="stylesheet" href="/css/admin/toolbar.css"><link rel="stylesheet" href="/bc_blog/css/admin/bc_blog_admin.css"><link rel="stylesheet" href="/bc_custom_content/css/admin/bc_custom_content_admin.css"><link rel="stylesheet" href="/bc_mail/css/admin/bc_mail_admin.css"><link rel="stylesheet" href="/bc_uploader/css/admin/bc_uploader_admin.css">
';
$this->BcBaser->set('user', ['User']);
$this->loginAdmin($this->getRequest('/baser/admin'));
ob_start();
$this->BcBaser->scripts();
$result = ob_get_clean();
$result = str_replace($themeConfigTag, '', $result);
$this->assertEquals($expected, $result);
}

Expand Down Expand Up @@ -1519,22 +1535,32 @@ public static function markDataProvider()
* @param string $recursive 取得する階層
* @param boolean $expected 期待値
* @dataProvider getSitemapDataProvider
* @TODO : 階層($recursive)を指定した場合のテスト
*/

public function testGetSitemap($siteId, $expected)
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$message = 'サイトマップを正しく出力できません';
ContentFactory::make(['id' => 1, 'url' => '/', 'site_id' => 1, 'parent_id' => 0, 'lft' => 1, 'rght' => 10])->persist();
ContentFactory::make(['id' => 2, 'url' => '/index', 'site_id' => 1, 'parent_id' => 1, 'lft' => 2, 'rght' => 9, 'level' => 1, 'title' => 'トップページ'])->persist();
ContentFactory::make(['id' => 3, 'url' => '/service/', 'site_id' => 1, 'parent_id' => 1, 'lft' => 3, 'rght' => 8, 'level' => 1])->persist();
ContentFactory::make(['id' => 4, 'url' => '/service/service1', 'site_id' => 1, 'parent_id' => 3, 'lft' => 4, 'rght' => 7, 'level' => 2])->persist();
ContentFactory::make(['id' => 5, 'url' => '/service/service1/service2', 'site_id' => 1, 'parent_id' => 4, 'lft' => 5, 'rght' => 6, 'level' => 3])->persist();

ContentFactory::make(['id' => 6, 'url' => '/', 'site_id' => 2, 'lft' => 10, 'rght' => 13, 'site_root' => true])->persist();
ContentFactory::make(['id' => 7, 'url' => '/m/', 'site_id' => 2, 'lft' => 11, 'rght' => 12, 'parent_id' => 6, 'title' => 'トップページ'])->persist();

ContentFactory::make(['id' => 8, 'url' => '/', 'site_id' => 3, 'lft' => 14, 'rght' => 17, 'site_root' => true])->persist();
ContentFactory::make(['id' => 9, 'url' => '/s/', 'site_id' => 3, 'lft' => 15, 'rght' => 16, 'parent_id' => 8, 'title' => 'トップページ'])->persist();

$this->assertMatchesRegularExpression('/' . $expected . '/s', $this->BcBaser->getSitemap($siteId));
}

public static function getSitemapDataProvider()
{
return [
[0, '<li class="menu-content li-level-1">.*?<a href="\/">トップページ<\/a>.*?<\/li>'],
[1, '<a href="\/m\/">トップページ.*<\/li>.*<\/ul>'],
[2, '<a href="\/s\/">トップページ.*<\/li>.*<\/ul>']
[0, '<ul class="menu ul-level-1">.*<a href="\/index">トップページ<\/a>.*<ul class="menu ul-level-2">.*<ul class="menu ul-level-3">'],
[1, '<ul class="menu ul-level-1">.*<a href="\/index">トップページ<\/a>.*<ul class="menu ul-level-2">.*<ul class="menu ul-level-3">'],
[2, '<a href="\/m\/">トップページ.*<\/li>.*<\/ul>'],
[3, '<a href="\/s\/">トップページ.*<\/li>.*<\/ul>']
];
}

Expand Down Expand Up @@ -1775,8 +1801,11 @@ public function testGetGlobalMenu()
*/
public function testGoogleAnalytics()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->expectOutputRegex('/<script>.*gtag\(\'config\', \'hoge\'\)\;/s', $this->BcBaser->googleAnalytics());
SiteConfigFactory::make(['name' => 'google_analytics_id', 'value' => 'hoge'])->persist();
ob_start();
$this->BcBaser->googleAnalytics();
$result = ob_get_clean();
$this->assertStringContainsString('<script async src="https://www.googletagmanager.com/gtag/js?id=hoge"></script>', $result);
}

/**
Expand Down Expand Up @@ -1954,6 +1983,17 @@ public function testGetContentsUrl()
Configure::write('BcEnv.siteUrl', $siteUrl);
}

/**
* test updateInfo
*/
public function testUpdateInfo()
{
ob_start();
$this->BcBaser->updateInfo();
$result = ob_get_clean();
$this->assertStringContainsString('<div class="bc-update-info clearfix">', $result);
}

/**
* @return void
*/
Expand Down
1 change: 1 addition & 0 deletions plugins/bc-mail/src/Model/Table/MailMessagesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public function validationDefault(Validator $validator): Validator
* @param $mailContentId
* @checked
* @noTodo
* @unitTest
*/
public function setUseTable($mailContentId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,16 @@ public static function createTableNameDataProvider()
[false, 'mail_message_0'],
];
}

/**
* test setUseTable
*/
public function test_setUseTable()
{
$mailContentId = 1;
$this->MailMessage->setUseTable($mailContentId);

$actualTableName = $this->MailMessage->getTable();
$this->assertEquals('mail_message_1', $actualTableName);
}
}
31 changes: 26 additions & 5 deletions plugins/bc-mail/tests/TestCase/View/Helper/MailHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use BaserCore\TestSuite\BcTestCase;
use BcMail\Model\Entity\MailContent;
use BcMail\View\Helper\MailHelper;
use Cake\ORM\Entity;
use Cake\View\View;

/**
Expand Down Expand Up @@ -63,13 +64,33 @@ public function testGetDescription()

/**
* 説明文の存在確認
* @param $description
* @param $expected
* @dataProvider descriptionExistsProvider
*/
public function testDescriptionExists()
public function testDescriptionExists($description, $expected)
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->Mail->setMailContent(1);
$result = $this->Mail->descriptionExists();
$this->assertTrue($result, "メールの説明文が指定されていません。");
//setUp
$mailContent = new Entity([
'description' => $description
]);
$this->MailHelper->currentMailContent = $mailContent;

$result = $this->MailHelper->descriptionExists();

$this->assertEquals($expected, $result);
}

public static function descriptionExistsProvider()
{
return [
['This is a test description', true],
['', false],
[null, false],
['0', false],
[' ', true],
['<p>This is a <strong>HTML</strong> description</p>', true],
];
}

/**
Expand Down

0 comments on commit 5da4814

Please sign in to comment.