Skip to content

Commit

Permalink
Merge pull request #3931 from HungDV2022/unitest_InstallationsService…
Browse files Browse the repository at this point in the history
…_executeDefaultUpdates

InstallationsService::executeDefaultUpdatesの ユニットテスト
  • Loading branch information
HungDV2022 authored Oct 29, 2024
2 parents 8db4fb9 + ea7979c commit bd695c2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 52 deletions.
1 change: 1 addition & 0 deletions plugins/bc-installer/src/Service/InstallationsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ public function setSiteName(string $name)
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function executeDefaultUpdates(): bool
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use BaserCore\Utility\BcFile;
use BaserCore\Utility\BcFolder;
use BcInstaller\Service\InstallationsService;
use BcInstaller\Service\InstallationsServiceInterface;
use BcSearchIndex\Test\Scenario\Service\SearchIndexesServiceScenario;
use Cake\Core\Configure;
use Cake\ORM\Exception\PersistenceFailedException;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;
Expand Down Expand Up @@ -302,57 +302,15 @@ public function test_deployAdminAssets()
*/
public function testExecuteDefaultUpdates()
{
$this->markTestIncomplete('このテストは未実装です。BcManagerComponentから移植中です。');
$dbConfig = [
'datasource' => 'Database/BcMysql',
'persistent' => false,
'host' => 'localhost',
'port' => '8889',
'login' => 'root',
'password' => 'root',
'database' => 'basercms',
'schema' => '',
'prefix' => 'mysite_',
'encoding' => 'utf8',
];

// プラグイン有効化チェック用準備(ダミーのプラグインディレクトリを作成)
$testPluginPath = BASER_PLUGINS . 'Test' . DS;
$testPluginConfigPath = $testPluginPath . 'config.php';
$Folder = new BcFolder($testPluginPath);
$Folder->create();
$File = new BcFile($testPluginConfigPath);
$File->write('<?php $title = "テスト";');

Configure::write('BcApp.corePlugins', ['BcBlog', 'BcFeed', 'BcMail', 'Test']);


// 初期更新を実行
$result = $this->BcManager->executeDefaultUpdates($dbConfig);


// =====================
// プラグイン有効化チェック
// =====================
$File->delete();
$Folder->delete($testPluginPath);

$this->Plugin = ClassRegistry::init('Plugin');
$plugin = $this->Plugin->find('first', [
'conditions' => ['id' => 4],
'fields' => ['title', 'status'],
]
);
$expected = [
'Plugin' => [
'title' => 'テスト',
'status' => 1,
]
];
$this->Plugin->delete(4);
unset($this->Plugin);
$this->assertEquals($expected, $plugin, 'プラグインのステータスを正しく更新できません');
$this->assertTrue($result, 'データベースのデータに初期更新に失敗しました');
//準備
$this->loadFixtureScenario(SearchIndexesServiceScenario::class);
$searchIndexesTable = $this->getTableLocator()->get('SearchIndexes');
//テスト前、search_indexes テーブルにデータを確認
$this->assertEquals(1, $searchIndexesTable->find()->count());
//テストを実行
$this->assertTrue($this->Installations->executeDefaultUpdates());
//テスト後、search_indexes テーブルにデータを確認
$this->assertEquals(3, $searchIndexesTable->find()->count());
}

/**
Expand Down

0 comments on commit bd695c2

Please sign in to comment.