diff --git a/plugins/bc-installer/src/Service/Admin/InstallationsAdminService.php b/plugins/bc-installer/src/Service/Admin/InstallationsAdminService.php index b2a828347d..6f4a6634ad 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 7389c3e2f4..42f1cd9c96 100644 --- a/plugins/bc-installer/tests/TestCase/Service/Admin/InstallationsAdminServiceTest.php +++ b/plugins/bc-installer/tests/TestCase/Service/Admin/InstallationsAdminServiceTest.php @@ -17,6 +17,7 @@ use BaserCore\Test\Factory\ContentFolderFactory; use BaserCore\Test\Factory\UserFactory; use BaserCore\Test\Scenario\InitAppScenario; +use BaserCore\Service\BcDatabaseServiceInterface; use BaserCore\TestSuite\BcTestCase; use BaserCore\Utility\BcContainerTrait; use BaserCore\Utility\BcFile; @@ -27,6 +28,7 @@ use Cake\Http\Response; use Cake\Http\ServerRequest; use Cake\Http\Session; +use Migrations\Migrations; use Cake\ORM\Exception\PersistenceFailedException; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; @@ -427,7 +429,55 @@ 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(); + $session->write('Installation', $config); + $request = new ServerRequest(['session' => $session]); + + //テストを実行 + $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); + } } /**