Implement getAddonDependencyConfig

This commit is contained in:
Art4 2025-05-15 12:37:57 +00:00
parent 638496e553
commit 694893e2bb
3 changed files with 113 additions and 0 deletions

View file

@ -12,6 +12,7 @@ namespace Friendica\Test\Unit\Core\Addon;
use Exception;
use Friendica\Core\Addon\AddonInfo;
use Friendica\Core\Addon\AddonManagerHelper;
use Friendica\Core\Addon\Exception\AddonInvalidConfigFileException;
use Friendica\Core\Cache\Capability\ICanCache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Database\Database;
@ -54,6 +55,76 @@ class AddonManagerHelperTest extends TestCase
$this->assertEquals('Hello Addon', $info->getName());
}
public function testGetAddonDependencyConfigReturnsArray(): void
{
$root = vfsStream::setup(__FUNCTION__ . '_addons', 0777, [
'helloaddon' => [
'static' => [
'dependencies.config.php' => <<<PHP
<?php
return [
'foo' => 'bar',
];
PHP,
],
]
]);
$addonManagerHelper = new AddonManagerHelper(
$root->url(),
$this->createStub(Database::class),
$this->createStub(IManageConfigValues::class),
$this->createStub(ICanCache::class),
$this->createStub(LoggerInterface::class),
$this->createStub(Profiler::class)
);
$this->assertSame(['foo' => 'bar'], $addonManagerHelper->getAddonDependencyConfig('helloaddon'));
}
public function testGetAddonDependencyConfigWithoutConfigFileReturnsEmptyArray(): void
{
$root = vfsStream::setup(__FUNCTION__ . '_addons', 0777, [
'helloaddon' => []
]);
$addonManagerHelper = new AddonManagerHelper(
$root->url(),
$this->createStub(Database::class),
$this->createStub(IManageConfigValues::class),
$this->createStub(ICanCache::class),
$this->createStub(LoggerInterface::class),
$this->createStub(Profiler::class)
);
$this->assertSame([], $addonManagerHelper->getAddonDependencyConfig('helloaddon'));
}
public function testGetAddonDependencyConfigWithoutReturningAnArrayThrowsException(): void
{
$root = vfsStream::setup(__FUNCTION__ . '_addons', 0777, [
'helloaddon' => [
'static' => [
'dependencies.config.php' => '<?php return null;',
],
]
]);
$addonManagerHelper = new AddonManagerHelper(
$root->url(),
$this->createStub(Database::class),
$this->createStub(IManageConfigValues::class),
$this->createStub(ICanCache::class),
$this->createStub(LoggerInterface::class),
$this->createStub(Profiler::class)
);
$this->expectException(AddonInvalidConfigFileException::class);
$this->expectExceptionMessageMatches('^#Error loading config file .+/helloaddon/static/dependencies\.config\.php#$');
$addonManagerHelper->getAddonDependencyConfig('helloaddon');
}
public function testEnabledAddons(): void
{
$config = $this->createStub(IManageConfigValues::class);