Skip to content

Commit

Permalink
Merge branch 'dev-5' of github.com:baserproject/basercms into dev-5
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Oct 16, 2023
2 parents 5cadcf1 + b135450 commit df47866
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 6 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 Expand Up @@ -183,6 +184,7 @@ public function add(ThemeFilesAdminServiceInterface $service)
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function edit(ThemeFilesAdminServiceInterface $service)
{
Expand Down Expand Up @@ -221,6 +223,7 @@ public function edit(ThemeFilesAdminServiceInterface $service)
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function delete(ThemeFilesAdminServiceInterface $service)
{
Expand Down Expand Up @@ -248,6 +251,7 @@ public function delete(ThemeFilesAdminServiceInterface $service)
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function delete_folder(ThemeFoldersAdminServiceInterface $service)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use BaserCore\Utility\BcFolder;
use BaserCore\Utility\BcFile;
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 +93,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 All @@ -116,23 +141,78 @@ public function test_add()
*/
public function test_edit()
{
$this->markTestIncomplete('このテストは未実装です。');
$this->enableSecurityToken();
$this->enableCsrfToken();
$fullpath = BASER_PLUGINS . 'BcColumn' . '/layout/';
$file = new BcFile($fullpath . 'base_name_1.php');
$file->create();

//GETメソッドを検証場合
$this->get('/baser/admin/bc-theme-file/theme_files/edit/BcColumn/layout/base_name_1.php');
//取得データを確認
$pageTitle = $this->_controller->viewBuilder()->getVars()['pageTitle'];
$this->assertEquals('BcColumn|レイアウトテンプレート編集', $pageTitle);

$postData = [
'fullpath' => '/var/www/html/plugins/BcColumn/layout/',
'parent' => '/var/www/html/plugins/BcColumn/layout/',
'theme' => 'BcColumn',
'type' => 'layout',
'path' => 'test.php',
'base_name' => 'base_name_2',
'contents' => 'this is a content changed!',
'ext' => 'php',
'plugin' => 'BaserCore'
];
//Postメソッドを検証場合
$this->post('/baser/admin/bc-theme-file/theme_files/edit/BcColumn/layout/base_name_1.php', $postData);
//戻る値を確認
$this->assertResponseCode(302);
$this->assertFlashMessage('ファイル base_name_2.php を更新しました。');
$this->assertRedirect(['action' => 'edit/layout/base_name_2.php']);
unlink($fullpath . 'base_name_2.php');
}

/**
* test delete
*/
public function test_delete()
{
$this->markTestIncomplete('このテストは未実装です。');
$this->enableSecurityToken();
$this->enableCsrfToken();
$fullpath = BASER_PLUGINS . 'bc-column' . '/templates/layout/';
$file = new BcFile($fullpath . 'base_name_1.php');
$file->create();

//Postメソッドを検証場合
$this->post('/baser/admin/bc-theme-file/theme_files/delete/BcColumn/layout/base_name_1.php');
//戻る値を確認
$this->assertResponseCode(302);
$this->assertFlashMessage('ファイル base_name_1.php を削除しました。');
$this->assertRedirect('/baser/admin/bc-theme-file/theme_files/index/BcColumn/layout/');
//実際にファイルが削除されいてるか確認すること
$this->assertFalse(file_exists($fullpath . 'base_name_1.php'));
}

/**
* test delete_folder
*/
public function test_delete_folder()
{
$this->markTestIncomplete('このテストは未実装です。');
$this->enableSecurityToken();
$this->enableCsrfToken();
//テストテーマフォルダを作成
$fullpath = BASER_PLUGINS . 'BcThemeSample' . '/templates/layout';
$folder = new BcFolder($fullpath . DS . 'delete_folder');
$folder->create();
//Postメソッドを検証場合
$this->post('/baser/admin/bc-theme-file/theme_files/delete_folder/BcThemeSample/layout/delete_folder');
//戻る値を確認
$this->assertResponseCode(302);
$this->assertFlashMessage('フォルダ delete_folder を削除しました。');
$this->assertRedirect('/baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout/');
//実際にフォルダが削除されいてるか確認すること
$this->assertFalse(file_exists($fullpath . 'delete_folder'));
}

/**
Expand Down

0 comments on commit df47866

Please sign in to comment.