From 0d71ec098e2b05444f44fef0f12f582fd0b2b53e Mon Sep 17 00:00:00 2001 From: thangnn Date: Wed, 4 Dec 2024 14:19:47 +0700 Subject: [PATCH] Add unitTest_MaildataHelper_toDisplayString --- .../src/View/Helper/MaildataHelper.php | 3 +- .../View/Helper/MaildataHelperTest.php | 88 ++++++++++++------- 2 files changed, 58 insertions(+), 33 deletions(-) diff --git a/plugins/bc-mail/src/View/Helper/MaildataHelper.php b/plugins/bc-mail/src/View/Helper/MaildataHelper.php index 455f511abb..26ca8a1a2c 100755 --- a/plugins/bc-mail/src/View/Helper/MaildataHelper.php +++ b/plugins/bc-mail/src/View/Helper/MaildataHelper.php @@ -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) { @@ -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 = []; diff --git a/plugins/bc-mail/tests/TestCase/View/Helper/MaildataHelperTest.php b/plugins/bc-mail/tests/TestCase/View/Helper/MaildataHelperTest.php index 61c430213a..48e1cafb32 100644 --- a/plugins/bc-mail/tests/TestCase/View/Helper/MaildataHelperTest.php +++ b/plugins/bc-mail/tests/TestCase/View/Helper/MaildataHelperTest.php @@ -1,29 +1,34 @@ 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 @@ -37,8 +42,8 @@ public function testControl($type, $value, $escape, $expected) public static function controlDataProvider() { return [ - ['text' , 'bold', true, ' <b>bold</b>'], - ['text' , 'bold', false, ' bold'], + ['text', 'bold', true, ' <b>bold</b>'], + ['text', 'bold', false, ' bold'], ]; } @@ -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); } @@ -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, 'hoge'], - ['file', 'test/hoge.jpg', $options, ''], - //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', '', 'hoge'], + ['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'] ]; } }