92 lines
6.3 KiB
PHP
92 lines
6.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Prüft die Plugin-Webseite: WordPress-Plugin und Chrome-Erweiterung als Apps (Version aus dem Paket, Auslieferung) und dass das
|
|
* Vorschaubild eines Plugins bei neuen Versionen erhalten bleibt, auch wenn die alte Version vorher entfernt wurde.
|
|
*/
|
|
|
|
if (!class_exists('ZipArchive')) { echo "Plugin-Webseite (Apps): übersprungen, PHP-ZIP fehlt.\n"; exit(0); }
|
|
|
|
$tmp = sys_get_temp_dir() . '/deskhub-site-apps-' . bin2hex(random_bytes(4));
|
|
mkdir($tmp . '/storage', 0755, true);
|
|
putenv('PLUGIN_SITE_CONFIG=' . $tmp . '/gibtesnicht.php');
|
|
putenv('PLUGIN_SITE_STORAGE=' . $tmp . '/storage');
|
|
putenv('PLUGIN_SITE_BASE_URL=https://plugins.example.test');
|
|
putenv('PLUGIN_SITE_TESTING=1');
|
|
|
|
require_once __DIR__ . '/fixtures/paths.php';
|
|
$siteDir = website_dir_or_skip('plugin_website_apps');
|
|
require_once $siteDir . '/inc/lib.php';
|
|
|
|
$failures = [];
|
|
$total = 0;
|
|
$check = function (bool $ok, string $what) use (&$failures, &$total): void {
|
|
$total++;
|
|
if (!$ok) $failures[] = $what;
|
|
};
|
|
$makeZip = function (array $files): string {
|
|
$p = tempnam(sys_get_temp_dir(), 'pwa') . '.zip';
|
|
$z = new ZipArchive();
|
|
$z->open($p, ZipArchive::CREATE | ZipArchive::OVERWRITE);
|
|
foreach ($files as $n => $c) $z->addFromString($n, $c);
|
|
$z->close();
|
|
return $p;
|
|
};
|
|
$pad = bin2hex(random_bytes(1200)); // zufällig, damit das ZIP die Mindestgröße erreicht
|
|
|
|
// ── WordPress-Plugin ─────────────────────────────────────────────────────────
|
|
$wp = fn(string $v) => $makeZip(['deskhub-tickets/deskhub-tickets.php' => "<?php\n/**\n * Plugin Name: DeskHub Tickets\n * Version: {$v}\n */\n// {$pad}", 'deskhub-tickets/readme.txt' => 'x']);
|
|
$check(site_zip_app_version('wordpress', $wp('1.2.2')) === '1.2.2', 'Version steht im Plugin-Kopf');
|
|
$check(site_zip_app_version('wordpress', $makeZip(['a/a.php' => '<?php echo 1;'])) === null, 'PHP ohne "Plugin Name:" ist kein WordPress-Plugin');
|
|
$r = site_publish_app('wordpress', $wp('1.2.2'), '', 'Neue Farben');
|
|
$check($r['ok'] && $r['version'] === '1.2.2', 'WordPress-Plugin ohne eingetippte Version: ' . json_encode($r));
|
|
$check(!site_publish_app('wordpress', $wp('1.2.2'), '', '')['ok'], 'dieselbe Version wird nicht doppelt veröffentlicht');
|
|
$check(site_publish_app('wordpress', $wp('1.3.0'), '', '')['ok'], 'zweite Version wird angenommen');
|
|
$check(site_app_release('wordpress')['version'] === '1.3.0', 'neueste WordPress-Version wird geliefert');
|
|
$bad = site_publish_app('wordpress', $makeZip(['x.txt' => $pad]), '', '');
|
|
$check(!$bad['ok'] && str_contains($bad['error'], 'kein WordPress-Plugin'), 'ZIP ohne Plugin-Kopf wird abgelehnt');
|
|
$check(site_publish_app('wordpress', $wp('9.9.9'), '4.0.1', '')['ok'] && site_app_release('wordpress')['version'] === '4.0.1', 'eingetippte Version hat Vorrang');
|
|
|
|
// ── Chrome-Erweiterung ───────────────────────────────────────────────────────
|
|
$ch = fn(string $v) => $makeZip(['manifest.json' => json_encode(['manifest_version' => 3, 'name' => 'DeskHub', 'version' => $v]), 'app.js' => $pad]);
|
|
$r = site_publish_app('chrome', $ch('2.0.0'), '', '');
|
|
$check($r['ok'] && $r['version'] === '2.0.0', 'Chrome-Erweiterung: Version aus manifest.json: ' . json_encode($r));
|
|
$check(site_publish_app('chrome', $ch('2.1'), '', '')['ok'] && site_app_release('chrome')['version'] === '2.1.0', 'zweiteilige Version wird zu 2.1.0');
|
|
$check(!site_publish_app('chrome', $makeZip(['manifest.json' => '{}', 'a.js' => $pad]), '', '')['ok'], 'manifest.json ohne Version wird abgelehnt');
|
|
$check(!site_publish_app('chrome', $wp('1.0.0'), '', '')['ok'], 'WordPress-Plugin ist keine Chrome-Erweiterung');
|
|
$check(!site_publish_app('windows', $ch('1.0.0'), '', '')['ok'], 'Windows-App braucht EXE und eine Versionsnummer');
|
|
$check(site_app_release('unbekannt') === null, 'unbekannte Plattform liefert nichts');
|
|
$p = site_app_platforms();
|
|
$check(isset($p['wordpress'], $p['chrome']) && $p['chrome']['file'] === 'deskhub-chrome-erweiterung.zip', 'Plattformliste enthält WordPress und Chrome');
|
|
|
|
// ── Vorschaubild bleibt erhalten ─────────────────────────────────────────────
|
|
$png = $tmp . '/vorschau.png';
|
|
file_put_contents($png, base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=='));
|
|
$plug = fn(string $v) => $makeZip(['plugin.json' => json_encode(['slug' => 'bildtest', 'name' => 'Bildtest', 'version' => $v]), 'plugin.php' => '<?php // ' . $pad]);
|
|
$check(site_publish('plugin', $plug('1.0.0'), [], $png, 'vorschau.png')['ok'], 'Plugin mit Bild veröffentlicht');
|
|
$bild = site_item('plugin', 'bildtest')['preview'] ?? null;
|
|
$check($bild !== null, 'Bild ist gespeichert');
|
|
$check(site_publish('plugin', $plug('1.0.1'))['ok'] && (site_item('plugin', 'bildtest')['preview'] ?? null) === $bild, 'Update ohne Bild behält das Bild');
|
|
// alte Version entfernen, bevor die neue hochgeladen wird: das Bild darf nicht verloren gehen
|
|
foreach (site_item('plugin', 'bildtest')['versions'] as $v) site_delete_version((int) $v['id']);
|
|
$check(site_item('plugin', 'bildtest') === null, 'ohne Version ist der Eintrag unsichtbar');
|
|
$check(site_publish('plugin', $plug('1.1.0'))['ok'] && (site_item('plugin', 'bildtest')['preview'] ?? null) === $bild, 'Bild bleibt, auch wenn alle Versionen vorher entfernt wurden');
|
|
$check(is_file($tmp . '/storage/previews/' . $bild), 'Bilddatei liegt noch im Speicher');
|
|
$id = (int) site_item('plugin', 'bildtest')['id'];
|
|
$check(site_set_preview($id, null, null)['ok'] && empty(site_item('plugin', 'bildtest')['preview']) && !is_file($tmp . '/storage/previews/' . $bild), 'Bild lässt sich entfernen');
|
|
copy($png, $tmp . '/neu.png');
|
|
$check(site_set_preview($id, $tmp . '/neu.png', 'neu.png')['ok'] && !empty(site_item('plugin', 'bildtest')['preview']), 'Bild lässt sich hinzufügen');
|
|
|
|
$rm = function (string $d) use (&$rm) {
|
|
foreach (scandir($d) ?: [] as $e) { if ($e === '.' || $e === '..') continue; is_dir("$d/$e") ? $rm("$d/$e") : @unlink("$d/$e"); }
|
|
@rmdir($d);
|
|
};
|
|
$rm($tmp);
|
|
|
|
if ($failures) {
|
|
fwrite(STDERR, "Fehlgeschlagen:\n - " . implode("\n - ", $failures) . "\n");
|
|
exit(1);
|
|
}
|
|
echo "Plugin website apps checks passed ({$total} Prüfungen).\n";
|