Let AddonHelper::getAddonInfo() throw exception on invalid addons

This commit is contained in:
Art4 2025-06-04 09:26:38 +00:00
parent ab3e54f0e1
commit f1143105d2
8 changed files with 106 additions and 18 deletions

View file

@ -30,8 +30,7 @@ class AddonInfoTest extends TestCase
'without-author' => [
'test',
<<<TEXT
<?php
/*
/**
* Name: Test Addon
* Description: adds awesome features to friendica
* Version: 100.4.50-beta.5
@ -55,7 +54,6 @@ class AddonInfoTest extends TestCase
'without-maintainer' => [
'test',
<<<TEXT
<?php
/*
* Name: Test Addon
* Description: adds awesome features to friendica
@ -79,7 +77,6 @@ class AddonInfoTest extends TestCase
'complete' => [
'test',
<<<TEXT
<?php
/*
* Name: Test Addon
* Description: adds awesome features to friendica

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\InvalidAddonException;
use Friendica\Core\Cache\Capability\ICanCache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Database\Database;
@ -54,6 +55,32 @@ class AddonManagerHelperTest extends TestCase
$this->assertEquals('Hello Addon', $info->getName());
}
public function testGetAddonInfoThrowsInvalidAddonException(): void
{
$root = vfsStream::setup(__FUNCTION__ . '_addons', 0777, [
'helloaddon' => [
'helloaddon.php' => <<<PHP
<?php
// This is not a valid addon comment section
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->expectException(InvalidAddonException::class);
$this->expectExceptionMessage('Could not find valid comment block in addon file:');
$addonManagerHelper->getAddonInfo('helloaddon');
}
public function testEnabledAddons(): void
{
$config = $this->createStub(IManageConfigValues::class);
@ -140,7 +167,18 @@ class AddonManagerHelperTest extends TestCase
{
$root = vfsStream::setup(__FUNCTION__ . '_addons', 0777, [
'helloaddon' => [
'helloaddon.php' => '<?php',
'helloaddon.php' => <<<PHP
<?php
/**
* Name: Hello Addon
* Description: For testing purpose only
* Version: 1.0
* Author: Artur Weigandt <dont-mail-me@example.com>
*/
PHP,
],
'invalidaddon' => [
'invalidaddon.php' => 'This addon should not be loaded, because it does not contain a valid comment section.',
],
'.hidden' => [
'.hidden.php' => 'This folder should be ignored',