mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-03-15 21:03:34 +00:00
Compare commits
No commits in common. "b3b251bae289d474937865a7a7f6ebc5a37c4059" and "e9037ef5d70a04077e9b6de0e5d56e9b6d9f825e" have entirely different histories.
b3b251bae2
...
e9037ef5d7
5 changed files with 13 additions and 273 deletions
|
|
@ -140,7 +140,7 @@ class PlaylistItem extends Model
|
||||||
if (! $this->isMashup()) {
|
if (! $this->isMashup()) {
|
||||||
return view('trmnl-layouts.single', [
|
return view('trmnl-layouts.single', [
|
||||||
'colorDepth' => $device?->deviceModel?->color_depth,
|
'colorDepth' => $device?->deviceModel?->color_depth,
|
||||||
'deviceVariant' => $device?->deviceModel->name ?? 'og',
|
'deviceVariant' => $device?->deviceModel?->name ?? 'og',
|
||||||
'scaleLevel' => $device?->deviceModel?->scale_level,
|
'scaleLevel' => $device?->deviceModel?->scale_level,
|
||||||
'slot' => $this->plugin instanceof Plugin
|
'slot' => $this->plugin instanceof Plugin
|
||||||
? $this->plugin->render('full', false)
|
? $this->plugin->render('full', false)
|
||||||
|
|
@ -164,7 +164,7 @@ class PlaylistItem extends Model
|
||||||
|
|
||||||
return view('trmnl-layouts.mashup', [
|
return view('trmnl-layouts.mashup', [
|
||||||
'colorDepth' => $device?->deviceModel?->color_depth,
|
'colorDepth' => $device?->deviceModel?->color_depth,
|
||||||
'deviceVariant' => $device?->deviceModel->name ?? 'og',
|
'deviceVariant' => $device?->deviceModel?->name ?? 'og',
|
||||||
'scaleLevel' => $device?->deviceModel?->scale_level,
|
'scaleLevel' => $device?->deviceModel?->scale_level,
|
||||||
'mashupLayout' => $this->getMashupLayoutType(),
|
'mashupLayout' => $this->getMashupLayoutType(),
|
||||||
'slot' => implode('', $pluginMarkups),
|
'slot' => implode('', $pluginMarkups),
|
||||||
|
|
|
||||||
|
|
@ -346,7 +346,7 @@ class Plugin extends Model
|
||||||
if ($size === 'full') {
|
if ($size === 'full') {
|
||||||
return view('trmnl-layouts.single', [
|
return view('trmnl-layouts.single', [
|
||||||
'colorDepth' => $device?->deviceModel?->color_depth,
|
'colorDepth' => $device?->deviceModel?->color_depth,
|
||||||
'deviceVariant' => $device?->deviceModel->name ?? 'og',
|
'deviceVariant' => $device?->deviceModel?->name ?? 'og',
|
||||||
'scaleLevel' => $device?->deviceModel?->scale_level,
|
'scaleLevel' => $device?->deviceModel?->scale_level,
|
||||||
'slot' => $renderedContent,
|
'slot' => $renderedContent,
|
||||||
])->render();
|
])->render();
|
||||||
|
|
@ -354,7 +354,7 @@ class Plugin extends Model
|
||||||
return view('trmnl-layouts.mashup', [
|
return view('trmnl-layouts.mashup', [
|
||||||
'mashupLayout' => $this->getPreviewMashupLayoutForSize($size),
|
'mashupLayout' => $this->getPreviewMashupLayoutForSize($size),
|
||||||
'colorDepth' => $device?->deviceModel?->color_depth,
|
'colorDepth' => $device?->deviceModel?->color_depth,
|
||||||
'deviceVariant' => $device?->deviceModel->name ?? 'og',
|
'deviceVariant' => $device?->deviceModel?->name ?? 'og',
|
||||||
'scaleLevel' => $device?->deviceModel?->scale_level,
|
'scaleLevel' => $device?->deviceModel?->scale_level,
|
||||||
'slot' => $renderedContent,
|
'slot' => $renderedContent,
|
||||||
])->render();
|
])->render();
|
||||||
|
|
@ -368,7 +368,7 @@ class Plugin extends Model
|
||||||
if ($standalone) {
|
if ($standalone) {
|
||||||
return view('trmnl-layouts.single', [
|
return view('trmnl-layouts.single', [
|
||||||
'colorDepth' => $device?->deviceModel?->color_depth,
|
'colorDepth' => $device?->deviceModel?->color_depth,
|
||||||
'deviceVariant' => $device?->deviceModel->name ?? 'og',
|
'deviceVariant' => $device?->deviceModel?->name ?? 'og',
|
||||||
'scaleLevel' => $device?->deviceModel?->scale_level,
|
'scaleLevel' => $device?->deviceModel?->scale_level,
|
||||||
'slot' => view($this->render_markup_view, [
|
'slot' => view($this->render_markup_view, [
|
||||||
'size' => $size,
|
'size' => $size,
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,11 @@ class PluginImportService
|
||||||
*
|
*
|
||||||
* @param UploadedFile $zipFile The uploaded ZIP file
|
* @param UploadedFile $zipFile The uploaded ZIP file
|
||||||
* @param User $user The user importing the plugin
|
* @param User $user The user importing the plugin
|
||||||
* @param string|null $zipEntryPath Optional path to specific plugin in monorepo
|
|
||||||
* @return Plugin The created plugin instance
|
* @return Plugin The created plugin instance
|
||||||
*
|
*
|
||||||
* @throws Exception If the ZIP file is invalid or required files are missing
|
* @throws Exception If the ZIP file is invalid or required files are missing
|
||||||
*/
|
*/
|
||||||
public function importFromZip(UploadedFile $zipFile, User $user, ?string $zipEntryPath = null): Plugin
|
public function importFromZip(UploadedFile $zipFile, User $user): Plugin
|
||||||
{
|
{
|
||||||
// Create a temporary directory using Laravel's temporary directory helper
|
// Create a temporary directory using Laravel's temporary directory helper
|
||||||
$tempDirName = 'temp/'.uniqid('plugin_import_', true);
|
$tempDirName = 'temp/'.uniqid('plugin_import_', true);
|
||||||
|
|
@ -48,7 +47,7 @@ class PluginImportService
|
||||||
$zip->close();
|
$zip->close();
|
||||||
|
|
||||||
// Find the required files (settings.yml and full.liquid/full.blade.php)
|
// Find the required files (settings.yml and full.liquid/full.blade.php)
|
||||||
$filePaths = $this->findRequiredFiles($tempDir, $zipEntryPath);
|
$filePaths = $this->findRequiredFiles($tempDir);
|
||||||
|
|
||||||
// Validate that we found the required files
|
// Validate that we found the required files
|
||||||
if (! $filePaths['settingsYamlPath'] || ! $filePaths['fullLiquidPath']) {
|
if (! $filePaths['settingsYamlPath'] || ! $filePaths['fullLiquidPath']) {
|
||||||
|
|
@ -139,12 +138,11 @@ class PluginImportService
|
||||||
*
|
*
|
||||||
* @param string $zipUrl The URL to the ZIP file
|
* @param string $zipUrl The URL to the ZIP file
|
||||||
* @param User $user The user importing the plugin
|
* @param User $user The user importing the plugin
|
||||||
* @param string|null $zipEntryPath Optional path to specific plugin in monorepo
|
|
||||||
* @return Plugin The created plugin instance
|
* @return Plugin The created plugin instance
|
||||||
*
|
*
|
||||||
* @throws Exception If the ZIP file is invalid or required files are missing
|
* @throws Exception If the ZIP file is invalid or required files are missing
|
||||||
*/
|
*/
|
||||||
public function importFromUrl(string $zipUrl, User $user, ?string $zipEntryPath = null): Plugin
|
public function importFromUrl(string $zipUrl, User $user): Plugin
|
||||||
{
|
{
|
||||||
// Download the ZIP file
|
// Download the ZIP file
|
||||||
$response = Http::timeout(60)->get($zipUrl);
|
$response = Http::timeout(60)->get($zipUrl);
|
||||||
|
|
@ -173,7 +171,7 @@ class PluginImportService
|
||||||
$zip->close();
|
$zip->close();
|
||||||
|
|
||||||
// Find the required files (settings.yml and full.liquid/full.blade.php)
|
// Find the required files (settings.yml and full.liquid/full.blade.php)
|
||||||
$filePaths = $this->findRequiredFiles($tempDir, $zipEntryPath);
|
$filePaths = $this->findRequiredFiles($tempDir);
|
||||||
|
|
||||||
// Validate that we found the required files
|
// Validate that we found the required files
|
||||||
if (! $filePaths['settingsYamlPath'] || ! $filePaths['fullLiquidPath']) {
|
if (! $filePaths['settingsYamlPath'] || ! $filePaths['fullLiquidPath']) {
|
||||||
|
|
@ -259,57 +257,12 @@ class PluginImportService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function findRequiredFiles(string $tempDir, ?string $zipEntryPath = null): array
|
private function findRequiredFiles(string $tempDir): array
|
||||||
{
|
{
|
||||||
$settingsYamlPath = null;
|
$settingsYamlPath = null;
|
||||||
$fullLiquidPath = null;
|
$fullLiquidPath = null;
|
||||||
$sharedLiquidPath = null;
|
$sharedLiquidPath = null;
|
||||||
|
|
||||||
// If zipEntryPath is specified, look for files in that specific directory first
|
|
||||||
if ($zipEntryPath) {
|
|
||||||
$targetDir = $tempDir . '/' . $zipEntryPath;
|
|
||||||
if (File::exists($targetDir)) {
|
|
||||||
// Check if files are directly in the target directory
|
|
||||||
if (File::exists($targetDir . '/settings.yml')) {
|
|
||||||
$settingsYamlPath = $targetDir . '/settings.yml';
|
|
||||||
|
|
||||||
if (File::exists($targetDir . '/full.liquid')) {
|
|
||||||
$fullLiquidPath = $targetDir . '/full.liquid';
|
|
||||||
} elseif (File::exists($targetDir . '/full.blade.php')) {
|
|
||||||
$fullLiquidPath = $targetDir . '/full.blade.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (File::exists($targetDir . '/shared.liquid')) {
|
|
||||||
$sharedLiquidPath = $targetDir . '/shared.liquid';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if files are in src subdirectory of target directory
|
|
||||||
if (!$settingsYamlPath && File::exists($targetDir . '/src/settings.yml')) {
|
|
||||||
$settingsYamlPath = $targetDir . '/src/settings.yml';
|
|
||||||
|
|
||||||
if (File::exists($targetDir . '/src/full.liquid')) {
|
|
||||||
$fullLiquidPath = $targetDir . '/src/full.liquid';
|
|
||||||
} elseif (File::exists($targetDir . '/src/full.blade.php')) {
|
|
||||||
$fullLiquidPath = $targetDir . '/src/full.blade.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (File::exists($targetDir . '/src/shared.liquid')) {
|
|
||||||
$sharedLiquidPath = $targetDir . '/src/shared.liquid';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we found the required files in the target directory, return them
|
|
||||||
if ($settingsYamlPath && $fullLiquidPath) {
|
|
||||||
return [
|
|
||||||
'settingsYamlPath' => $settingsYamlPath,
|
|
||||||
'fullLiquidPath' => $fullLiquidPath,
|
|
||||||
'sharedLiquidPath' => $sharedLiquidPath,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// First, check if files are directly in the src folder
|
// First, check if files are directly in the src folder
|
||||||
if (File::exists($tempDir.'/src/settings.yml')) {
|
if (File::exists($tempDir.'/src/settings.yml')) {
|
||||||
$settingsYamlPath = $tempDir.'/src/settings.yml';
|
$settingsYamlPath = $tempDir.'/src/settings.yml';
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ new class extends Component {
|
||||||
'github' => Arr::get($plugin, 'author.github'),
|
'github' => Arr::get($plugin, 'author.github'),
|
||||||
'license' => Arr::get($plugin, 'license'),
|
'license' => Arr::get($plugin, 'license'),
|
||||||
'zip_url' => Arr::get($plugin, 'trmnlp.zip_url'),
|
'zip_url' => Arr::get($plugin, 'trmnlp.zip_url'),
|
||||||
'zip_entry_path' => Arr::get($plugin, 'trmnlp.zip_entry_path'),
|
|
||||||
'repo_url' => Arr::get($plugin, 'trmnlp.repo'),
|
'repo_url' => Arr::get($plugin, 'trmnlp.repo'),
|
||||||
'logo_url' => Arr::get($plugin, 'logo_url'),
|
'logo_url' => Arr::get($plugin, 'logo_url'),
|
||||||
'screenshot_url' => Arr::get($plugin, 'screenshot_url'),
|
'screenshot_url' => Arr::get($plugin, 'screenshot_url'),
|
||||||
|
|
@ -83,7 +82,7 @@ new class extends Component {
|
||||||
$this->installingPlugin = $pluginId;
|
$this->installingPlugin = $pluginId;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$importedPlugin = $pluginImportService->importFromUrl($plugin['zip_url'], auth()->user(), $plugin['zip_entry_path'] ?? null);
|
$importedPlugin = $pluginImportService->importFromUrl($plugin['zip_url'], auth()->user());
|
||||||
|
|
||||||
$this->dispatch('plugin-installed');
|
$this->dispatch('plugin-installed');
|
||||||
Flux::modal('import-from-catalog')->close();
|
Flux::modal('import-from-catalog')->close();
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ use App\Models\Plugin;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Services\PluginImportService;
|
use App\Services\PluginImportService;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
use Illuminate\Support\Facades\Http;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
|
|
@ -133,221 +132,11 @@ it('handles blade markup language correctly', function () {
|
||||||
expect($plugin->markup_language)->toBe('blade');
|
expect($plugin->markup_language)->toBe('blade');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('imports plugin from monorepo with zip_entry_path parameter', function () {
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
// Create a mock ZIP file with plugin in a subdirectory
|
|
||||||
$zipContent = createMockZipFile([
|
|
||||||
'example-plugin/settings.yml' => getValidSettingsYaml(),
|
|
||||||
'example-plugin/full.liquid' => getValidFullLiquid(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$zipFile = UploadedFile::fake()->createWithContent('monorepo.zip', $zipContent);
|
|
||||||
|
|
||||||
$pluginImportService = new PluginImportService();
|
|
||||||
$plugin = $pluginImportService->importFromZip($zipFile, $user);
|
|
||||||
|
|
||||||
expect($plugin)->toBeInstanceOf(Plugin::class)
|
|
||||||
->and($plugin->user_id)->toBe($user->id)
|
|
||||||
->and($plugin->name)->toBe('Test Plugin');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('imports plugin from monorepo with src subdirectory', function () {
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
// Create a mock ZIP file with plugin in a subdirectory with src folder
|
|
||||||
$zipContent = createMockZipFile([
|
|
||||||
'example-plugin/src/settings.yml' => getValidSettingsYaml(),
|
|
||||||
'example-plugin/src/full.liquid' => getValidFullLiquid(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$zipFile = UploadedFile::fake()->createWithContent('monorepo.zip', $zipContent);
|
|
||||||
|
|
||||||
$pluginImportService = new PluginImportService();
|
|
||||||
$plugin = $pluginImportService->importFromZip($zipFile, $user);
|
|
||||||
|
|
||||||
expect($plugin)->toBeInstanceOf(Plugin::class)
|
|
||||||
->and($plugin->user_id)->toBe($user->id)
|
|
||||||
->and($plugin->name)->toBe('Test Plugin');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('imports plugin from monorepo with shared.liquid in subdirectory', function () {
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
$zipContent = createMockZipFile([
|
|
||||||
'example-plugin/settings.yml' => getValidSettingsYaml(),
|
|
||||||
'example-plugin/full.liquid' => getValidFullLiquid(),
|
|
||||||
'example-plugin/shared.liquid' => '{% comment %}Monorepo shared styles{% endcomment %}',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$zipFile = UploadedFile::fake()->createWithContent('monorepo.zip', $zipContent);
|
|
||||||
|
|
||||||
$pluginImportService = new PluginImportService();
|
|
||||||
$plugin = $pluginImportService->importFromZip($zipFile, $user);
|
|
||||||
|
|
||||||
expect($plugin->render_markup)->toContain('{% comment %}Monorepo shared styles{% endcomment %}')
|
|
||||||
->and($plugin->render_markup)->toContain('<div class="view view--{{ size }}">');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('imports plugin from URL with zip_entry_path parameter', function () {
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
// Create a mock ZIP file with plugin in a subdirectory
|
|
||||||
$zipContent = createMockZipFile([
|
|
||||||
'example-plugin/settings.yml' => getValidSettingsYaml(),
|
|
||||||
'example-plugin/full.liquid' => getValidFullLiquid(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Mock the HTTP response
|
|
||||||
Http::fake([
|
|
||||||
'https://github.com/example/repo/archive/refs/heads/main.zip' => Http::response($zipContent, 200),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$pluginImportService = new PluginImportService();
|
|
||||||
$plugin = $pluginImportService->importFromUrl(
|
|
||||||
'https://github.com/example/repo/archive/refs/heads/main.zip',
|
|
||||||
$user,
|
|
||||||
'example-plugin'
|
|
||||||
);
|
|
||||||
|
|
||||||
expect($plugin)->toBeInstanceOf(Plugin::class)
|
|
||||||
->and($plugin->user_id)->toBe($user->id)
|
|
||||||
->and($plugin->name)->toBe('Test Plugin');
|
|
||||||
|
|
||||||
Http::assertSent(function ($request) {
|
|
||||||
return $request->url() === 'https://github.com/example/repo/archive/refs/heads/main.zip';
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('imports plugin from URL with zip_entry_path and src subdirectory', function () {
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
// Create a mock ZIP file with plugin in a subdirectory with src folder
|
|
||||||
$zipContent = createMockZipFile([
|
|
||||||
'example-plugin/src/settings.yml' => getValidSettingsYaml(),
|
|
||||||
'example-plugin/src/full.liquid' => getValidFullLiquid(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Mock the HTTP response
|
|
||||||
Http::fake([
|
|
||||||
'https://github.com/example/repo/archive/refs/heads/main.zip' => Http::response($zipContent, 200),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$pluginImportService = new PluginImportService();
|
|
||||||
$plugin = $pluginImportService->importFromUrl(
|
|
||||||
'https://github.com/example/repo/archive/refs/heads/main.zip',
|
|
||||||
$user,
|
|
||||||
'example-plugin'
|
|
||||||
);
|
|
||||||
|
|
||||||
expect($plugin)->toBeInstanceOf(Plugin::class)
|
|
||||||
->and($plugin->user_id)->toBe($user->id)
|
|
||||||
->and($plugin->name)->toBe('Test Plugin');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('imports plugin from GitHub monorepo with repository-named directory', function () {
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
// Create a mock ZIP file that simulates GitHub's ZIP structure with repository-named directory
|
|
||||||
$zipContent = createMockZipFile([
|
|
||||||
'example-repo-main/another-plugin/src/settings.yml' => "name: Other Plugin\nrefresh_interval: 60\nstrategy: static\npolling_verb: get\nstatic_data: '{}'\ncustom_fields: []",
|
|
||||||
'example-repo-main/another-plugin/src/full.liquid' => '<div>Other content</div>',
|
|
||||||
'example-repo-main/example-plugin/src/settings.yml' => getValidSettingsYaml(),
|
|
||||||
'example-repo-main/example-plugin/src/full.liquid' => getValidFullLiquid(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Mock the HTTP response
|
|
||||||
Http::fake([
|
|
||||||
'https://github.com/example/repo/archive/refs/heads/main.zip' => Http::response($zipContent, 200),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$pluginImportService = new PluginImportService();
|
|
||||||
$plugin = $pluginImportService->importFromUrl(
|
|
||||||
'https://github.com/example/repo/archive/refs/heads/main.zip',
|
|
||||||
$user,
|
|
||||||
'example-repo-main/example-plugin'
|
|
||||||
);
|
|
||||||
|
|
||||||
expect($plugin)->toBeInstanceOf(Plugin::class)
|
|
||||||
->and($plugin->user_id)->toBe($user->id)
|
|
||||||
->and($plugin->name)->toBe('Test Plugin'); // Should be from example-plugin, not other-plugin
|
|
||||||
});
|
|
||||||
|
|
||||||
it('finds required files in simple ZIP structure', function () {
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
// Create a simple ZIP file with just one plugin
|
|
||||||
$zipContent = createMockZipFile([
|
|
||||||
'example-repo-main/example-plugin/src/settings.yml' => getValidSettingsYaml(),
|
|
||||||
'example-repo-main/example-plugin/src/full.liquid' => getValidFullLiquid(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$zipFile = UploadedFile::fake()->createWithContent('simple.zip', $zipContent);
|
|
||||||
|
|
||||||
$pluginImportService = new PluginImportService();
|
|
||||||
$plugin = $pluginImportService->importFromZip($zipFile, $user);
|
|
||||||
|
|
||||||
expect($plugin)->toBeInstanceOf(Plugin::class)
|
|
||||||
->and($plugin->user_id)->toBe($user->id)
|
|
||||||
->and($plugin->name)->toBe('Test Plugin');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('finds required files in GitHub monorepo structure with zip_entry_path', function () {
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
// Create a mock ZIP file that simulates GitHub's ZIP structure
|
|
||||||
$zipContent = createMockZipFile([
|
|
||||||
'example-repo-main/example-plugin/src/settings.yml' => getValidSettingsYaml(),
|
|
||||||
'example-repo-main/example-plugin/src/full.liquid' => getValidFullLiquid(),
|
|
||||||
'example-repo-main/other-plugin/src/settings.yml' => "name: Other Plugin\nrefresh_interval: 60\nstrategy: static\npolling_verb: get\nstatic_data: '{}'\ncustom_fields: []",
|
|
||||||
'example-repo-main/other-plugin/src/full.liquid' => '<div>Other content</div>',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$zipFile = UploadedFile::fake()->createWithContent('monorepo.zip', $zipContent);
|
|
||||||
|
|
||||||
$pluginImportService = new PluginImportService();
|
|
||||||
$plugin = $pluginImportService->importFromZip($zipFile, $user, 'example-repo-main/example-plugin');
|
|
||||||
|
|
||||||
expect($plugin)->toBeInstanceOf(Plugin::class)
|
|
||||||
->and($plugin->user_id)->toBe($user->id)
|
|
||||||
->and($plugin->name)->toBe('Test Plugin'); // Should be from example-plugin, not other-plugin
|
|
||||||
});
|
|
||||||
|
|
||||||
it('imports specific plugin from monorepo zip with zip_entry_path parameter', function () {
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
// Create a mock ZIP file with 2 plugins in a monorepo structure
|
|
||||||
$zipContent = createMockZipFile([
|
|
||||||
'example-plugin/settings.yml' => getValidSettingsYaml(),
|
|
||||||
'example-plugin/full.liquid' => getValidFullLiquid(),
|
|
||||||
'example-plugin/shared.liquid' => '{% comment %}Monorepo shared styles{% endcomment %}',
|
|
||||||
'example-plugin2/settings.yml' => "name: Example Plugin 2\nrefresh_interval: 45\nstrategy: static\npolling_verb: get\nstatic_data: '{}'\ncustom_fields: []",
|
|
||||||
'example-plugin2/full.liquid' => '<div class="plugin2-content">Plugin 2 content</div>',
|
|
||||||
'example-plugin2/shared.liquid' => '{% comment %}Plugin 2 shared styles{% endcomment %}',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$zipFile = UploadedFile::fake()->createWithContent('monorepo.zip', $zipContent);
|
|
||||||
|
|
||||||
$pluginImportService = new PluginImportService();
|
|
||||||
|
|
||||||
// This test will fail because importFromZip doesn't support zip_entry_path parameter yet
|
|
||||||
// The logic needs to be implemented to specify which plugin to import from the monorepo
|
|
||||||
$plugin = $pluginImportService->importFromZip($zipFile, $user, 'example-plugin2');
|
|
||||||
|
|
||||||
expect($plugin)->toBeInstanceOf(Plugin::class)
|
|
||||||
->and($plugin->user_id)->toBe($user->id)
|
|
||||||
->and($plugin->name)->toBe('Example Plugin 2') // Should import example-plugin2, not example-plugin
|
|
||||||
->and($plugin->render_markup)->toContain('{% comment %}Plugin 2 shared styles{% endcomment %}')
|
|
||||||
->and($plugin->render_markup)->toContain('<div class="plugin2-content">Plugin 2 content</div>');
|
|
||||||
});
|
|
||||||
|
|
||||||
// Helper methods
|
// Helper methods
|
||||||
function createMockZipFile(array $files): string
|
function createMockZipFile(array $files): string
|
||||||
{
|
{
|
||||||
$zip = new ZipArchive();
|
$zip = new ZipArchive();
|
||||||
|
$tempFile = tempnam(sys_get_temp_dir(), 'test_zip_');
|
||||||
$tempFileName = 'test_zip_'.uniqid().'.zip';
|
|
||||||
$tempFile = Storage::path($tempFileName);
|
|
||||||
|
|
||||||
$zip->open($tempFile, ZipArchive::CREATE);
|
$zip->open($tempFile, ZipArchive::CREATE);
|
||||||
|
|
||||||
|
|
@ -358,8 +147,7 @@ function createMockZipFile(array $files): string
|
||||||
$zip->close();
|
$zip->close();
|
||||||
|
|
||||||
$content = file_get_contents($tempFile);
|
$content = file_get_contents($tempFile);
|
||||||
|
unlink($tempFile);
|
||||||
Storage::delete($tempFileName);
|
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue