From a34e1ab2e5a4df0459d7df1bd280e7f63e94e8e9 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Fri, 6 Dec 2024 10:49:22 +0900 Subject: [PATCH] =?UTF-8?q?MailMessagesController::beforeFilter()=20?= =?UTF-8?q?=E3=83=A6=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 | 40 +++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php b/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php index 3f0abc12b8..a5c45f74ff 100644 --- a/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php +++ b/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php @@ -54,6 +54,7 @@ public function initialize(): void * @return void * @checked * @noTodo + * @unitTest */ public function beforeFilter(EventInterface $event) { diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php index 54f996b53f..855390103d 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php @@ -11,12 +11,21 @@ namespace BcMail\Test\TestCase\Controller\Admin; +use BaserCore\Test\Factory\ContentFactory; +use BaserCore\Test\Scenario\InitAppScenario; use BaserCore\TestSuite\BcTestCase; use BcMail\Controller\Admin\MailMessagesController; +use Cake\Event\Event; +use Cake\TestSuite\IntegrationTestTrait; +use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; class MailMessagesControllerTest extends BcTestCase { - + /** + * Trait + */ + use ScenarioAwareTrait; + use IntegrationTestTrait; /** * set up * @@ -25,7 +34,8 @@ class MailMessagesControllerTest extends BcTestCase public function setUp(): void { parent::setUp(); - $this->MailMessagesController = new MailMessagesController($this->getRequest()); + $this->loadFixtureScenario(InitAppScenario::class); + $this->MailMessagesController = new MailMessagesController($this->loginAdmin($this->getRequest())); } /** @@ -53,7 +63,31 @@ public function testInitialize() */ public function testBeforeFilter() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + ContentFactory::make([ + 'name' => 'name_test', + 'plugin' => 'BcMail', + 'type' => 'MailContent', + 'url' => '/contact/', + 'site_id' => 1, + 'title' => 'お問い合わせ', + 'entity_id' => 1 + ])->persist(); + + //正常テスト・エラーにならない + $request = $this->getRequest('/baser/admin/bc-mail/mail_messages/view/1/1'); + $request = $this->loginAdmin($request); + $this->MailMessagesController = new MailMessagesController($request); + $event = new Event('filter'); + $this->MailMessagesController->beforeFilter($event); + + //異常テスト + $request = $this->getRequest('/baser/admin/bc-mail/mail_messages/view/2222/1'); + $request = $this->loginAdmin($request); + $this->MailMessagesController = new MailMessagesController($request); + $event = new Event('filter'); + $this->expectExceptionMessage('コンテンツデータが見つかりません。'); + $this->expectException('BaserCore\Error\BcException'); + $this->MailMessagesController->beforeFilter($event); } /**