From: Art4 Date: Tue, 13 May 2025 14:04:57 +0000 (+0000) Subject: Implement loading addons in AddonManagerHelper X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=93a171765abe1c25813efd665bad6215fd711201;p=friendica.git Implement loading addons in AddonManagerHelper --- diff --git a/src/Core/Addon/AddonManagerHelper.php b/src/Core/Addon/AddonManagerHelper.php index 1672be1de2..294f44d85b 100644 --- a/src/Core/Addon/AddonManagerHelper.php +++ b/src/Core/Addon/AddonManagerHelper.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace Friendica\Core\Addon; +use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Util\Profiler; /** @@ -20,16 +21,23 @@ final class AddonManagerHelper implements AddonHelper { private string $addonPath; + private IManageConfigValues $config; + private Profiler $profiler; + /** @var string[] */ + private array $addons = []; + /** @deprecated */ private AddonHelper $proxy; public function __construct( string $addonPath, + IManageConfigValues $config, Profiler $profiler ) { $this->addonPath = $addonPath; + $this->config = $config; $this->profiler = $profiler; $this->proxy = new AddonProxy($addonPath); @@ -86,7 +94,7 @@ final class AddonManagerHelper implements AddonHelper */ public function loadAddons(): void { - $this->proxy->loadAddons(); + $this->addons = array_keys(array_filter($this->config->get('addons') ?? [])); } /** @@ -125,7 +133,7 @@ final class AddonManagerHelper implements AddonHelper */ public function isAddonEnabled(string $addonId): bool { - return $this->proxy->isAddonEnabled($addonId); + return in_array($addonId, $this->addons); } /** @@ -135,7 +143,7 @@ final class AddonManagerHelper implements AddonHelper */ public function getEnabledAddons(): array { - return $this->proxy->getEnabledAddons(); + return $this->addons; } /** diff --git a/tests/Unit/Core/Addon/AddonManagerHelperTest.php b/tests/Unit/Core/Addon/AddonManagerHelperTest.php index 9ee8bde3c8..9afdbb0cfd 100644 --- a/tests/Unit/Core/Addon/AddonManagerHelperTest.php +++ b/tests/Unit/Core/Addon/AddonManagerHelperTest.php @@ -11,6 +11,7 @@ namespace Friendica\Test\Unit\Core\Addon; use Friendica\Core\Addon\AddonInfo; use Friendica\Core\Addon\AddonManagerHelper; +use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Util\Profiler; use PHPUnit\Framework\TestCase; @@ -20,6 +21,7 @@ class AddonManagerHelperTest extends TestCase { $addonManagerHelper = new AddonManagerHelper( __DIR__ . '/../../../Util/addons', + $this->createStub(IManageConfigValues::class), $this->createStub(Profiler::class) ); @@ -29,4 +31,29 @@ class AddonManagerHelperTest extends TestCase $this->assertEquals('Hello Addon', $info->getName()); } + + public function testEnabledAddons(): void + { + $config = $this->createStub(IManageConfigValues::class); + $config->method('get')->willReturn([ + 'helloaddon' => [ + 'last_update' => 1738760499, + 'admin' => false, + ], + ]); + + $addonManagerHelper = new AddonManagerHelper( + __DIR__ . '/../../../Util/addons', + $config, + $this->createStub(Profiler::class) + ); + + $this->assertSame([], $addonManagerHelper->getEnabledAddons()); + $this->assertFalse($addonManagerHelper->isAddonEnabled('helloaddon')); + + $addonManagerHelper->loadAddons(); + + $this->assertSame(['helloaddon'], $addonManagerHelper->getEnabledAddons()); + $this->assertTrue($addonManagerHelper->isAddonEnabled('helloaddon')); + } }