createStub(IManageConfigValues::class), $this->createStub(LoggerInterface::class), $this->createStub(Profiler::class) ); $info = $addonManagerHelper->getAddonInfo('helloaddon'); $this->assertInstanceOf(AddonInfo::class, $info); $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(LoggerInterface::class), $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')); } public function testGetVisibleEnabledAddons(): 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(LoggerInterface::class), $this->createStub(Profiler::class) ); $this->assertSame(['helloaddon'], $addonManagerHelper->getVisibleEnabledAddons()); } public function testGetEnabledAddonsWithAdminSettings(): void { $config = $this->createStub(IManageConfigValues::class); $config->method('get')->willReturn([ 'helloaddon' => [ 'last_update' => 1738760499, 'admin' => false, ], 'addonwithadminsettings' => [ 'last_update' => 1738760499, 'admin' => true, ], ]); $addonManagerHelper = new AddonManagerHelper( __DIR__ . '/../../../Util/addons', $config, $this->createStub(LoggerInterface::class), $this->createStub(Profiler::class) ); $this->assertSame(['addonwithadminsettings'], $addonManagerHelper->getEnabledAddonsWithAdminSettings()); } public function testGetAvailableAddons(): void { $addonManagerHelper = new AddonManagerHelper( __DIR__ . '/../../../Util/addons', $this->createStub(IManageConfigValues::class), $this->createStub(LoggerInterface::class), $this->createStub(Profiler::class) ); $this->assertSame(['helloaddon'], $addonManagerHelper->getAvailableAddons()); } public function testInstallAddonIncludesAddonFile(): void { $root = vfsStream::setup(__FUNCTION__ . '_addons', 0777, [ 'helloaddon' => [ 'helloaddon.php' => 'url(), $this->createStub(IManageConfigValues::class), $this->createStub(LoggerInterface::class), $this->createStub(Profiler::class) ); $this->expectException(Exception::class); $this->expectExceptionMessage('Addon file loaded'); $addonManagerHelper->installAddon('helloaddon'); } public function testInstallAddonCallsInstallFunction(): void { // We need a unique name for the addon to avoid conflicts // with other tests that may define the same install function. $addonName = __FUNCTION__; $root = vfsStream::setup(__FUNCTION__ . '_addons', 0777, [ $addonName => [ $addonName . '.php' => <<url(), $this->createStub(IManageConfigValues::class), $this->createStub(LoggerInterface::class), $this->createStub(Profiler::class) ); $this->expectException(Exception::class); $this->expectExceptionMessage('Addon installed'); $addonManagerHelper->installAddon($addonName); } public function testInstallAddonUpdatesConfig(): void { $root = vfsStream::setup(__FUNCTION__ . '_addons', 0777, [ 'helloaddon' => [ 'helloaddon.php' => 'getChild('helloaddon/helloaddon.php')->lastModified(1234567890); $config = $this->createMock(IManageConfigValues::class); $config->expects($this->once())->method('set')->with( 'addons', 'helloaddon', ['last_update' => 1234567890, 'admin' => false] ); $addonManagerHelper = new AddonManagerHelper( $root->url(), $config, $this->createStub(LoggerInterface::class), $this->createStub(Profiler::class) ); $addonManagerHelper->installAddon('helloaddon'); } public function testInstallAddonEnablesAddon(): void { $root = vfsStream::setup(__FUNCTION__ . '_addons', 0777, [ 'helloaddon' => [ 'helloaddon.php' => 'url(), $this->createStub(IManageConfigValues::class), $this->createStub(LoggerInterface::class), $this->createStub(Profiler::class) ); $this->assertSame([], $addonManagerHelper->getEnabledAddons()); $this->assertTrue($addonManagerHelper->installAddon('helloaddon')); $this->assertSame(['helloaddon'], $addonManagerHelper->getEnabledAddons()); } }