Plugin-SDK: Oberflächen für Kunden-Plugins, Generator, Doku (0.20.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m46s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m49s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m7s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m8s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m51s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m12s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m11s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m33s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m46s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m49s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m7s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m8s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m51s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m12s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m11s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m33s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
46b7b05f94
commit
ea2200cb3e
353 changed files with 2151 additions and 1542 deletions
164
tests/Feature/Plugins/PluginSdkTest.php
Normal file
164
tests/Feature/Plugins/PluginSdkTest.php
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Plugins;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Plugins\PluginAssets;
|
||||
use App\Plugins\PluginManager;
|
||||
use App\Plugins\PluginState;
|
||||
use App\Support\Update\Filesystem;
|
||||
use App\Version;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PluginSdkTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private string $dir;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->dir = sys_get_temp_dir().'/inhaus-sdk-'.bin2hex(random_bytes(4));
|
||||
mkdir($this->dir.'/core', 0777, true);
|
||||
mkdir($this->dir.'/custom', 0777, true);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Filesystem::deleteDirectory($this->dir);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Kunden-Plugin mit vorkompilierter Oberfläche unter dist/.
|
||||
*/
|
||||
private function makeUiPlugin(string $slug, string $base = 'custom'): string
|
||||
{
|
||||
$namespace = 'SdkTest'.bin2hex(random_bytes(3));
|
||||
$path = "{$this->dir}/{$base}/{$slug}";
|
||||
mkdir("{$path}/src", 0777, true);
|
||||
mkdir("{$path}/dist/pages", 0777, true);
|
||||
|
||||
file_put_contents("{$path}/plugin.json", json_encode([
|
||||
'slug' => $slug, 'name' => 'SDK-Test', 'version' => '1.2.3',
|
||||
'namespace' => "{$namespace}\\", 'class' => "{$namespace}\\Plugin",
|
||||
]));
|
||||
file_put_contents("{$path}/src/Plugin.php", "<?php\nnamespace {$namespace};\nclass Plugin extends \\App\\Plugins\\Plugin {}\n");
|
||||
file_put_contents("{$path}/dist/inhaus.json", json_encode([
|
||||
'components' => ['pages/Index' => 'pages/Index.js', 'widgets/Böse' => '../../.env'],
|
||||
'css' => ['style.css'],
|
||||
]));
|
||||
file_put_contents("{$path}/dist/pages/Index.js", 'export default {};');
|
||||
file_put_contents("{$path}/dist/style.css", '.ih\:grid{display:grid}');
|
||||
file_put_contents("{$path}/dist/geheim.php", '<?php echo 1;');
|
||||
file_put_contents("{$path}/plugin-geheim.js", 'außerhalb von dist');
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
private function boot(string ...$enabled): PluginManager
|
||||
{
|
||||
$state = new PluginState($this->dir.'/state.json');
|
||||
|
||||
foreach ($enabled as $slug) {
|
||||
$state->setEnabled($slug, true);
|
||||
}
|
||||
|
||||
$manager = new PluginManager($this->app, $state, $this->dir.'/core', $this->dir.'/custom');
|
||||
$manager->registerAll();
|
||||
$manager->bootAll();
|
||||
|
||||
$this->app->instance(PluginManager::class, $manager);
|
||||
$this->app->instance(PluginAssets::class, new PluginAssets($manager));
|
||||
|
||||
return $manager;
|
||||
}
|
||||
|
||||
public function test_active_customer_plugins_expose_their_components(): void
|
||||
{
|
||||
$this->makeUiPlugin('mit-ui');
|
||||
$this->makeUiPlugin('inaktiv');
|
||||
$this->makeUiPlugin('kern-ui', 'core');
|
||||
$this->boot('mit-ui');
|
||||
|
||||
$assets = app(PluginAssets::class)->forFrontend();
|
||||
|
||||
$this->assertSame(['mit-ui'], array_keys($assets));
|
||||
$this->assertSame('/plugin-assets/mit-ui/1.2.3/', $assets['mit-ui']['base']);
|
||||
$this->assertSame(['pages/Index' => 'pages/Index.js'], $assets['mit-ui']['components']);
|
||||
$this->assertSame(['style.css'], $assets['mit-ui']['css']);
|
||||
}
|
||||
|
||||
public function test_asset_route_serves_only_whitelisted_files_from_dist(): void
|
||||
{
|
||||
$this->makeUiPlugin('mit-ui');
|
||||
$this->makeUiPlugin('inaktiv');
|
||||
$this->boot('mit-ui');
|
||||
|
||||
$response = $this->get('/plugin-assets/mit-ui/1.2.3/pages/Index.js');
|
||||
$response->assertOk();
|
||||
$this->assertStringStartsWith('text/javascript', $response->headers->get('Content-Type'));
|
||||
$this->assertStringContainsString('immutable', $response->headers->get('Cache-Control'));
|
||||
$this->assertSame('nosniff', $response->headers->get('X-Content-Type-Options'));
|
||||
|
||||
$this->get('/plugin-assets/mit-ui/1.2.3/style.css')->assertOk();
|
||||
$this->get('/plugin-assets/mit-ui/1.2.3/geheim.php')->assertNotFound();
|
||||
$this->get('/plugin-assets/mit-ui/1.2.3/../plugin-geheim.js')->assertNotFound();
|
||||
$this->get('/plugin-assets/mit-ui/1.2.3/fehlt.js')->assertNotFound();
|
||||
$this->get('/plugin-assets/inaktiv/1.2.3/pages/Index.js')->assertNotFound();
|
||||
|
||||
$this->assertNull(app(PluginAssets::class)->file('mit-ui', '../plugin-geheim.js'));
|
||||
}
|
||||
|
||||
public function test_pages_carry_import_map_and_plugin_manifest(): void
|
||||
{
|
||||
$this->makeUiPlugin('mit-ui');
|
||||
$this->boot('mit-ui');
|
||||
|
||||
$html = $this->actingAs(User::factory()->create())->get('/')->assertOk()->getContent();
|
||||
|
||||
$this->assertStringContainsString('<script type="importmap">', $html);
|
||||
$this->assertStringContainsString('/sdk/ui.js?v='.Version::VERSION, $html);
|
||||
$this->assertStringContainsString('window.__inhausPlugins', $html);
|
||||
$this->assertStringContainsString('/plugin-assets/mit-ui/1.2.3/style.css', $html);
|
||||
}
|
||||
|
||||
public function test_sdk_shims_are_built_for_every_shared_module(): void
|
||||
{
|
||||
foreach (['vue' => 'ref', 'inertia' => 'router', 'ui' => 'Panel'] as $file => $export) {
|
||||
$shim = (string) file_get_contents(public_path("sdk/{$file}.js"));
|
||||
$this->assertStringContainsString('window.__inhaus.modules', $shim);
|
||||
$this->assertMatchesRegularExpression('/\b'.$export.'\b/', $shim);
|
||||
}
|
||||
|
||||
$this->assertStringContainsString('prefix(ih)', (string) file_get_contents(base_path('sdk/theme.css')));
|
||||
}
|
||||
|
||||
public function test_generator_creates_a_loadable_plugin(): void
|
||||
{
|
||||
$target = $this->dir.'/custom/mav-kalender';
|
||||
|
||||
$this->artisan('inhaus:make-plugin', ['slug' => 'mav-kalender', '--name' => 'MAV-Kalender', '--author' => 'MAV', '--path' => $target])
|
||||
->assertSuccessful();
|
||||
|
||||
foreach (['plugin.json', 'src/MavKalenderPlugin.php', 'resources/js/pages/Index.vue', 'resources/js/widgets/Hello.vue',
|
||||
'vite.config.js', 'package.json', 'bin/package', 'inhaus-sdk/vite.js', 'inhaus-sdk/theme.css'] as $file) {
|
||||
$this->assertFileExists("{$target}/{$file}");
|
||||
}
|
||||
|
||||
$manifest = json_decode((string) file_get_contents("{$target}/plugin.json"), true);
|
||||
$this->assertSame('MAV-Kalender', $manifest['name']);
|
||||
$this->assertSame('Inhaus\\Plugins\\MavKalender\\', $manifest['namespace']);
|
||||
$this->assertStringNotContainsString('{{', (string) file_get_contents("{$target}/package.json"));
|
||||
|
||||
$manager = $this->boot('mav-kalender');
|
||||
$this->assertSame(['mav-kalender'], array_keys($manager->loaded()), (string) $manager->problem('mav-kalender'));
|
||||
|
||||
$this->artisan('inhaus:make-plugin', ['slug' => 'mav-kalender', '--path' => $target])->assertFailed();
|
||||
$this->artisan('inhaus:make-plugin', ['slug' => 'Böse Sache', '--path' => $this->dir.'/x'])->assertFailed();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue