diff --git a/app/helpers.php b/app/helpers.php index e029c050..5109c4c9 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -32,9 +32,10 @@ if (! function_exists('plugin')) { } if (! function_exists('plugin_assets')) { - function plugin_assets(string $id, string $relativeUri): string + function plugin_assets(string $name, string $relativeUri): string { - if ($plugin = plugin($id)) { + $plugin = plugin($name); + if ($plugin) { return $plugin->assets($relativeUri); } else { throw new InvalidArgumentException('No such plugin.'); diff --git a/tests/ServicesTest/PluginManagerTest.php b/tests/ServicesTest/PluginManagerTest.php index c4976cd9..df3825a1 100644 --- a/tests/ServicesTest/PluginManagerTest.php +++ b/tests/ServicesTest/PluginManagerTest.php @@ -449,4 +449,24 @@ class PluginManagerTest extends TestCase $this->assertCount(0, json_decode(resolve(\App\Services\Option::class)->get('plugins_enabled'), true)); $this->assertTrue($manager->all()->isEmpty()); } + + public function testHelpers() + { + $manager = app('plugins'); + $reflection = new ReflectionClass($manager); + $property = $reflection->getProperty('plugins'); + $property->setAccessible(true); + $property->setValue($manager, collect(['fake' => new Plugin('', ['name' => 'fake', 'version' => '1'])])); + + $this->assertNull(plugin('nope')); + $this->assertInstanceOf(Plugin::class, plugin('fake')); + + $this->expectExceptionMessage('No such plugin.'); + plugin_assets('nope', 'relative'); + + $this->assertEquals( + url('plugins').'/fake/assets/relative?v=1', + plugin_assets('fake', 'relative') + ); + } }