This commit is contained in:
Pig Fang 2019-08-15 17:08:25 +08:00
parent 560ed2c2fd
commit f117a4f3c7
2 changed files with 23 additions and 2 deletions

View File

@ -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.');

View File

@ -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')
);
}
}