Skip to content

Commit

Permalink
Merge branch '5.1.x' into unitTest_MailFieldsTable_copy
Browse files Browse the repository at this point in the history
  • Loading branch information
thangnn committed Nov 29, 2024
2 parents 0e908e8 + d92b0b1 commit 5c3d710
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testExecute()

// composer実行(composer.json を配布用にセットアップ)
BcComposer::setup('', ROOT . DS);
$this->exec('composer 5.1.3.0');
$this->exec('composer 5.1.4.0');
$this->assertExitCode(Command::CODE_SUCCESS);
$this->assertOutputContains('Composer によるアップデートが完了しました。');

Expand Down
1 change: 1 addition & 0 deletions plugins/bc-mail/src/Model/Table/MailContentsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function initialize(array $config): void
* @return Validator
* @checked
* @noTodo
* @unitTest
*/
public function validationDefault(Validator $validator): Validator
{
Expand Down
1 change: 1 addition & 0 deletions plugins/bc-mail/src/Model/Table/MailFieldsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public function validationDefault(Validator $validator): Validator
* @return array source
* @checked
* @noTodo
* @unitTest
*/
public function getControlSource($field = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,51 @@ public function testFindAccepting()
$this->markTestIncomplete('このテストは、まだ実装されていません。');
}

/**
* test validationDefault
*/
public function testValidationDefault()
{
$validator = $this->MailContent->getValidator('default');

//notEmptyString
$errors = $validator->validate(['subject_user' => '', 'subject_admin' => '']);
$this->assertEquals('自動返信メール件名[ユーザー宛]を入力してください。', current($errors['subject_user']));
$this->assertEquals('自動返信メール件名[管理者宛]を入力してください。', current($errors['subject_admin']));

//maxLength
$errors = $validator->validate([
'subject_user' => str_repeat('a', 256),
'subject_admin' => str_repeat('a', 256),
'form_template' => str_repeat('a', 21),
'mail_template' => str_repeat('a', 21),
'redirect_url' => 'https://github.com/' . str_repeat('a', 256),
]);
$this->assertEquals('自動返信メール件名[ユーザー宛]は255文字以内で入力してください。', current($errors['subject_user']));
$this->assertEquals('自動返信メール件名[管理者宛]は255文字以内で入力してください。', current($errors['subject_admin']));
$this->assertEquals('フォームテンプレート名は20文字以内で入力してください。', current($errors['form_template']));
$this->assertEquals('送信メールテンプレート名は20文字以内で入力してください。', current($errors['mail_template']));
$this->assertEquals('リダイレクトURLは255文字以内で入力してください。', current($errors['redirect_url']));

//halfText
$errors = $validator->validate(['form_template' => 'カタカナ', 'mail_template' => 'カタカナ']);
$this->assertEquals('メールフォームテンプレート名は半角のみで入力してください。', current($errors['form_template']));
$this->assertEquals('送信メールテンプレートは半角のみで入力してください。', current($errors['mail_template']));

//redirect_urlのURL形式ではない
$errors = $validator->validate(['redirect_url' => 'abc']);
$this->assertEquals('リダイレクトURLはURLの形式を入力してください。', current($errors['redirect_url']));

//containsScript
$errors = $validator->validate(['description' => '<script></script>']);
$this->assertEquals('説明文でスクリプトの入力は許可されていません。', current($errors['description']));

//emails
$errors = $validator->validate(['sender_1' => 'カタカナ', 'sender_2' => 'カタカナ']);
$this->assertEquals('送信先メールアドレスのEメールの形式が不正です。', current($errors['sender_1']));
$this->assertEquals('BCC用送信先メールアドレスのEメールの形式が不正です。', current($errors['sender_2']));
}

/**
* test createSearchIndex
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,16 @@ public function test_validationDefaultDuplicate()
*/
public function testGetControlSource()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
//$field = null
$rs = $this->MailFieldsTable->getControlSource();
$this->assertEquals('テキスト', $rs['type']['text']);
$this->assertEquals('Eメール形式チェック', $rs['valid_ex']['VALID_EMAIL']);
$this->assertEquals('半角変換', $rs['auto_convert']['CONVERT_HANKAKU']);

//$field != null
$rs = $this->MailFieldsTable->getControlSource('type');
$this->assertEquals('テキストエリア', $rs['textarea']);
$this->assertEquals('隠しフィールド', $rs['hidden']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class BcThemeConfigHelper extends Helper
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function mainImage($options = [])
{
Expand Down Expand Up @@ -94,6 +95,7 @@ public function mainImage($options = [])
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function logo($options = [])
{
Expand All @@ -120,6 +122,7 @@ public function logo($options = [])
* @return string $tag テーマ画像のHTMLタグ
* @checked
* @noTodo
* @unitTest
*/
public function getThemeImage($name, $options = [])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,33 @@

namespace BcThemeConfig\Test\TestCase\View\Helper;

use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\View\BcAdminAppView;
use BcThemeConfig\View\Helper\BcThemeConfigHelper;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
* BcThemeConfigHelperTest
*/
class BcThemeConfigHelperTest extends BcTestCase
{
use ScenarioAwareTrait;

/**
* @var $BcThemeConfigHelper
*/
private $BcThemeConfigHelper;

/**
* set up
*/
public function setUp(): void
{
parent::setUp();
$this->loadFixtureScenario(InitAppScenario::class);
$BcAdminAppView = new BcAdminAppView($this->getRequest('/'));
$this->BcThemeConfigHelper = new BcThemeConfigHelper($BcAdminAppView);
}

/**
Expand All @@ -41,9 +54,10 @@ public function tearDown(): void
*/
public function testLogo()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->expectOutputRegex('/<img src="\/theme\/nada-icons\/img\/logo.png" alt="baserCMS"\/>/');
$this->BcBaser->logo();
ob_start();
$this->BcThemeConfigHelper->logo();
$result = ob_get_clean();
$this->assertEquals('<img src="/bc_front/img/logo.png" alt="">', $result);
}

/**
Expand All @@ -54,9 +68,10 @@ public function testLogo()
*/
public function testMainImage($options, $expect)
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->expectOutputRegex('/' . $expect . '/s');
$this->BcBaser->mainImage($options);
ob_start();
$this->BcThemeConfigHelper->mainImage($options);
$result = ob_get_clean();
$this->assertEquals($expect, $result);
}

/**
Expand All @@ -78,16 +93,23 @@ public function testMainImage($options, $expect)
public static function mainImageDataProvider()
{
return [
[[], '<img src="\/theme\/nada-icons\/img\/main_image_1.jpg" alt="コーポレートサイトにちょうどいい国産CMS"\/>'],
[['num' => 2], 'main_image_2'],
[['all' => true, 'num' => 2], '^(.*main_image_1.*main_image_2)'],
[['all' => true, 'class' => 'test-class', 'id' => 'test-id'], '^(.*id="test-id".*class="test-class")'],
[['popup' => true], 'href="\/theme\/nada-icons\/img\/main_image_1.jpg"'],
[['alt' => 'テスト'], 'alt="テスト"'],
[['link' => '/test'], 'href="\/test"'],
[['maxWidth' => '200', 'maxHeight' => '200'], 'width="200"'],
[['width' => '200', 'height' => '200'], '^(.*width="200".*height="200")'],
[['hoge' => 'hoge'], 'main_image_1'],
[[], '<img src="/bc_front/img/main_image_1.jpg" alt="">'],
[['num' => 2], '<img src="/bc_front/img/main_image_2.jpg" alt="">'],
[['all' => true, 'num' => 2], '<ul id="MainImage">
<li><img src="/bc_front/img/main_image_1.jpg" alt=""></li>
<li><img src="/bc_front/img/main_image_2.jpg" alt=""></li>
</ul>'],
[['all' => true, 'class' => 'test-class', 'id' => 'test-id'], '<ul id="test-id" class="test-class">
<li><img src="/bc_front/img/main_image_1.jpg" alt=""></li>
</ul>'],
[['popup' => true], '<a href="/bc_front/img/main_image_1.jpg" rel="colorbox"><img src="/bc_front/img/main_image_1.jpg" alt=""></a>'],
[['alt' => 'テスト'], '<img src="/bc_front/img/main_image_1.jpg" alt="テスト">'],
[['link' => '/test'], '<a href="/test"><img src="/bc_front/img/main_image_1.jpg" alt=""></a>'],
[['maxWidth' => '200', 'maxHeight' => '200'], '<img src="/bc_front/img/main_image_1.jpg" width="200" alt="">'],
[['width' => '200', 'height' => '200'], '<img src="/bc_front/img/main_image_1.jpg" width="200" height="200" alt="">'],
[['hoge' => 'hoge'], '<img src="/bc_front/img/main_image_1.jpg" alt="">'],
];
}

Expand Down

0 comments on commit 5c3d710

Please sign in to comment.