Skip to content

Commit

Permalink
MailMessagesController::beforeFilter() ユニットテスト
Browse files Browse the repository at this point in the history
  • Loading branch information
dovanhung committed Dec 6, 2024
1 parent 60acdbb commit a34e1ab
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function initialize(): void
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function beforeFilter(EventInterface $event)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@

namespace BcMail\Test\TestCase\Controller\Admin;

use BaserCore\Test\Factory\ContentFactory;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BcMail\Controller\Admin\MailMessagesController;
use Cake\Event\Event;
use Cake\TestSuite\IntegrationTestTrait;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

class MailMessagesControllerTest extends BcTestCase
{

/**
* Trait
*/
use ScenarioAwareTrait;
use IntegrationTestTrait;
/**
* set up
*
Expand All @@ -25,7 +34,8 @@ class MailMessagesControllerTest extends BcTestCase
public function setUp(): void
{
parent::setUp();
$this->MailMessagesController = new MailMessagesController($this->getRequest());
$this->loadFixtureScenario(InitAppScenario::class);
$this->MailMessagesController = new MailMessagesController($this->loginAdmin($this->getRequest()));
}

/**
Expand Down Expand Up @@ -53,7 +63,31 @@ public function testInitialize()
*/
public function testBeforeFilter()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
ContentFactory::make([
'name' => 'name_test',
'plugin' => 'BcMail',
'type' => 'MailContent',
'url' => '/contact/',
'site_id' => 1,
'title' => 'お問い合わせ',
'entity_id' => 1
])->persist();

//正常テスト・エラーにならない
$request = $this->getRequest('/baser/admin/bc-mail/mail_messages/view/1/1');
$request = $this->loginAdmin($request);
$this->MailMessagesController = new MailMessagesController($request);
$event = new Event('filter');
$this->MailMessagesController->beforeFilter($event);

//異常テスト
$request = $this->getRequest('/baser/admin/bc-mail/mail_messages/view/2222/1');
$request = $this->loginAdmin($request);
$this->MailMessagesController = new MailMessagesController($request);
$event = new Event('filter');
$this->expectExceptionMessage('コンテンツデータが見つかりません。');
$this->expectException('BaserCore\Error\BcException');
$this->MailMessagesController->beforeFilter($event);
}

/**
Expand Down

0 comments on commit a34e1ab

Please sign in to comment.