From 32f61195e67cafe85d310dcecea61830da9d25d9 Mon Sep 17 00:00:00 2001 From: thangnn Date: Fri, 12 Apr 2024 13:21:42 +0700 Subject: [PATCH 1/2] unitTest_Admin_MailFieldsController_edit --- .../Controller/Admin/MailFieldsController.php | 1 + .../Admin/MailFieldsControllerTest.php | 37 ++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php b/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php index 0adbcfa531..c434b0f9e0 100644 --- a/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php +++ b/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php @@ -174,6 +174,7 @@ public function add(MailFieldsAdminServiceInterface $service, int $mailContentId * @return void * @checked * @noTodo + * @unitTest */ public function edit(MailFieldsAdminServiceInterface $service, int $mailContentId, int $id) { diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php index ab672cd9ec..8961999a31 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; @@ -94,7 +95,41 @@ public function testAdmin_add() */ public function testAdmin_edit() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $this->enableSecurityToken(); + $this->enableCsrfToken(); + $MailMessagesService = $this->getService(MailMessagesServiceInterface::class); + //テストデータベースを生成 + $MailMessagesService->createTable(1); + //テストデータベースを生成 + $this->loadFixtureScenario(MailContentsScenario::class); + $this->loadFixtureScenario(MailFieldsScenario::class); + //data edit + $data = [ + 'name' => 'edit', + 'type' => 'text' + ]; + //対象URLをコル + $this->post('/baser/admin/bc-mail/mail_fields/edit/1/1', $data); + //check response code + $this->assertResponseCode(302); + //check flash message + $this->assertFlashMessage('メールフィールド「edit」を更新しました。'); + //check redirect + $this->assertRedirect('/baser/admin/bc-mail/mail_fields/index/1'); + //check data + $mailField = MailFieldsFactory::get(1); + $this->assertEquals($data['name'], $mailField['name']); + $data = [ + 'name' => null, + 'type' => 'text' + ]; + //対象URLをコル + $this->post('/baser/admin/bc-mail/mail_fields/edit/1/1', $data); + //check response code + $this->assertResponseCode(200); + $this->assertResponseContains('入力エラーです。内容を修正してください。'); + //テストデータベースを削除 + $MailMessagesService->dropTable(1); } /** From fbcfa8241e1b821e7a32b43c5c4e799710a3dcaa Mon Sep 17 00:00:00 2001 From: thangnn Date: Mon, 15 Apr 2024 20:52:42 +0700 Subject: [PATCH 2/2] modified --- .../Controller/Admin/MailFieldsControllerTest.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php index 8961999a31..752551fa14 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php @@ -97,9 +97,6 @@ public function testAdmin_edit() { $this->enableSecurityToken(); $this->enableCsrfToken(); - $MailMessagesService = $this->getService(MailMessagesServiceInterface::class); - //テストデータベースを生成 - $MailMessagesService->createTable(1); //テストデータベースを生成 $this->loadFixtureScenario(MailContentsScenario::class); $this->loadFixtureScenario(MailFieldsScenario::class); @@ -116,9 +113,7 @@ public function testAdmin_edit() $this->assertFlashMessage('メールフィールド「edit」を更新しました。'); //check redirect $this->assertRedirect('/baser/admin/bc-mail/mail_fields/index/1'); - //check data - $mailField = MailFieldsFactory::get(1); - $this->assertEquals($data['name'], $mailField['name']); + //case error $data = [ 'name' => null, 'type' => 'text' @@ -128,8 +123,6 @@ public function testAdmin_edit() //check response code $this->assertResponseCode(200); $this->assertResponseContains('入力エラーです。内容を修正してください。'); - //テストデータベースを削除 - $MailMessagesService->dropTable(1); } /**