From cfe252edc3717b205b80ff8929e109be9341da2c Mon Sep 17 00:00:00 2001 From: thangnnmd <150879641+thangnnmd@users.noreply.github.com> Date: Tue, 23 Apr 2024 06:53:53 +0700 Subject: [PATCH 1/7] add unitTest_Admin_MailFieldsController_beforeAddEvent (#3358) Co-authored-by: thangnn --- .../Controller/Admin/MailFieldsControllerTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php index 3197c724b4..d50b1921aa 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php @@ -279,15 +279,12 @@ public function testAdmin_ajax_publish() */ public function testBeforeAddEvent() { - $this->markTestIncomplete('こちらのテストはまだ未確認です'); + $this->enableSecurityToken(); + $this->enableCsrfToken(); $MailMessagesService = $this->getService(MailMessagesServiceInterface::class); //テストデータベースを生成 $MailMessagesService->createTable(1); - $this->loadFixtureScenario(MailFieldsScenario::class); $this->loadFixtureScenario(MailContentsScenario::class); - - $this->enableSecurityToken(); - $this->enableCsrfToken(); //イベントをコル $this->entryEventToMock(self::EVENT_LAYER_CONTROLLER, 'BcMail.MailFields.beforeAdd', function (Event $event) { $data = $event->getData('data'); @@ -296,17 +293,20 @@ public function testBeforeAddEvent() }); //追加データを準備 $data = [ + 'mail_content_id' => 1, 'field_name' => 'name_add_1', 'type' => 'text', 'name' => '性', + 'source' => '資料請求|問い合わせ|その他' ]; //対象URLをコル $this->post('/baser/admin/bc-mail/mail_fields/add/1', $data); + //check response code + $this->assertResponseCode(302); //イベントに入るかどうか確認 $mailFields = $this->getTableLocator()->get('BcMail.MailFields'); $query = $mailFields->find()->where(['name' => 'beforeAdd']); $this->assertEquals(1, $query->count()); - //テストデータベースを削除 $MailMessagesService->dropTable(1); } From e16f4874d58b138e2d1c6912d03bce3fb6055329 Mon Sep 17 00:00:00 2001 From: thangnnmd <150879641+thangnnmd@users.noreply.github.com> Date: Tue, 23 Apr 2024 06:54:12 +0700 Subject: [PATCH 2/7] add Admin_MailFieldsController_afterAddEvent (#3359) Co-authored-by: thangnn --- .../Admin/MailFieldsControllerTest.php | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php index d50b1921aa..18321904ba 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php @@ -316,14 +316,6 @@ public function testBeforeAddEvent() */ public function testAfterAddEvent() { - $this->markTestIncomplete('こちらのテストはまだ未確認です'); - $MailMessagesService = $this->getService(MailMessagesServiceInterface::class); - //テストデータベースを生成 - $MailMessagesService->createTable(10); - - $this->enableSecurityToken(); - $this->enableCsrfToken(); - //イベントをコル $this->entryEventToMock(self::EVENT_LAYER_CONTROLLER, 'BcMail.MailFields.afterAdd', function (Event $event) { $data = $event->getData('data'); @@ -331,20 +323,32 @@ public function testAfterAddEvent() $data->name = 'afterAdd'; $contentLinks->save($data); }); - //Postデータを生成 + $MailMessagesService = $this->getService(MailMessagesServiceInterface::class); + $MailMessagesService->createTable(1); + + //テストデータベースを生成 + $this->loadFixtureScenario(MailContentsScenario::class); + $this->enableSecurityToken(); + $this->enableCsrfToken(); + + //正常系実行 $data = [ + 'mail_content_id' => 1, 'field_name' => 'name_add_1', 'type' => 'text', 'name' => '性', + 'source' => '資料請求|問い合わせ|その他' ]; - //対象URLをコル - $this->post('/baser/admin/bc-mail/mail_fields/add/10', $data); + $this->post('/baser/admin/bc-mail/mail_fields/add/1', $data); + $this->assertResponseCode(302); + //イベントに入るかどうか確認 $mailFields = $this->getTableLocator()->get('BcMail.MailFields'); $query = $mailFields->find()->where(['name' => 'afterAdd']); $this->assertEquals(1, $query->count()); + //テストデータベースを削除 - $MailMessagesService->dropTable(10); + $MailMessagesService->dropTable(1); } /** From 1b1b10a5743575a143e49c88d20de807c98ad5b7 Mon Sep 17 00:00:00 2001 From: thangnnmd <150879641+thangnnmd@users.noreply.github.com> Date: Tue, 23 Apr 2024 06:54:32 +0700 Subject: [PATCH 3/7] unitTest_Admin_MailFieldsController_afterEditEvent (#3361) Co-authored-by: thangnn --- .../Admin/MailFieldsControllerTest.php | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php index 18321904ba..e21ba4bbcc 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php @@ -379,15 +379,10 @@ public function testBeforeEditEvent() } /** - * Test beforeAddEvent + * Test afterAddEvent */ public function testAfterEditEvent() { - $this->markTestIncomplete('こちらのテストはまだ未確認です'); - $this->enableSecurityToken(); - $this->enableCsrfToken(); - //データを生成 - $this->loadFixtureScenario(MailFieldsScenario::class); //イベントをコル $this->entryEventToMock(self::EVENT_LAYER_CONTROLLER, 'BcMail.MailFields.afterEdit', function (Event $event) { $data = $event->getData('data'); @@ -395,11 +390,18 @@ public function testAfterEditEvent() $data->name = 'afterEdit'; $mailFields->save($data); }); - //メールのコンテンツサービスをコル - $mailFieldsService = $this->getService(MailFieldsAdminServiceInterface::class); - $data = $mailFieldsService->get(1); - //対象URLをコル - $this->post('/baser/admin/bc-mail/mail_fields/edit/1/1', $data->toArray()); + $this->enableSecurityToken(); + $this->enableCsrfToken(); + + //データを生成 + $this->loadFixtureScenario(MailContentsScenario::class); + $this->loadFixtureScenario(MailFieldsScenario::class); + + //正常系実行 + $data = ['name' => 'afterEdit', 'type' => 'text']; + $this->post('/baser/admin/bc-mail/mail_fields/edit/1/1', $data); + $this->assertResponseCode(302); + //イベントに入るかどうか確認 $mailFields = $this->getTableLocator()->get('BcMail.MailFields'); $query = $mailFields->find()->where(['name' => 'afterEdit']); From fd21aa1ba9cdb99c4e7ac4355471d39ad357b7d4 Mon Sep 17 00:00:00 2001 From: thangnnmd <150879641+thangnnmd@users.noreply.github.com> Date: Tue, 23 Apr 2024 06:54:51 +0700 Subject: [PATCH 4/7] add unitTest_Admin_MailFieldsController_beforeEditEvent (#3362) Co-authored-by: thangnn --- .../Admin/MailFieldsControllerTest.php | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php index e21ba4bbcc..da58ce3a3d 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php @@ -352,30 +352,35 @@ public function testAfterAddEvent() } /** - * Test beforeAddEvent + * Test beforeEditEvent */ public function testBeforeEditEvent() { - $this->markTestIncomplete('こちらのテストはまだ未確認です'); - $this->enableSecurityToken(); - $this->enableCsrfToken(); - //データを生成 - $this->loadFixtureScenario(MailFieldsScenario::class); //イベントをコル $this->entryEventToMock(self::EVENT_LAYER_CONTROLLER, 'BcMail.MailFields.beforeEdit', function (Event $event) { $data = $event->getData('data'); $data['name'] = 'beforeEdit'; $event->setData('data', $data); }); - //メールのコンテンツサービスをコル - $mailFieldsService = $this->getService(MailFieldsAdminServiceInterface::class); - $data = $mailFieldsService->get(1); - //対象URLをコル - $this->post('/baser/admin/bc-mail/mail_fields/edit/1/1', $data->toArray()); + $this->enableSecurityToken(); + $this->enableCsrfToken(); + $MailMessagesService = $this->getService(MailMessagesServiceInterface::class); + //テストデータベースを生成 + $MailMessagesService->createTable(1); + //データを生成 + $this->loadFixtureScenario(MailContentsScenario::class); + $this->loadFixtureScenario(MailFieldsScenario::class); + $data = ['name' => 'editedName', 'type' => 'text']; + //対象URLをコル + $this->post('/baser/admin/bc-mail/mail_fields/edit/1/1', $data); + //check response code + $this->assertResponseCode(302); //イベントに入るかどうか確認 $mailFields = $this->getTableLocator()->get('BcMail.MailFields'); $query = $mailFields->find()->where(['name' => 'beforeEdit']); $this->assertEquals(1, $query->count()); + //テストデータベースを削除 + $MailMessagesService->dropTable(1); } /** From d7fc85c42bbc2932b3fe8fe8a1cd1b627b05883e Mon Sep 17 00:00:00 2001 From: thangnnmd <150879641+thangnnmd@users.noreply.github.com> Date: Tue, 23 Apr 2024 07:05:16 +0700 Subject: [PATCH 5/7] add unitTest_WidgetAreasController_add (#3367) Co-authored-by: thangnn --- .../Admin/WidgetAreasController.php | 1 + .../Admin/WidgetAreasControllerTest.php | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/plugins/bc-widget-area/src/Controller/Admin/WidgetAreasController.php b/plugins/bc-widget-area/src/Controller/Admin/WidgetAreasController.php index 7ed4e1ac03..3a2c499d67 100644 --- a/plugins/bc-widget-area/src/Controller/Admin/WidgetAreasController.php +++ b/plugins/bc-widget-area/src/Controller/Admin/WidgetAreasController.php @@ -55,6 +55,7 @@ public function index(WidgetAreasServiceInterface $service) * @return void|ResponseInterface * @checked * @noTodo + * @unitTest */ public function add(WidgetAreasServiceInterface $service) { diff --git a/plugins/bc-widget-area/tests/TestCase/Controller/Admin/WidgetAreasControllerTest.php b/plugins/bc-widget-area/tests/TestCase/Controller/Admin/WidgetAreasControllerTest.php index fc238ecd38..f840c441bd 100644 --- a/plugins/bc-widget-area/tests/TestCase/Controller/Admin/WidgetAreasControllerTest.php +++ b/plugins/bc-widget-area/tests/TestCase/Controller/Admin/WidgetAreasControllerTest.php @@ -75,7 +75,36 @@ public function testAdmin_index() */ public function testAdmin_add() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $this->loginAdmin($this->getRequest('/')); + $this->enableSecurityToken(); + $this->enableCsrfToken(); + + // データ生成 + $data = [ + 'name' => 'test', + 'widgets' => serialize([ + [ + 1 => 'test 1', + 2 => 'test 2' + ] + ]) + ]; + + //正常系実行 + $this->post('/baser/admin/bc-widget-area/widget_areas/add', $data); + $this->assertResponseCode(302); + $this->assertFlashMessage('新しいウィジェットエリアを保存しました。'); + $this->assertRedirect('/baser/admin/bc-widget-area/widget_areas/edit/1'); + + //データが空の場合、 + $data = [ + 'name' => '', + 'widgets' => '' + ]; + $this->post('/baser/admin/bc-widget-area/widget_areas/add', $data); + $vars = $this->_controller->viewBuilder()->getVars(); + $this->assertEquals(['name' => ['_empty' => "ウィジェットエリア名を入力してください。"]], $vars['widgetArea']->getErrors()); + $this->assertResponseCode(200); } /** From 542003643c8021b5b2cfe26e59327e456346fcb0 Mon Sep 17 00:00:00 2001 From: thangnnmd <150879641+thangnnmd@users.noreply.github.com> Date: Tue, 23 Apr 2024 07:06:55 +0700 Subject: [PATCH 6/7] add unitTest_Table_MailFields_halfTextMailField (#3368) Co-authored-by: thangnn --- plugins/bc-mail/src/Model/Table/MailFieldsTable.php | 1 + .../tests/TestCase/Model/Table/MailFieldsTableTest.php | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/bc-mail/src/Model/Table/MailFieldsTable.php b/plugins/bc-mail/src/Model/Table/MailFieldsTable.php index c729b8ff4b..99cc9790f5 100755 --- a/plugins/bc-mail/src/Model/Table/MailFieldsTable.php +++ b/plugins/bc-mail/src/Model/Table/MailFieldsTable.php @@ -233,6 +233,7 @@ public function duplicateMailField(string $value, array $context) * @return boolean * @checked * @noTodo + * @unitTest */ public function halfTextMailField(string $value) { diff --git a/plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php b/plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php index e349283fc3..7378f342d5 100755 --- a/plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php +++ b/plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php @@ -176,7 +176,15 @@ public function testDuplicateMailField() */ public function testHalfTextMailField() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + //case true + $string = 'abc123_'; + $result = $this->MailFieldsTable->halfTextMailField($string); + $this->assertTrue($result); + + //case false + $string = 'abcABC123_'; + $result = $this->MailFieldsTable->halfTextMailField($string); + $this->assertFalse($result); } /** From 73395b3a9f49c1f4eade61734988c64f5c28cac5 Mon Sep 17 00:00:00 2001 From: thangnnmd <150879641+thangnnmd@users.noreply.github.com> Date: Tue, 23 Apr 2024 07:09:03 +0700 Subject: [PATCH 7/7] unitTest_MailFieldsTable_formatSource (#3370) Co-authored-by: thangnn --- plugins/bc-mail/src/Model/Table/MailFieldsTable.php | 1 + .../bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/bc-mail/src/Model/Table/MailFieldsTable.php b/plugins/bc-mail/src/Model/Table/MailFieldsTable.php index 99cc9790f5..23c70eae4e 100755 --- a/plugins/bc-mail/src/Model/Table/MailFieldsTable.php +++ b/plugins/bc-mail/src/Model/Table/MailFieldsTable.php @@ -331,6 +331,7 @@ public function copy(?int $id, MailField $data = null, array $options = []) * @return string 整形後選択リストソース * @checked * @noTodo + * @unitTest */ public function formatSource($source) { diff --git a/plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php b/plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php index 7378f342d5..b2c754f59d 100755 --- a/plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php +++ b/plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php @@ -269,8 +269,7 @@ public function testAfterSave() */ public function testFormatSource($source, $expected) { - $this->markTestIncomplete('こちらのテストはまだ未確認です'); - $result = $this->MailField->formatSource($source); + $result = $this->MailFieldsTable->formatSource($source); $this->assertEquals($expected, $result); }