From eeb180faa769644bbd066818bf374365f6e48518 Mon Sep 17 00:00:00 2001 From: TPGF00003 Date: Thu, 31 Oct 2024 12:53:56 +0900 Subject: [PATCH 1/2] =?UTF-8?q?MailController::confirm()=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=E8=AA=BF?= =?UTF-8?q?=E6=95=B4?= 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 | 50 ++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/plugins/bc-mail/src/Controller/MailController.php b/plugins/bc-mail/src/Controller/MailController.php index fa4fde61be..8a399b5e64 100755 --- a/plugins/bc-mail/src/Controller/MailController.php +++ b/plugins/bc-mail/src/Controller/MailController.php @@ -166,6 +166,7 @@ public function index( * @return \Cake\Http\Response|void|null * @checked * @noTodo + * @unitTest */ public function confirm( MailFrontServiceInterface $service, diff --git a/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php index 604c4da8d9..486b9e89e5 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 * @@ -75,7 +87,43 @@ public function testIndex() */ public function testConfirm() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + + //準備 + $this->enableSecurityToken(); + $this->enableCsrfToken(); + + SiteFactory::make(['id' => 1])->persist(); + MailFieldsFactory::make(['mail_content_id' => 1, 'field_name' => 'sex'])->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(); + + //正常テスト GET METHOD + $this->get('/contact/confirm'); + $this->assertResponseCode(302); + $this->assertRedirect('/contact/'); + $vars = $this->_controller->viewBuilder()->getVars(); + $this->assertNotNull($vars['title']); + $this->assertNotNull($vars['description']); + + //異常テスト valid=false + $this->post('/contact/confirm/', ['sex' => 1]); + $this->assertResponseCode(302); + $this->assertRedirect('/contact/'); + $this->assertFlashMessage('エラーが発生しました。もう一度操作してください。'); + + //正常テスト  valid=true + $this->session(['BcMail' => ['valid' => true]]); + $this->post('/contact/confirm/', ['sex' => 1]); + $this->assertResponseCode(200); + $vars = $this->_controller->viewBuilder()->getVars(); + $this->assertNotNull($vars['mailContent']); + $this->assertNotNull($vars['mailFields']); + $this->assertNotNull($vars['mailMessage']); + $this->assertNotNull($vars['description']); + + //異常テスト + $this->post('/contact/confirm/'); + $this->assertResponseCode(500); } /** From c0511710367d8e56cf3f768044f7dc72bcf7e6e4 Mon Sep 17 00:00:00 2001 From: TPGF00003 Date: Thu, 7 Nov 2024 12:27:06 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/baser-core/src/BaserCorePlugin.php | 2 +- .../Controller/MailControllerTest.php | 24 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/plugins/baser-core/src/BaserCorePlugin.php b/plugins/baser-core/src/BaserCorePlugin.php index 0165c97b3b..a092f39fc2 100644 --- a/plugins/baser-core/src/BaserCorePlugin.php +++ b/plugins/baser-core/src/BaserCorePlugin.php @@ -253,7 +253,7 @@ public function setupThemePlugin(array $themes): void if (!is_dir($pluginsPath)) continue; $path[] = $pluginsPath; } - if($path) { + if(isset($path) && $path) { Configure::write('App.paths.plugins', array_merge( Configure::read('App.paths.plugins'), $path diff --git a/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php index e8cda7c49c..8327399fc3 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php @@ -12,6 +12,7 @@ namespace BcMail\Test\TestCase\Controller; use BaserCore\Test\Factory\ContentFactory; +use BaserCore\Test\Factory\SiteConfigFactory; use BaserCore\Test\Factory\SiteFactory; use BaserCore\TestSuite\BcTestCase; use BaserCore\Utility\BcContainerTrait; @@ -148,7 +149,28 @@ public function testConfirm() */ public function testSubmit() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + //準備 + $this->enableSecurityToken(); + $this->enableCsrfToken(); + + SiteConfigFactory::make(['name' => 'email', 'value' => 'abc@gmail.com'])->persist(); + SiteConfigFactory::make(['name' => 'admin-theme', 'value' => 'test theme'])->persist(); + SiteFactory::make(['id' => 1])->persist(); + MailFieldsFactory::make(['mail_content_id' => 1, 'field_name' => 'sex'])->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', + 'subject_user' => '【baserCMS】お問い合わせ頂きありがとうございます。', + 'subject_admin' => '【baserCMS】お問い合わせを受け付けました', + 'sender_1' => 't@gm.com' + ])->persist(); + + $this->session(['BcMail' => ['valid' => true]]); + $this->post('/contact/submit/', ['sex' => 1]); + $this->assertResponseCode(302); + $this->assertRedirect('/contact/thanks'); } /**