Loheide-eu-mitarbeiterplatt.../tests/Feature/Update/UpdateStateTest.php
Friederich Loheide 28ef1e4a20 Plugin-System; Neuigkeiten und Termine als mitgelieferte Plugins
- Plugins nach WordPress-Prinzip: plugin.json-Manifest mit Versions- und
  Abhängigkeitsprüfung, eigenes PSR-4-Autoloading, register()/boot(),
  activate()/deactivate()/uninstall(), Migrationen, Routen und Views je Plugin
- plugins-core/ (mitgeliefert, aktiv bis zur Deaktivierung) und plugins/
  (Kunden-Plugins, geschützt vor Updates, inaktiv bis zur Aktivierung)
- Zustand in storage/app/plugins.json – Laden ohne Datenbankabfrage
- Wiederherstellungsmodus: Ausnahmen und Fatal Errors beim Laden
  deaktivieren das Plugin, das Portal bleibt erreichbar
- Hooks (Actions/Filter mit Prioritäten) und Registries für Navigation,
  Startseiten-Kacheln, Rechte und Admin-Seiten (Filament-Discovery)
- Admin-Seite „Plugins“: aktivieren, deaktivieren, per ZIP installieren
  (ZIP-Slip-Schutz), löschen mit oder ohne Daten; abschaltbar per
  INHAUS_DISALLOW_FILE_MODS
- Startseite komplett aus Kacheln; Plugin-Seiten als „slug::Seite“
- Version 0.3.0

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 07:06:16 +00:00

113 lines
3.7 KiB
PHP

<?php
namespace Tests\Feature\Update;
use App\Support\Update\Filesystem;
use App\Support\Update\InstalledVersion;
use App\Support\Update\MaintenanceFlag;
use App\Support\Update\UpdateProgress;
use InvalidArgumentException;
use Tests\TestCase;
class UpdateStateTest extends TestCase
{
private string $dir;
protected function setUp(): void
{
parent::setUp();
$this->dir = sys_get_temp_dir().'/inhaus-state-'.bin2hex(random_bytes(4));
mkdir($this->dir);
}
protected function tearDown(): void
{
Filesystem::deleteDirectory($this->dir);
parent::tearDown();
}
public function test_sha_is_read_and_written(): void
{
$version = new InstalledVersion($this->dir.'/.version');
$this->assertNull($version->current());
$this->assertSame('0.3.0', $version->release());
$this->assertSame('0.3.0', $version->full());
$version->save('A1B2C3D4E5F60718293a4b5c6d7e8f9012345678');
$this->assertSame('a1b2c3d4e5f60718293a4b5c6d7e8f9012345678', $version->current());
$this->assertSame('a1b2c3d', $version->short());
$this->assertSame('0.3.0 (a1b2c3d)', $version->full());
}
public function test_invalid_sha_is_rejected(): void
{
$version = new InstalledVersion($this->dir.'/.version');
foreach (['', 'main', 'a1b2c3d', str_repeat('g', 40), str_repeat('a', 41)] as $invalid) {
try {
$version->save($invalid);
$this->fail("„{$invalid}“ hätte abgelehnt werden müssen.");
} catch (InvalidArgumentException) {
$this->assertNull($version->current());
}
}
file_put_contents($this->dir.'/.version', "kaputt\n");
$this->assertNull($version->current());
}
public function test_maintenance_mode_heals_itself_after_expiry(): void
{
$flag = new MaintenanceFlag($this->dir.'/.maintenance');
$this->assertFalse($flag->isActive());
$flag->activate(600);
$this->assertTrue($flag->isActive());
$flag->deactivate();
$this->assertFalse($flag->isActive());
// Absturz mitten im Update: Flag bleibt liegen, ist aber abgelaufen.
file_put_contents($this->dir.'/.maintenance', json_encode(['since' => time() - 700, 'until' => time() - 100]));
$this->assertFalse($flag->isActive());
$this->assertFileDoesNotExist($this->dir.'/.maintenance');
// Kaputte Datei sperrt ebenfalls nicht.
file_put_contents($this->dir.'/.maintenance', 'Müll');
$this->assertFalse($flag->isActive());
}
public function test_progress_file_including_error_state(): void
{
$progress = new UpdateProgress($this->dir.'/.update-progress');
$this->assertSame(['pct' => 0, 'step' => 'idle', 'text' => '', 'ts' => 0], $progress->get());
$this->assertFalse($progress->isRunning());
$progress->set(20, 'download', 'Lädt …');
$this->assertSame(20, $progress->get()['pct']);
$this->assertSame('Lädt …', $progress->get()['text']);
$this->assertTrue($progress->isRunning());
$progress->fail('Kaputt');
$this->assertSame(-1, $progress->get()['pct']);
$this->assertSame('error', $progress->get()['step']);
$this->assertFalse($progress->isRunning());
}
public function test_stale_run_does_not_block_forever(): void
{
$progress = new UpdateProgress($this->dir.'/.update-progress');
file_put_contents($this->dir.'/.update-progress', json_encode([
'pct' => 50, 'step' => 'extract', 'text' => '', 'ts' => time() - UpdateProgress::STALE_AFTER_SECONDS - 1,
]));
$this->assertFalse($progress->isRunning());
}
}