From a7a46ff57325be9e8beebca2bb8e96ac3ef30f89 Mon Sep 17 00:00:00 2001 From: TPGF00003 Date: Thu, 31 Oct 2024 11:16:50 +0900 Subject: [PATCH] =?UTF-8?q?MailController::index()=20=E3=83=A6=E3=83=8B?= =?UTF-8?q?=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 --- .../bc-mail/src/Controller/MailController.php | 1 + .../Controller/MailControllerTest.php | 33 +++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/plugins/bc-mail/src/Controller/MailController.php b/plugins/bc-mail/src/Controller/MailController.php index fa4fde61be..ccae3c4762 100755 --- a/plugins/bc-mail/src/Controller/MailController.php +++ b/plugins/bc-mail/src/Controller/MailController.php @@ -134,6 +134,7 @@ public function beforeRender(EventInterface $event): void * @return void * @checked * @noTodo + * @unitTest */ public function index( MailFrontServiceInterface $service, diff --git a/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php index 604c4da8d9..88a552da50 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php @@ -11,10 +11,22 @@ namespace BcMail\Test\TestCase\Controller; +use BaserCore\Test\Factory\ContentFactory; +use BaserCore\Test\Factory\SiteFactory; use BaserCore\TestSuite\BcTestCase; +use BaserCore\Utility\BcContainerTrait; +use BcMail\Test\Factory\MailContentFactory; +use BcMail\Test\Factory\MailFieldsFactory; +use Cake\TestSuite\IntegrationTestTrait; +use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; class MailControllerTest extends BcTestCase { + + use ScenarioAwareTrait; + use IntegrationTestTrait; + use BcContainerTrait; + /** * set up * @@ -53,11 +65,28 @@ public function testBeforeRender() /** * [test_index description] - * @return [type] [description] */ public function test_index() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + //準備 + SiteFactory::make(['id' => 1])->persist(); + MailFieldsFactory::make(['mail_content_id' => 1, 'no' => 1])->persist(); + ContentFactory::make(['id' => 1, 'plugin' => 'BcMail', 'type' => 'MailContent', 'entity_id' => 1, 'url' => '/contact/', 'site_id' => 1, 'lft' => 1, 'rght' => 2])->persist(); + MailContentFactory::make(['id' => 1, 'form_template' => 'default', 'mail_template' => 'mail_default'])->persist(); + //正常テスト + $this->get('/contact/'); + + $this->assertResponseOk(); + $vars = $this->_controller->viewBuilder()->getVars(); + $this->assertNotNull($vars['mailContent']); + $this->assertNotNull($vars['mailFields']); + $this->assertNotNull($vars['mailMessage']); + $this->assertNotNull($vars['description']); + $this->assertTrue($_SESSION["BcMail"]["valid"]); + + //異常テスト + $this->get('/contact-test/'); + $this->assertResponseCode(404); } /**