Skip to content

Commit

Permalink
Merge pull request #3965 from HungDV2022/unittest_MailController_confirm
Browse files Browse the repository at this point in the history
MailController::confirm() ユニットテスト調整
  • Loading branch information
HungDV2022 authored Nov 8, 2024
2 parents 4ad5093 + c051171 commit 8f9ceba
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugins/baser-core/src/BaserCorePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions plugins/bc-mail/src/Controller/MailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public function index(
* @return \Cake\Http\Response|void|null
* @checked
* @noTodo
* @unitTest
*/
public function confirm(
MailFrontServiceInterface $service,
Expand Down
62 changes: 60 additions & 2 deletions plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -104,15 +105,72 @@ 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);
}

/**
* [PUBIC] データ送信
*/
public function testSubmit()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
//準備
$this->enableSecurityToken();
$this->enableCsrfToken();

SiteConfigFactory::make(['name' => 'email', 'value' => '[email protected]'])->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' => '[email protected]'
])->persist();

$this->session(['BcMail' => ['valid' => true]]);
$this->post('/contact/submit/', ['sex' => 1]);
$this->assertResponseCode(302);
$this->assertRedirect('/contact/thanks');
}

/**
Expand Down

0 comments on commit 8f9ceba

Please sign in to comment.