diff --git a/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php b/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php index 0adbcfa531..69481fb779 100644 --- a/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php +++ b/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php @@ -128,6 +128,7 @@ public function index(MailFieldsAdminServiceInterface $service, int $mailContent * @return void * @checked * @noTodo + * @unitTest */ public function add(MailFieldsAdminServiceInterface $service, int $mailContentId) { diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php index ab672cd9ec..2c4c4aa0c7 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php @@ -18,6 +18,7 @@ use BcMail\Controller\Admin\MailFieldsController; use BcMail\Service\Admin\MailFieldsAdminServiceInterface; use BcMail\Service\MailMessagesServiceInterface; +use BcMail\Test\Factory\MailFieldsFactory; use BcMail\Test\Scenario\MailContentsScenario; use BcMail\Test\Scenario\MailFieldsScenario; use Cake\Event\Event; @@ -86,7 +87,41 @@ public function testAdmin_index() */ public function testAdmin_add() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $this->enableSecurityToken(); + $this->enableCsrfToken(); + $MailMessagesService = $this->getService(MailMessagesServiceInterface::class); + //テストデータベースを生成 + $MailMessagesService->createTable(1); + //テストデータベースを生成 + $this->loadFixtureScenario(MailContentsScenario::class); + $data = [ + 'id' => 1, + 'mail_content_id' => 1, + 'name' => 'test', + 'field_name' => 'name_1', + 'type' => 'text', + 'source' => '資料請求|問い合わせ|その他' + ]; + $this->post('/baser/admin/bc-mail/mail_fields/add/1', $data); + //check response code + $this->assertResponseCode(302); + //check redirect + $this->assertRedirect('/baser/admin/bc-mail/mail_fields/index/1'); + //異常系のテスト + $data = [ + 'id' => 1, + 'mail_content_id' => 1, + 'name' => null, + 'field_name' => 'name_1', + 'type' => 'text', + 'source' => '資料請求|問い合わせ|その他' + ]; + $this->post('/baser/admin/bc-mail/mail_fields/add/1', $data); + //check response code + $this->assertResponseCode(200); + $this->assertResponseContains('入力エラーです。内容を修正してください。'); + //テストデータベースを削除 + $MailMessagesService->dropTable(1); } /**