Loheide-eu-mitarbeiterplatt.../tests/Feature/InstallerTest.php
Friederich Loheide 9ddc35a62c
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m30s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m28s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m31s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m36s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 1m45s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 1m44s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 1m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 1m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 54s
Rollen, Rechte und Zielgruppen
- Rollen mit globalen Rechten und Rechten für einzelne Objekte (z. B. „Beiträge
  schreiben in Kategorie MAV-Info“); Rollen sind additiv, Zuweisungen merken
  sich ihre Herkunft (manuell oder später Identity-Provider-Gruppe)
- Systemrolle „Administration“ ersetzt users.is_admin (Migration übernimmt
  bestehende Administratoren); nicht löschbar, man kann sie sich nicht selbst entziehen
- Rechte je Person vorberechnet und gecacht, Versionszähler invalidiert bei Änderungen
- Gate-Anbindung: registrierte Rechte entscheidet das Rechtesystem, Objektregeln
  die Policies; Admin-Seiten und Plugin-Ressourcen hinter passenden Rechten
- Redaktion nach Kategorie: Schreiben und Veröffentlichen getrennt, Liste im
  Admin auf eigene Kategorien beschränkt, ohne Veröffentlichungsrecht bleibt
  ein Beitrag Entwurf
- Zielgruppen (Rolle/Abteilung/Standort) für Kategorien und Termine als
  indizierte SQL-Bedingung in Listen, Detailseiten, Kacheln und .ics-Export
- Admin: Rollen-Verwaltung, „Rechte prüfen“, Redaktion und Sichtbarkeit direkt
  an Kategorie bzw. Termin
- Kern-Ressourcen explizit registriert, damit nach Updates liegengebliebene
  alte Dateien nicht doppelt geladen werden
- docs/PLUGINS.md für Plugin-Entwicklung; Demo-Rolle „MAV“

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

117 lines
4.6 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\User;
use App\Support\Installation;
use App\Support\License\LicenseStore;
use App\Support\Settings;
use App\Support\Update\Filesystem;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class InstallerTest extends TestCase
{
use RefreshDatabase;
private string $dir;
protected function setUp(): void
{
parent::setUp();
$this->dir = sys_get_temp_dir().'/inhaus-inst-'.bin2hex(random_bytes(4));
mkdir($this->dir);
copy(base_path('.env.example'), $this->dir.'/.env');
$this->app->useEnvironmentPath($this->dir);
$this->app->instance(LicenseStore::class, new LicenseStore($this->dir.'/license.json'));
config(['inhaus.installed' => false]);
}
protected function tearDown(): void
{
@unlink(storage_path('.installed'));
Filesystem::deleteDirectory($this->dir);
parent::tearDown();
}
public function test_every_page_leads_to_the_installer(): void
{
$this->get('/')->assertRedirect('/install');
$this->get('/login')->assertRedirect('/install');
$this->get('/install')->assertOk()->assertSee('Systemprüfung')->assertSee('PHP-Version');
}
public function test_wrong_database_credentials_are_explained(): void
{
$this->post('/install/datenbank', [
'host' => config('database.connections.mysql.host'),
'port' => config('database.connections.mysql.port'),
'database' => config('database.connections.mysql.database'),
'username' => 'gibtesnicht',
'password' => 'falsch',
])->assertSessionHasErrors(['host' => 'Verbindung fehlgeschlagen: Benutzername oder Passwort sind falsch, oder der Benutzer hat keinen Zugriff auf diese Datenbank.']);
}
public function test_database_settings_are_written_to_env(): void
{
$this->post('/install/datenbank', [
'host' => config('database.connections.mysql.host'),
'port' => config('database.connections.mysql.port'),
'database' => config('database.connections.mysql.database'),
'username' => config('database.connections.mysql.username'),
'password' => config('database.connections.mysql.password'),
])->assertRedirect('/install/konto');
$env = file_get_contents($this->dir.'/.env');
$this->assertStringContainsString('DB_DATABASE='.config('database.connections.mysql.database'), $env);
$this->assertStringContainsString('DB_USERNAME='.config('database.connections.mysql.username'), $env);
$this->assertStringContainsString('APP_URL='.url('/'), $env);
}
public function test_account_step_completes_the_installation(): void
{
$this->post('/install/konto', [
'portal_name' => 'Caritas-Netz',
'first_name' => 'Ada',
'last_name' => 'Admin',
'email' => 'Ada@Example.com',
'password' => 'SicheresPasswort1',
'password_confirmation' => 'SicheresPasswort1',
'license_email' => 'lizenz@example.com',
'license_key' => 'KEY-123',
])->assertRedirect('/login?eingerichtet=1');
$admin = User::query()->where('email', 'ada@example.com')->sole();
$this->assertTrue($admin->isAdministrator());
$this->assertSame('Ada Admin', $admin->name);
$this->assertSame('Caritas-Netz', app(Settings::class)->get('branding.portal_name'));
$this->assertSame('KEY-123', app(LicenseStore::class)->key());
$this->assertFileExists(storage_path('.installed'));
config(['inhaus.installed' => null]);
$this->assertTrue(Installation::isInstalled());
$this->get('/install')->assertNotFound();
$this->get('/login?eingerichtet=1')->assertInertia(fn ($page) => $page
->where('status', 'Die Einrichtung ist abgeschlossen. Sie können sich jetzt mit Ihrem Administratorkonto anmelden.'));
}
public function test_weak_admin_password_is_rejected(): void
{
$this->post('/install/konto', [
'portal_name' => 'Portal', 'first_name' => 'A', 'last_name' => 'B', 'email' => 'a@example.com',
'password' => 'kurz', 'password_confirmation' => 'kurz',
])->assertSessionHasErrors('password');
$this->assertFileDoesNotExist(storage_path('.installed'));
}
public function test_installer_is_gone_once_installed(): void
{
config(['inhaus.installed' => true]);
$this->get('/install')->assertNotFound();
$this->post('/install/konto', [])->assertNotFound();
}
}