Skip to content

Commit

Permalink
admin/ThemeFilesController::add_folder() のユニットテスト (#2814)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <[email protected]>
  • Loading branch information
HungDV2022 and dovanhung authored Oct 22, 2023
1 parent 5b20e13 commit 1ae01f6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ public function upload(ThemeFilesAdminServiceInterface $service)
* @return Response|void|null
* @checked
* @noTodo
* @unitTest
*/
public function add_folder(ThemeFoldersAdminServiceInterface $service)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,44 @@ public function test_upload()
*/
public function test_add_folder()
{
$this->markTestIncomplete('このテストは未実装です。');
$this->enableSecurityToken();
$this->enableCsrfToken();

//GETメソッドを検証場合
$this->get('/baser/admin/bc-theme-file/theme_files/add_folder/BcThemeSample/layout');
//取得データを確認
$pageTitle = $this->_controller->viewBuilder()->getVars()['pageTitle'];
$this->assertEquals('BcThemeSample|フォルダ作成', $pageTitle);

$fullpath = BASER_PLUGINS . 'BcThemeSample' . '/templates/layout';
$postData = [
'parent' => $fullpath,
'fullpath' => $fullpath,
'name' => 'new_folder',
];

//POSTメソッドを検証場合
$this->post('/baser/admin/bc-theme-file/theme_files/add_folder/BcThemeSample/layout', $postData);
//戻る値を確認
$this->assertResponseCode(302);
$this->assertFlashMessage('フォルダ「new_folder」を作成しました。');
$this->assertRedirect('/baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout');
//実際にフォルダが作成されいてるか確認すること
$this->assertTrue(is_dir($fullpath . '/new_folder'));

//作成されたフォルダを削除
rmdir($fullpath . '/new_folder');

//BcFormFailedExceptionを発生した場合、
$postData['name'] = 'ああああ';
$this->post('/baser/admin/bc-theme-file/theme_files/add_folder/BcThemeSample/layout', $postData);
//戻る値を確認
$this->assertResponseCode(200);
$themeFolderForm = $this->_controller->viewBuilder()->getVar('themeFolderForm');
$this->assertEquals(
'テーマフォルダー名は半角英数字とハイフン、アンダースコアのみが利用可能です。',
$themeFolderForm->getErrors()['name']['nameAlphaNumericPlus']
);
}

/**
Expand Down

0 comments on commit 1ae01f6

Please sign in to comment.