Skip to content

Commit

Permalink
Merge branch '5.1.x' into unitTest_MailHelper_link
Browse files Browse the repository at this point in the history
  • Loading branch information
thangnn committed Dec 5, 2024
2 parents 322d3a6 + 60acdbb commit c386503
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
if (empty($link['class'])) {
$link['class'] = 'bca-btn';
}
if (empty($link['data-bca-btn-type'])) {
if (empty($link['data-bca-btn-type']) && !empty($url['action'])) {
$link['data-bca-btn-type'] = $url['action'];
}
if (empty($link['data-bca-btn-size'])) {
Expand Down
17 changes: 17 additions & 0 deletions plugins/bc-mail/src/Model/Table/MailContentsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ public function validationDefault(Validator $validator): Validator
]
]);

// publish_end
$validator
->add('publish_end', [
'dateTime' => [
'rule' => ['dateTime'],
'message' => __d('baser_core', '公開終了日に不正な文字列が入っています。')
]
])
->allowEmptyDateTime('publish_end')
->add('publish_end', [
'checkDateAfterThan' => [
'rule' => ['checkDateAfterThan', 'publish_begin'],
'provider' => 'bc',
'message' => __d('baser_core', '公開終了日は、公開開始日より新しい日付で入力してください。')
]
]);

// sender_1
$validator
->scalar('sender_1')
Expand Down
4 changes: 4 additions & 0 deletions plugins/bc-mail/src/View/Helper/MailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public function getFormTemplates($siteId = 1)
* @todo 他のヘルパに移動する
* @checked
* @noTodo
* @unitTest
*/
public function getMailTemplates($siteId = 1)
{
Expand Down Expand Up @@ -244,6 +245,7 @@ public function link($title, $contentsName, $datas = [], $options = [])
* @return string
* @checked
* @noTodo
* @unitTest
*/
public function getToken()
{
Expand All @@ -256,6 +258,7 @@ public function getToken()
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function token()
{
Expand Down Expand Up @@ -338,6 +341,7 @@ public function isMail(): bool
* @return mixed
* @checked
* @noTodo
* @unitTest
*/
public function getPublishedMailContents(int $siteId)
{
Expand Down
3 changes: 2 additions & 1 deletion plugins/bc-mail/src/View/Helper/MaildataHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function control($type, $value, $escape = true)
* @return string メール用データ
* @checked
* @noTodo
* @unitTest
*/
public function toDisplayString(string $type, $value, bool $prefixSpace = true)
{
Expand All @@ -77,7 +78,7 @@ public function toDisplayString(string $type, $value, bool $prefixSpace = true)
case 'number':
case 'password':
$result = $value;

break;
case 'pref':
$prefs = $this->prefList();
$options = [];
Expand Down
49 changes: 26 additions & 23 deletions plugins/bc-mail/tests/TestCase/View/Helper/MailHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,40 @@
use BaserCore\TestSuite\BcTestCase;
use BaserCore\View\BcFrontAppView;
use BcMail\Model\Entity\MailContent;
use BcMail\Test\Scenario\MailContentsScenario;
use BcMail\View\Helper\MailHelper;
use Cake\ORM\Entity;
use Cake\View\View;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
* Class MailHelperTest
*
* @property MailHelper $Mail
* @property MailHelper $MailHelper
*/
class MailHelperTest extends BcTestCase
{
/**
* ScenarioAwareTrait
*/
use ScenarioAwareTrait;

/**
* set up
*/
public function setUp(): void
{
parent::setUp();
$this->MailHelper = new MailHelper(new View());
SiteFactory::make(['id' => '1'])->persist();
$view = new BcFrontAppView($this->getRequest('/'));
$this->MailHelper = new MailHelper($view);
}

/**
* tear down
*/
public function tearDown(): void
{
// unset($this->Mail);
unset($this->MailHelper);
parent::tearDown();
}

Expand Down Expand Up @@ -114,9 +122,6 @@ public function testGetForm()
*/
public function testGetFormTemplates()
{
SiteFactory::make(['id' => '1'])->persist();
$view = new BcFrontAppView($this->getRequest('/'));
$this->MailHelper = new MailHelper($view);
$result = $this->MailHelper->getFormTemplates(1);
$this->assertEquals(['default' => 'default'], $result);
}
Expand All @@ -126,30 +131,18 @@ public function testGetFormTemplates()
*/
public function testGetMailTemplates()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$View = new View(null);
$View->set('siteConfig', Configure::read('BcSite'));
$this->Mail->BcBaser = new BcBaserHelper($View);
$result = $this->Mail->getMailTemplates();
$expected = [
'mail_default' => 'mail_default',
'default' => 'default',
'reset_password' => 'reset_password',
'send_activate_url' => 'send_activate_url',
'send_activate_urls' => 'send_activate_urls',
];
$this->assertEquals($result, $expected, 'メールテンプレートの取得結果が違います。');
$result = $this->MailHelper->getMailTemplates(1);
$this->assertEquals(['mail_default' => 'mail_default'], $result);
}

/**
* ブラウザの戻るボタンを取得
*/
public function testGetToken()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$result = $this->Mail->getToken();
$result = $this->MailHelper->getToken();
$expected = '/<script.*<\/script>.*/s';
$this->assertMatchesRegularExpression($expected, $result, 'スクリプトが取得できません。');
$this->assertMatchesRegularExpression($expected, $result);
}

/**
Expand Down Expand Up @@ -263,4 +256,14 @@ public function test_isMail()
$result = $this->MailHelper->isMail();
$this->assertTrue($result);
}

/**
* test getPublishedMailContents
*/
public function testGetPublishedMailContents()
{
$this->loadFixtureScenario(MailContentsScenario::class);
$rs = $this->MailHelper->getPublishedMailContents(1);
$this->assertEquals(1, $rs->count());
}
}
88 changes: 56 additions & 32 deletions plugins/bc-mail/tests/TestCase/View/Helper/MaildataHelperTest.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
<?php
namespace BcMail\Test\TestCase\View\Helper;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\View\BcFrontAppView;
use BcMail\View\Helper\MaildataHelper;
use Cake\View\View;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

class MaildataHelperTest extends BcTestCase
{

use ScenarioAwareTrait;

/**
* set up
*/
public function setUp():void
public function setUp(): void
{
parent::setUp();
$this->MaildataHelper = new MaildataHelper(new View());
$view = new BcFrontAppView($this->getRequest('/'));
$this->MaildataHelper = new MaildataHelper($view);
}

/**
* tear down
*/
public function tearDown():void
public function tearDown(): void
{
unset($this->MaildataHelper);
parent::tearDown();
}

/**
* メール表示用のデータを出力する
* @dataProvider controlDataProvider
Expand All @@ -37,8 +42,8 @@ public function testControl($type, $value, $escape, $expected)
public static function controlDataProvider()
{
return [
['text' , '<b>bold</b>', true, ' &lt;b&gt;bold&lt;/b&gt;'],
['text' , '<b>bold</b>', false, ' <b>bold</b>'],
['text', '<b>bold</b>', true, ' &lt;b&gt;bold&lt;/b&gt;'],
['text', '<b>bold</b>', false, ' <b>bold</b>'],
];
}

Expand All @@ -48,12 +53,7 @@ public static function controlDataProvider()
*/
public function testToDisplayString($type, $value, $options, $expected)
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
if ($type == 'file') {
$this->View->set('mailContent', ['MailContent' => ['id' => 1]]);
}

$result = $this->Maildata->toDisplayString($type, $value, $options);
$result = $this->MaildataHelper->toDisplayString($type, $value, $options);
$this->assertEquals($result, $expected);
}

Expand All @@ -75,33 +75,57 @@ public static function toDisplayStringProvider()
['email', 'hoge', '', 'hoge'],
['hidden', 'hoge', '', 'hoge'],
['radio', '', '', ''],
['radio', '', $options, ''],
['radio', 'hoge', $options, 'hoge'],
['radio', 'h', $options, 'h'],
['radio', $options, '', '・資料請求
・お問い合わせ
・その他
'],
['radio', $options, true, ' ・資料請求
・お問い合わせ
・その他
'],
['radio', $options, false, '・資料請求
・お問い合わせ
・その他
'],
['select', '', '', ''],
['select', '', $options, ''],
['select', 'hoge', $options, 'hoge'],
['select', 'h', $options, 'h'],
['select', $options, '', '・資料請求
・お問い合わせ
・その他
'],
['select', $options, '', '・資料請求
・お問い合わせ
・その他
'],
['pref', '', '', ''],
['pref', '東京都', '', '東京都'],
['pref', '福岡県', '', '福岡県'],
['check', '', '', ''],
['check', '', $options, ''],
['check', $options, '', '・資料請求
・お問い合わせ
・その他
'],
['check', 'hoge', '', 'hoge'],
['check', 'hoge', $options, 'hoge'],
['check', $options, '', '・資料請求
・お問い合わせ
・その他
'],
['multi_check', '', '', ''],
['multi_check', '', $options, ''],
['multi_check', $get, $options, "・hoge\n ・hello\n ・world\n"],
['file', 'hoge', $options, '<a href="/admin/mail_messages/attachment/1/hoge">hoge</a>'],
['file', 'test/hoge.jpg', $options, '<a href="/admin/mail_messages/attachment/1/test/hoge.jpg" target="_blank"><img src="/admin/mail_messages/attachment/1/test/hoge.jpg" width="400" alt=""/></a>'],
//TODO 西暦のオーバーフロー処理ができてない
['date_time_calender', 'hoge', $options, '1970年 01月 01日'],
['date_time_calender', '21000828', $options, '2100年 08月 28日'],
['date_time_calender', '2100/08/32', $options, '1970年 01月 01日'],
['date_time_calender', '', $options, ''],
['autozip', '888-0000', $options, '888-0000'],
['autozip', '8880000', $options, '888-0000'],
['', 'hoge', $options, 'hoge']
['multi_check', $options, '', '・資料請求
・お問い合わせ
・その他
'],
['multi_check', $get, '', "・hoge
・hello
・world
"],
// ['file', 'hoge', '', '<a href="/admin/mail_messages/attachment/1/hoge">hoge</a>'],
['date_time_calender', 'hoge', '', '1970年 01月 01日'],
['date_time_calender', '21000828', '', '2100年 08月 28日'],
['date_time_calender', '2100/08/32', '', '1970年 01月 01日'],
['date_time_calender', '', '', ''],
['autozip', '888-0000', '', '888-0000'],
['autozip', '8880000', '', '888-0000'],
['', 'hoge', '', 'hoge']
];
}
}

0 comments on commit c386503

Please sign in to comment.