Skip to content

Commit

Permalink
Merge pull request #3940 from HungDV2022/unitest_InstallationsAdminSe…
Browse files Browse the repository at this point in the history
…rviceTest_deleteAllTables

InstallationsAdminService::deleteAllTables() のユニットテスト
  • Loading branch information
HungDV2022 authored Oct 29, 2024
2 parents bd695c2 + 412746d commit a8a907d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
}

/**
Expand Down

0 comments on commit a8a907d

Please sign in to comment.