From 29248d2d9df27b62e685f44ee8e1d60fe9e6f884 Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Thu, 2 Nov 2023 16:24:18 +0700 Subject: [PATCH] =?UTF-8?q?BcThemeFile=E3=82=92=E5=85=A8=E4=BD=93=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=81=AE=E5=AE=9F=E8=A1=8C=E5=AF=BE=E8=B1=A1?= =?UTF-8?q?=E3=81=AB=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B=20(#2830)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- phpunit.xml.dist | 6 ++-- .../Controller/Admin/ThemeFilesController.php | 10 +++---- .../Admin/ThemeFilesControllerTest.php | 30 ++++++++----------- .../Api/Admin/ThemeFoldersControllerTest.php | 5 ++++ .../Service/ThemeFilesServiceTest.php | 1 - 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4f81950cec..3cd8f9b62c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -39,9 +39,9 @@ plugins/bc-theme-config/tests/TestCase - - - + + plugins/bc-theme-file/tests/TestCase + diff --git a/plugins/bc-theme-file/src/Controller/Admin/ThemeFilesController.php b/plugins/bc-theme-file/src/Controller/Admin/ThemeFilesController.php index 610295ee04..7c1ea78f79 100644 --- a/plugins/bc-theme-file/src/Controller/Admin/ThemeFilesController.php +++ b/plugins/bc-theme-file/src/Controller/Admin/ThemeFilesController.php @@ -203,7 +203,7 @@ public function edit(ThemeFilesAdminServiceInterface $service) $this->BcMessage->setInfo(sprintf(__d('baser_core', 'ファイル %s を更新しました。'), $themeFile->name)); $this->redirect(array_merge( [$args['theme'], $args['plugin'], $args['type']], - explode('/', dirname($args['path'])), + (str_contains($args['path'], '/'))? explode('/', dirname($args['path'])) : [], [$themeFile->name] )); } catch (BcFormFailedException $e) { @@ -242,7 +242,7 @@ public function delete(ThemeFilesAdminServiceInterface $service) $this->redirect(array_merge( ['action' => 'index', $args['theme'], $args['plugin'], $args['type']], - explode('/', dirname($args['path'])) + (str_contains($args['path'], '/'))? explode('/', dirname($args['path'])) : [] )); } @@ -270,7 +270,7 @@ public function delete_folder(ThemeFoldersAdminServiceInterface $service) $this->redirect(array_merge( ['action' => 'index', $args['theme'], $args['plugin'], $args['type']], - explode('/', dirname($args['path'])) + (str_contains($args['path'], '/'))? explode('/', dirname($args['path'])) : [] )); } @@ -316,7 +316,7 @@ public function copy(ThemeFilesAdminServiceInterface $service) $this->redirect(array_merge( ['action' => 'index', $args['theme'], $args['plugin'], $args['type']], - explode('/', dirname($args['path'])) + (str_contains($args['path'], '/'))? explode('/', dirname($args['path'])) : [] )); } @@ -343,7 +343,7 @@ public function copy_folder(ThemeFoldersAdminServiceInterface $service) $this->redirect(array_merge( ['action' => 'index', $args['theme'], $args['plugin'], $args['type']], - explode('/', dirname($args['path'])) + (str_contains($args['path'], '/'))? explode('/', dirname($args['path'])) : [] )); } diff --git a/plugins/bc-theme-file/tests/TestCase/Controller/Admin/ThemeFilesControllerTest.php b/plugins/bc-theme-file/tests/TestCase/Controller/Admin/ThemeFilesControllerTest.php index 94f2e6a109..3b0acc42ef 100644 --- a/plugins/bc-theme-file/tests/TestCase/Controller/Admin/ThemeFilesControllerTest.php +++ b/plugins/bc-theme-file/tests/TestCase/Controller/Admin/ThemeFilesControllerTest.php @@ -193,33 +193,29 @@ public function test_edit() { $this->enableSecurityToken(); $this->enableCsrfToken(); - $fullpath = BASER_PLUGINS . 'BcColumn' . '/layout/'; + $fullpath = BASER_PLUGINS . 'BcThemeSample/templates/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'); + $this->get('/baser/admin/bc-theme-file/theme_files/edit/BcThemeSample/layout/base_name_1.php'); //取得データを確認 $pageTitle = $this->_controller->viewBuilder()->getVars()['pageTitle']; - $this->assertEquals('BcColumn|レイアウトテンプレート編集', $pageTitle); + $this->assertEquals('BcThemeSample|レイアウトテンプレート編集', $pageTitle); $postData = [ - 'fullpath' => '/var/www/html/plugins/BcColumn/layout/', - 'parent' => '/var/www/html/plugins/BcColumn/layout/', - 'theme' => 'BcColumn', - 'type' => 'layout', - 'path' => 'test.php', + 'fullpath' => $fullpath . 'base_name_1.php', + 'parent' => $fullpath, 'base_name' => 'base_name_2', - 'contents' => 'this is a content changed!', 'ext' => 'php', - 'plugin' => 'BaserCore' + 'contents' => "" ]; //Postメソッドを検証場合 - $this->post('/baser/admin/bc-theme-file/theme_files/edit/BcColumn/layout/base_name_1.php', $postData); + $this->post('/baser/admin/bc-theme-file/theme_files/edit/BcThemeSample/layout/base_name_1.php', $postData); //戻る値を確認 $this->assertResponseCode(302); $this->assertFlashMessage('ファイル base_name_2.php を更新しました。'); - $this->assertRedirect(['action' => 'edit/layout/base_name_2.php']); + $this->assertRedirect(['action' => 'edit/BcThemeSample/layout/base_name_2.php']); unlink($fullpath . 'base_name_2.php'); } @@ -239,7 +235,7 @@ public function test_delete() //戻る値を確認 $this->assertResponseCode(302); $this->assertFlashMessage('ファイル base_name_1.php を削除しました。'); - $this->assertRedirect('/baser/admin/bc-theme-file/theme_files/index/BcColumn/layout/'); + $this->assertRedirect('/baser/admin/bc-theme-file/theme_files/index/BcColumn/layout'); //実際にファイルが削除されいてるか確認すること $this->assertFalse(file_exists($fullpath . 'base_name_1.php')); } @@ -260,7 +256,7 @@ public function test_delete_folder() //戻る値を確認 $this->assertResponseCode(302); $this->assertFlashMessage('フォルダ delete_folder を削除しました。'); - $this->assertRedirect('/baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout/'); + $this->assertRedirect('/baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout'); //実際にフォルダが削除されいてるか確認すること $this->assertFalse(file_exists($fullpath . 'delete_folder')); } @@ -300,7 +296,7 @@ public function test_copy() //戻る値を確認 $this->assertResponseCode(302); $this->assertFlashMessage('ファイル default.php をコピーしました。'); - $this->assertRedirect('baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout/.'); + $this->assertRedirect('baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout'); unlink($fullpath . 'default_copy.php'); } @@ -321,7 +317,7 @@ public function test_copy_folder() //戻る値を確認 $this->assertResponseCode(302); $this->assertFlashMessage('フォルダ new_folder をコピーしました。'); - $this->assertRedirect('baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout/.'); + $this->assertRedirect('baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout'); //テスト後に不要なフォルダーを削除 $folder->delete(); @@ -364,7 +360,7 @@ public function test_upload() unlink($fullpath . 'uploadTestFile.html'); //エラーを発生した場合 - $this->assertRedirect('/baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout3'); + $this->post('/baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout3'); //ステータスを確認 $this->assertResponseCode(500); } diff --git a/plugins/bc-theme-file/tests/TestCase/Controller/Api/Admin/ThemeFoldersControllerTest.php b/plugins/bc-theme-file/tests/TestCase/Controller/Api/Admin/ThemeFoldersControllerTest.php index 2467784eff..8632e2a836 100644 --- a/plugins/bc-theme-file/tests/TestCase/Controller/Api/Admin/ThemeFoldersControllerTest.php +++ b/plugins/bc-theme-file/tests/TestCase/Controller/Api/Admin/ThemeFoldersControllerTest.php @@ -114,6 +114,7 @@ public function test_add() $fullpath = BASER_PLUGINS . 'BcThemeSample' . '/templates/layout/'; $data = [ 'theme' => 'BcThemeSample', + 'parent' => '/var/www/html/plugins/BcThemeSample/templates/layout/', 'plugin' => 'BaserCore', 'type' => 'layout', 'path' => '', @@ -146,6 +147,7 @@ public function test_edit() //Postデータを生成 $data = [ 'theme' => 'BcThemeSample', + 'parent' => '/var/www/html/plugins/BcThemeSample/templates/layout/', 'plugin' => 'BaserCore', 'type' => 'layout', 'path' => 'new_folder', @@ -180,6 +182,7 @@ public function test_delete() //Postデータを生成 $data = [ 'theme' => 'BcThemeSample', + 'parent' => '/var/www/html/plugins/BcThemeSample/templates/layout/', 'plugin' => 'BaserCore', 'type' => 'layout', 'path' => 'delete_folder', @@ -215,6 +218,7 @@ public function test_copy() //Postデータを生成 $data = [ 'theme' => 'BcThemeSample', + 'parent' => '/var/www/html/plugins/BcThemeSample/templates/layout/', 'plugin' => 'BaserCore', 'type' => 'layout', 'path' => 'new_folder', @@ -243,6 +247,7 @@ public function test_copy_to_theme() $fullpath = BASER_PLUGINS . '/BcPluginSample/templates/'; $data = [ 'theme' => 'BcFront', + 'parent' => '/var/www/html/plugins/BcThemeSample/templates/layout/', 'type' => 'Pages', 'path' => '', 'assets' => '', diff --git a/plugins/bc-theme-file/tests/TestCase/Service/ThemeFilesServiceTest.php b/plugins/bc-theme-file/tests/TestCase/Service/ThemeFilesServiceTest.php index cbbcd04084..2d459a3667 100644 --- a/plugins/bc-theme-file/tests/TestCase/Service/ThemeFilesServiceTest.php +++ b/plugins/bc-theme-file/tests/TestCase/Service/ThemeFilesServiceTest.php @@ -88,7 +88,6 @@ public function test_get() $this->assertEquals('php', $rs['ext']); $this->assertEquals('text', $rs['type']); $this->assertEquals(null, $rs['path']); - $this->assertTextContains('baserCMS : Based Website Development Project', $rs['contents']); } /**