Skip to content

Commit

Permalink
Merge pull request #3964 from HungDV2022/unittest_MailController_index
Browse files Browse the repository at this point in the history
MailController::index() ユニットテスト
  • Loading branch information
HungDV2022 authored Nov 7, 2024
2 parents 868499a + 43544b4 commit 2c13165
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
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 @@ -134,6 +134,7 @@ public function beforeRender(EventInterface $event): void
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function index(
MailFrontServiceInterface $service,
Expand Down
33 changes: 31 additions & 2 deletions plugins/bc-mail/tests/TestCase/Controller/MailControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand 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);
}

/**
Expand Down

0 comments on commit 2c13165

Please sign in to comment.