From 252fd41c1fce4935fcbd2a080b5d3df3666466ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Fri, 18 Oct 2024 11:09:01 +0900 Subject: [PATCH] =?UTF-8?q?InstallationsService::installPlugin()=20?= =?UTF-8?q?=E3=81=AE=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Service/InstallationsService.php | 5 ++++- .../TestCase/Service/InstallationsServiceTest.php | 12 +++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/bc-installer/src/Service/InstallationsService.php b/plugins/bc-installer/src/Service/InstallationsService.php index d7e076edc2..6e2f202605 100644 --- a/plugins/bc-installer/src/Service/InstallationsService.php +++ b/plugins/bc-installer/src/Service/InstallationsService.php @@ -380,13 +380,16 @@ public function installCorePlugin(): bool * @return boolean * @checked * @noTodo + * @unitTest */ public function installPlugin($name) { BcUtil::clearAllCache(); /* @var BcPlugin $plugin */ $plugin = Plugin::isLoaded($name); - if(!$plugin) $plugin = Plugin::getCollection()->create($name); + if ($plugin) + return true; + $plugin = Plugin::getCollection()->create($name); return $plugin->install(); } diff --git a/plugins/bc-installer/tests/TestCase/Service/InstallationsServiceTest.php b/plugins/bc-installer/tests/TestCase/Service/InstallationsServiceTest.php index 6ea99e31fd..9916b7ae2c 100644 --- a/plugins/bc-installer/tests/TestCase/Service/InstallationsServiceTest.php +++ b/plugins/bc-installer/tests/TestCase/Service/InstallationsServiceTest.php @@ -22,6 +22,7 @@ use BcInstaller\Service\InstallationsService; use BcInstaller\Service\InstallationsServiceInterface; use Cake\Core\Configure; +use Cake\Core\Exception\MissingPluginException; use Cake\ORM\Exception\PersistenceFailedException; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; @@ -304,7 +305,16 @@ public function testInstallCorePlugin() */ public function testInstallPlugin() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + //プラグインがすでにインストールした場合、 + $this->assertTrue($this->Installations->installPlugin('BcBlog')); + + //プラグインがインストールしない場合、 + $this->assertTrue($this->Installations->installPlugin('BcPluginSample')); + + //存在しないプラグイン + $this->expectException(MissingPluginException::class); + $this->expectExceptionMessage('Plugin `BcPluginSampleTest` could not be found.'); + $this->Installations->installPlugin('BcPluginSampleTest'); } /**