diff --git a/plugins/baser-core/src/BaserCorePlugin.php b/plugins/baser-core/src/BaserCorePlugin.php index f23deb8969..a5848d8901 100644 --- a/plugins/baser-core/src/BaserCorePlugin.php +++ b/plugins/baser-core/src/BaserCorePlugin.php @@ -254,7 +254,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/src/Controller/MailController.php b/plugins/bc-mail/src/Controller/MailController.php index ccae3c4762..db237419a5 100755 --- a/plugins/bc-mail/src/Controller/MailController.php +++ b/plugins/bc-mail/src/Controller/MailController.php @@ -167,6 +167,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 88a552da50..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; @@ -104,7 +105,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); } /** @@ -112,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'); } /**