Skip to content

Commit

Permalink
Admin/ThemeFilesController::beforeRender のユニットテスト (#2791)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <[email protected]>
Co-authored-by: ryuring <[email protected]>
  • Loading branch information
3 people authored Oct 16, 2023
1 parent 83d3256 commit 8eba0be
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ protected function isDefaultTheme()
* @param EventInterface $event
* @checked
* @noTodo
* @unitTest
*/
public function beforeRender(EventInterface $event): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use BcThemeFile\Controller\Admin\ThemeFilesController;
use Cake\Event\Event;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
* Class ThemeFilesControllerTest
*
* @property ThemeFilesController $ThemeFilesController
*/
class ThemeFilesControllerTest extends BcTestCase
{
Expand Down Expand Up @@ -92,7 +91,31 @@ public function test_isDefaultTheme()
*/
public function test_beforeRender()
{
$this->markTestIncomplete('このテストは未実装です。');
$this->enableSecurityToken();
$this->enableCsrfToken();

//テーマがデフォルトテーマの場合、
$request = $this->getRequest()->withParam('pass.0', 'BcFront');
$themeFilesController = new ThemeFilesController($this->loginAdmin($request));
$themeFilesController->beforeRender(new Event('beforeRender'));
$this->assertEquals(
'デフォルトテーマのため編集できません。編集する場合は、テーマをコピーしてご利用ください。',
$_SESSION['Flash']['flash'][0]['message']
);

//テーマがデフォルトテーマではないの場合、
$request = $this->getRequest()->withParam('pass.0', 'BcColumn');
$themeFilesController = new ThemeFilesController($this->loginAdmin($request));
$themeFilesController->beforeRender(new Event('beforeRender'));
$this->assertEmpty($_SESSION);

$this->get('/baser/admin/bc-theme-file/theme_files/index/BcThemeSample');
$isDefaultTheme = $this->_controller->viewBuilder()->getVars()['isDefaultTheme'];
$this->assertFalse($isDefaultTheme);

$this->get('/baser/admin/bc-theme-file/theme_files/index/BcFront');
$isDefaultTheme = $this->_controller->viewBuilder()->getVars()['isDefaultTheme'];
$this->assertTrue($isDefaultTheme);
}

/**
Expand Down

0 comments on commit 8eba0be

Please sign in to comment.