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 19, 2023
2 parents 3c03e04 + dc00ecb commit 46b9478
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public function beforeRender(EventInterface $event): void
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function index(ThemeFilesAdminServiceInterface $service)
{
Expand All @@ -146,6 +147,7 @@ public function index(ThemeFilesAdminServiceInterface $service)
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function add(ThemeFilesAdminServiceInterface $service)
{
Expand Down Expand Up @@ -279,6 +281,7 @@ public function delete_folder(ThemeFoldersAdminServiceInterface $service)
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function view(ThemeFilesAdminServiceInterface $service)
{
Expand All @@ -296,6 +299,7 @@ public function view(ThemeFilesAdminServiceInterface $service)
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function copy(ThemeFilesAdminServiceInterface $service)
{
Expand All @@ -322,6 +326,7 @@ public function copy(ThemeFilesAdminServiceInterface $service)
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function copy_folder(ThemeFoldersAdminServiceInterface $service)
{
Expand Down Expand Up @@ -349,6 +354,7 @@ public function copy_folder(ThemeFoldersAdminServiceInterface $service)
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function upload(ThemeFilesAdminServiceInterface $service)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,65 @@ public function test_beforeRender()
*/
public function test_index()
{
$this->markTestIncomplete('このテストは未実装です。');
$this->enableSecurityToken();
$this->enableCsrfToken();
//実行成功場合
$this->get('/baser/admin/bc-theme-file/theme_files/index/BcThemeSample');
//ステータスを確認
$this->assertResponseCode(200);
//取得データを確認
$pageTitle = $this->_controller->viewBuilder()->getVars()['pageTitle'];
$this->assertEquals('BcThemeSample|レイアウトテンプレート一覧', $pageTitle);

//実行成功場合
$this->get('/baser/admin/bc-theme-file/theme_files/index');
//ステータスを確認
$this->assertResponseCode(404);
}

/**
* test add
*/
public function test_add()
{
$this->markTestIncomplete('このテストは未実装です。');
$this->enableSecurityToken();
$this->enableCsrfToken();
//GETメソッドを検証場合
$this->get('/baser/admin/bc-theme-file/theme_files/add/BcThemeSample/layout');
//取得データを確認
$pageTitle = $this->_controller->viewBuilder()->getVars()['pageTitle'];
$this->assertEquals('BcThemeSample|レイアウトテンプレート作成', $pageTitle);

$postData = [
'fullpath' => '/var/www/html/plugins/BcThemeSample/templates/layout/',
'parent' => '/var/www/html/plugins/BcThemeSample/templates/layout/',
'base_name' => 'test',
'ext' => 'php',
'contents' => 'test content',
];
//Postメソッドを検証場合
$this->post('/baser/admin/bc-theme-file/theme_files/add', $postData);
//戻る値を確認
$this->assertResponseCode(302);
$this->assertFlashMessage('ファイル test.php を作成しました。');
$this->assertRedirect(['action' => 'edit/layout/test.php']);
unlink('/var/www/html/plugins/BcThemeSample/templates/layout/test.php');

$postData = [
'fullpath' => '/var/www/html/plugins/BcThemeSample/templates/layout/',
'parent' => '/var/www/html/plugins/BcThemeSample/templates/layout/',
'ext' => 'php',
'contents' => 'test content',
];
//エラーを発生した場合
$this->post('/baser/admin/bc-theme-file/theme_files/add', $postData);
//戻る値を確認
$this->assertResponseCode(200);
$themeFileFormVar = $this->_controller->viewBuilder()->getVar('themeFileForm');
$this->assertEquals(
'テーマファイル名を入力してください。',
$themeFileFormVar->getErrors()['base_name']['_required']
);
}

/**
Expand Down Expand Up @@ -220,31 +270,103 @@ public function test_delete_folder()
*/
public function test_view()
{
$this->markTestIncomplete('このテストは未実装です。');
//準備
$this->enableSecurityToken();
$this->enableCsrfToken();
//GETメソッドを検証場合
$this->get('/baser/admin/bc-theme-file/theme_files/view/BcThemeSample/layout/default.php');
//ステータスを確認
$this->assertResponseCode(200);
//取得データを確認
$pageTitle = $this->_controller->viewBuilder()->getVars()['pageTitle'];
$this->assertEquals('BcThemeSample|レイアウトテンプレート表示', $pageTitle);

//エラーを発生した場合
$this->get('/baser/admin/bc-theme-file/theme_files/view/BcThemeSample/layout3/default.php');
//ステータスを確認
$this->assertResponseCode(404);
}

/**
* test copy
*/
public function test_copy()
{
$this->markTestIncomplete('このテストは未実装です。');
$this->enableSecurityToken();
$this->enableCsrfToken();
$fullpath = BASER_PLUGINS . 'BcThemeSample/templates/layout/';
//Postメソッドを検証場合
$this->post('/baser/admin/bc-theme-file/theme_files/copy/BcThemeSample/layout/default.php');
//戻る値を確認
$this->assertResponseCode(302);
$this->assertFlashMessage('ファイル default.php をコピーしました。');
$this->assertRedirect('baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout/.');
unlink($fullpath . 'default_copy.php');
}

/**
* test copy_folder
*/
public function test_copy_folder()
{
$this->markTestIncomplete('このテストは未実装です。');
$this->enableSecurityToken();
$this->enableCsrfToken();
//テストテーマフォルダを作成
$fullpath = BASER_PLUGINS . 'BcThemeSample' . '/templates/layout';
$folder = new BcFolder($fullpath . DS . 'new_folder');
$folder->create();

//Postメソッドを検証場合
$this->post('/baser/admin/bc-theme-file/theme_files/copy_folder/BcThemeSample/layout/new_folder');
//戻る値を確認
$this->assertResponseCode(302);
$this->assertFlashMessage('フォルダ new_folder をコピーしました。');
$this->assertRedirect('baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout/.');

//テスト後に不要なフォルダーを削除
$folder->delete();
$folder = new BcFolder($fullpath . DS . 'new_folder_copy');
$folder->delete();
}

/**
* test upload
*/
public function test_upload()
{
$this->markTestIncomplete('このテストは未実装です。');
//準備
$this->enableSecurityToken();
$this->enableCsrfToken();
//テストフォルダパス
$fullpath = BASER_PLUGINS . 'BcThemeSample' . '/templates/layout/';

//テストファイルを作成
$filePath = TMP . 'test_upload' . DS;
(new BcFolder($filePath))->create();
$testFile = $filePath . 'uploadTestFile.html';
$tmpFile = new BcFile($testFile);
$tmpFile->create();

$this->setUploadFileToRequest('file', $testFile);
$this->setUnlockedFields(['file']);

//Postメソッドを検証場合
$this->post('/baser/admin/bc-theme-file/theme_files/upload/BcThemeSample/layout');
//ステータスを確認
$this->assertResponseCode(302);
$this->assertFlashMessage('アップロードに成功しました。');
$this->assertRedirect('/baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout');
//実際にファイルが存在するか確認すること
$this->assertTrue(file_exists($fullpath . 'uploadTestFile.html'));

//テストファイルとフォルダを削除
rmdir($filePath);
unlink($fullpath . 'uploadTestFile.html');

//エラーを発生した場合
$this->assertRedirect('/baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout3');
//ステータスを確認
$this->assertResponseCode(500);
}

/**
Expand Down

0 comments on commit 46b9478

Please sign in to comment.