From 39ed635cfdea80d3f0c90dee62c672b44d4f1e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Tue, 22 Oct 2024 13:53:03 +0900 Subject: [PATCH 1/2] =?UTF-8?q?InstallationsAdminService::deleteAllTables(?= =?UTF-8?q?)=20=E3=81=AE=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/InstallationsAdminService.php | 4 +- .../Admin/InstallationsAdminServiceTest.php | 51 ++++++++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/plugins/bc-installer/src/Service/Admin/InstallationsAdminService.php b/plugins/bc-installer/src/Service/Admin/InstallationsAdminService.php index 34bfcb95e1..062205fd67 100644 --- a/plugins/bc-installer/src/Service/Admin/InstallationsAdminService.php +++ b/plugins/bc-installer/src/Service/Admin/InstallationsAdminService.php @@ -232,13 +232,11 @@ public function readDbSetting(ServerRequest $request, array $installationData = * @return bool * @checked * @noTodo + * @unitTest */ public function deleteAllTables(ServerRequest $request): bool { $dbConfig = $this->readDbSetting($request); - if (!$dbConfig) { - $dbConfig = ConnectionManager::getConfig('default'); - } return $this->BcDatabase->deleteTables('default', $dbConfig); } diff --git a/plugins/bc-installer/tests/TestCase/Service/Admin/InstallationsAdminServiceTest.php b/plugins/bc-installer/tests/TestCase/Service/Admin/InstallationsAdminServiceTest.php index 2856216447..17dbb9359a 100644 --- a/plugins/bc-installer/tests/TestCase/Service/Admin/InstallationsAdminServiceTest.php +++ b/plugins/bc-installer/tests/TestCase/Service/Admin/InstallationsAdminServiceTest.php @@ -12,6 +12,7 @@ namespace BcInstaller\Test\TestCase\Service\Admin; +use BaserCore\Service\BcDatabaseServiceInterface; use BaserCore\TestSuite\BcTestCase; use BaserCore\Utility\BcContainerTrait; use BcInstaller\Service\Admin\InstallationsAdminService; @@ -19,6 +20,7 @@ use Cake\Core\Configure; use Cake\Http\ServerRequest; use Cake\Http\Session; +use Migrations\Migrations; /** * InstallationsAdminServiceTest @@ -416,7 +418,54 @@ public static function readDbSettingDataProvider() */ public function test_deleteAllTables() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + //準備 + $bcDatabaseService = $this->getService(BcDatabaseServiceInterface::class); + $config = [ + 'dbType' => 'mysql', + 'dbHost' => 'localhost', + 'dbPrefix' => '', + 'dbPort' => '3306', + 'dbUsername' => 'dbUsername', + 'dbPassword' => 'dbPassword', + 'dbSchema' => 'dbSchema', + 'dbName' => 'basercms', + 'dbEncoding' => 'utf-8', + 'dbDataPattern' => 'BcThemeSample.default' + ]; + $session = new Session(); + $request = new ServerRequest(['session' => $session->write('Installation', $config)]); + + //テストを実行 + $this->Installations->deleteAllTables($request); + + //全てテーブルを削除できるか確認 + $db = $bcDatabaseService->getDataSource(); + $tables = $db->getSchemaCollection()->listTables(); + $this->assertCount(0, $tables); + + //テーブルを復活 + $migrations = new Migrations(); + $plugins = [ + 'BaserCore', + 'BcBlog', + 'BcContentLink', + 'BcCustomContent', + 'BcEditorTemplate', + 'BcFavorite', + 'BcMail', + 'BcSearchIndex', + 'BcThemeConfig', + 'BcThemeFile', + 'BcUploader', + 'BcWidgetArea', + ]; + foreach ($plugins as $plugin) { + $migrate = $migrations->migrate([ + 'connection' => 'test', + 'plugin' => $plugin, + ]); + $this->assertTrue($migrate); + } } /** From a442eb83b329ec0957ed80f7b9c3872a493fb014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Tue, 22 Oct 2024 13:54:51 +0900 Subject: [PATCH 2/2] =?UTF-8?q?InstallationsAdminService::deleteAllTables(?= =?UTF-8?q?)=20=E3=81=AE=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestCase/Service/Admin/InstallationsAdminServiceTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/bc-installer/tests/TestCase/Service/Admin/InstallationsAdminServiceTest.php b/plugins/bc-installer/tests/TestCase/Service/Admin/InstallationsAdminServiceTest.php index 17dbb9359a..9bfaf396c2 100644 --- a/plugins/bc-installer/tests/TestCase/Service/Admin/InstallationsAdminServiceTest.php +++ b/plugins/bc-installer/tests/TestCase/Service/Admin/InstallationsAdminServiceTest.php @@ -433,7 +433,8 @@ public function test_deleteAllTables() 'dbDataPattern' => 'BcThemeSample.default' ]; $session = new Session(); - $request = new ServerRequest(['session' => $session->write('Installation', $config)]); + $session->write('Installation', $config); + $request = new ServerRequest(['session' => $session]); //テストを実行 $this->Installations->deleteAllTables($request);