From 37b113e2d7d198a00ba1ad7acb8042c42103d2ff Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Tue, 10 Dec 2024 11:39:35 +0900 Subject: [PATCH] =?UTF-8?q?MailMessagesController::delete()=20=E3=83=A6?= =?UTF-8?q?=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/MailMessagesController.php | 1 + .../Admin/MailMessagesControllerTest.php | 35 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php b/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php index 2d2129bdec..c2d2ed2254 100644 --- a/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php +++ b/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php @@ -130,6 +130,7 @@ public function view( * @return void|Response * @checked * @noTodo + * @unitTest */ public function delete( MailMessagesServiceInterface $service, diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php index 002460464c..ab8add2ebc 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php @@ -18,6 +18,8 @@ use BcMail\Service\MailMessagesServiceInterface; use BcMail\Test\Factory\MailContentFactory; use Cake\Event\Event; +use Cake\ORM\Entity; +use Cake\ORM\TableRegistry; use Cake\TestSuite\IntegrationTestTrait; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; @@ -140,7 +142,38 @@ public function testView() */ public function testDelete() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $this->enableSecurityToken(); + $this->enableCsrfToken(); + // メールメッセージのデータを作成する + ContentFactory::make([ + 'plugin' => 'BcMail', + 'type' => 'MailContent', + 'url' => '/contact/', + 'site_id' => 1, + 'title' => 'お問い合わせ', + 'entity_id' => 1, + ])->persist(); + MailContentFactory::make(['id' => 1])->persist(); + $MailMessagesService = $this->getService(MailMessagesServiceInterface::class); + //テストデータベースを生成 + $MailMessagesService->createTable(1); + $mailMessageTable = TableRegistry::getTableLocator()->get('BcMail.MailMessages'); + $mailContentId = 1; + $mailMessageTable->setup($mailContentId); + $mailMessageTable->setup($mailContentId); + $mailMessageTable->save(new Entity(['id' => 1])); + + //正常テスト + $this->post('/baser/admin/bc-mail/mail_messages/delete/1/1'); + $this->assertResponseCode(302); + $this->assertRedirect(['action' => 'index', 1]); + $this->assertFlashMessage('お問い合わせ への受信データ NO「1」 を削除しました。'); + + //異常テスト + $this->get('/baser/admin/bc-mail/mail_messages/delete/1/1'); + $this->assertResponseCode(405); + + $MailMessagesService->dropTable(1); } /**