From 9538ef92ef1465de2daf93b5433d2c63444ddc4d Mon Sep 17 00:00:00 2001 From: thangnnmd <150879641+thangnnmd@users.noreply.github.com> Date: Sat, 20 Apr 2024 17:21:43 +0700 Subject: [PATCH] add Admin_MailFieldsController_delete (#3352) Co-authored-by: thangnn --- .../Controller/Admin/MailFieldsController.php | 3 ++- .../Admin/MailFieldsControllerTest.php | 27 ++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php b/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php index 2a5d5f1f3d..74d96d7288 100644 --- a/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php +++ b/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php @@ -224,12 +224,13 @@ public function edit(MailFieldsAdminServiceInterface $service, int $mailContentI * @throws \Throwable * @checked * @noTodo + * @unitTest */ public function delete(MailFieldsServiceInterface $service, int $mailContentId, int $id) { $this->request->allowMethod(['post', 'delete']); - $entity = $service->get($id); try { + $entity = $service->get($id); if($service->delete($id)) { $this->BcMessage->setSuccess(__d('baser_core', 'メールフィールド「{0}」を削除しました。', $entity->name)); } else { diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php index cef9d1b008..c5d7e6e0c0 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php @@ -180,7 +180,32 @@ public function testAdmin_ajax_delete() */ public function testAdmin_delete() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $this->enableSecurityToken(); + $this->enableCsrfToken(); + + //メールメッセージサービスをコル + $MailMessagesService = $this->getService(MailMessagesServiceInterface::class); + $MailMessagesService->createTable(1); + $MailMessagesService->addMessageField(1, 'name_1'); + + //データを生成 + $this->loadFixtureScenario(MailContentsScenario::class); + $this->loadFixtureScenario(MailFieldsScenario::class); + + //対象URLをコル + $this->post('/baser/admin/bc-mail/mail_fields/delete/1/1'); + $this->assertResponseCode(302); + $this->assertFlashMessage('メールフィールド「性」を削除しました。'); + $this->assertRedirect('/baser/admin/bc-mail/mail_fields/index/1'); + + //check case error + $this->post('/baser/admin/bc-mail/mail_fields/delete/1/999'); + $this->assertResponseCode(302); + $this->assertFlashMessage('データベース処理中にエラーが発生しました。Record not found in table `mail_fields`.'); + $this->assertRedirect('/baser/admin/bc-mail/mail_fields/index/1'); + + //テストデータベースを削除 + $MailMessagesService->dropTable(1); } /**