Skip to content

Commit

Permalink
Merge pull request #4039 from HungDV2022/unittest_BcShortCodeEventLis…
Browse files Browse the repository at this point in the history
…tener_afterRender

BcShortCodeEventListener::afterRender() & _execShortCode() ユニットテスト調整
  • Loading branch information
HungDV2022 authored Nov 25, 2024
2 parents 752569a + 062215d commit 71ffb88
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plugins/baser-core/src/Event/BcShortCodeEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function implementedEvents(): array
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function afterRender(Event $event)
{
Expand All @@ -65,6 +66,7 @@ public function afterRender(Event $event)
* @return void
* @checked
* @noTodo
* @unitTest
*/
protected function _execShortCode(View $view)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@

use BaserCore\Event\BcShortCodeEventListener;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\View\BcFrontAppView;
use Cake\Event\Event;

class BcShortCodeEventListenerTest extends BcTestCase
{
/**
* @var BcShortCodeEventListener
*/
protected $BcShortCodeEventListener;

public function setUp(): void
{
parent::setUp();
Expand All @@ -26,4 +33,34 @@ public function testImplementedEvents()
$this->assertTrue(is_array($this->BcShortCodeEventListener->implementedEvents()));
}

/**
* test afterRender
*/
public function testAfterRender()
{
//準備
$view = new BcFrontAppView($this->getRequest('/'));
$view->loadHelper('BcBaser', ['className' => 'BaserCore.BcBaser']);
$view->assign('content', '[BcBaser.getSitemap]');
$event = new Event('afterRender', $view);
//テストを実行
$this->BcShortCodeEventListener->afterRender($event);
//戻り値を確認
$this->assertTextContains('<ul class="menu ul-level-1">', $view->fetch('content'));
}

/**
* test _execShortCode
*/
public function test_execShortCode()
{
//準備
$view = new BcFrontAppView($this->getRequest('/'));
$view->loadHelper('BcBaser', ['className' => 'BaserCore.BcBaser']);
$view->assign('content', '[BcBaser.getSitemap]');
//テストを実行
$this->execPrivateMethod($this->BcShortCodeEventListener, '_execShortCode', [$view]);
//戻り値を確認
$this->assertTextContains('<ul class="menu ul-level-1">', $view->fetch('content'));
}
}

0 comments on commit 71ffb88

Please sign in to comment.