namespace Friendica\Core\Addon;
+use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Util\Profiler;
/**
{
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);
*/
public function loadAddons(): void
{
- $this->proxy->loadAddons();
+ $this->addons = array_keys(array_filter($this->config->get('addons') ?? []));
}
/**
*/
public function isAddonEnabled(string $addonId): bool
{
- return $this->proxy->isAddonEnabled($addonId);
+ return in_array($addonId, $this->addons);
}
/**
*/
public function getEnabledAddons(): array
{
- return $this->proxy->getEnabledAddons();
+ return $this->addons;
}
/**
use Friendica\Core\Addon\AddonInfo;
use Friendica\Core\Addon\AddonManagerHelper;
+use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Util\Profiler;
use PHPUnit\Framework\TestCase;
{
$addonManagerHelper = new AddonManagerHelper(
__DIR__ . '/../../../Util/addons',
+ $this->createStub(IManageConfigValues::class),
$this->createStub(Profiler::class)
);
$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'));
+ }
}