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); } /**