Implement loading addons in AddonManagerHelper

This commit is contained in:
Art4 2025-05-13 14:04:57 +00:00
parent e2a2cf5d6e
commit 93a171765a
2 changed files with 38 additions and 3 deletions

View file

@ -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;
}
/**

View file

@ -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'));
}
}