create(['name' => 'QM-Beauftragte']);
$role->grants()->create(['ability' => 'qm.manage']);
$this->qmb = User::factory()->withRoles([$role])->create();
$this->general = QmCategory::query()->create(['name' => 'Allgemein', 'sort' => 1]);
$this->personal = QmFolder::query()->create(['name' => 'Personal', 'category_id' => $this->general->id, 'color' => 'teal', 'icon' => 'users', 'intro' => '
Alles zu Personal
']);
}
/** Ein echtes PDF mit Textebene. */
private function pdf(string $name, array $lines): UploadedFile
{
$content = 'BT /F1 12 Tf 50 750 Td 14 TL '.implode(' ', array_map(fn ($l) => '('.$l.') \'', $lines)).' ET';
$objects = [
'<< /Type /Catalog /Pages 2 0 R >>',
'<< /Type /Pages /Kids [3 0 R] /Count 1 >>',
'<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >>',
'<< /Length '.strlen($content)." >>\nstream\n{$content}\nendstream",
'<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>',
];
$pdf = "%PDF-1.4\n";
$offsets = [];
foreach ($objects as $i => $object) {
$offsets[] = strlen($pdf);
$pdf .= ($i + 1)." 0 obj\n{$object}\nendobj\n";
}
$xref = strlen($pdf);
$pdf .= 'xref\n0 '.(count($objects) + 1)."\n0000000000 65535 f \n".implode('', array_map(fn ($o) => sprintf("%010d 00000 n \n", $o), $offsets));
$pdf = str_replace('xref\n', "xref\n", $pdf);
$pdf .= 'trailer << /Size '.(count($objects) + 1)." /Root 1 0 R >>\nstartxref\n{$xref}\n%%EOF";
return UploadedFile::fake()->createWithContent($name, $pdf);
}
private function docx(string $name, string $text): UploadedFile
{
$path = tempnam(sys_get_temp_dir(), 'docx');
$zip = new ZipArchive;
$zip->open($path, ZipArchive::OVERWRITE);
$zip->addFromString('[Content_Types].xml', '');
$zip->addFromString('word/document.xml', ''.htmlspecialchars($text).'');
$zip->close();
return UploadedFile::fake()->createWithContent($name, (string) file_get_contents($path));
}
private function addFile(QmFolder $folder, string $title, UploadedFile $reading, array $extra = []): QmEntry
{
$this->actingAs($this->qmb)->post("/qm/ordner/{$folder->id}/eintraege", ['type' => 'file', 'title' => $title, 'version' => '1.0', 'valid_from' => '2026-03-01', 'reading' => $reading, ...$extra])
->assertSessionHasNoErrors();
return QmEntry::query()->where('title', $title)->sole();
}
public function test_start_page_shows_categories_with_colored_tiles_and_inherited_colors(): void
{
$sub = QmFolder::query()->create(['name' => 'Urlaub', 'parent_id' => $this->personal->id]);
QmFolder::query()->create(['name' => 'Arbeitsschutz', 'category_id' => QmCategory::query()->create(['name' => 'Sicherheit', 'sort' => 2])->id, 'color' => 'red']);
$this->actingAs(User::factory()->create())->get('/qm')->assertOk()->assertInertia(fn (Assert $p) => $p
->component('qm::Index')
->where('categories.0.name', 'Allgemein')
->where('categories.0.folders.0.name', 'Personal')
->where('categories.0.folders.0.color', 'teal')
->where('categories.0.folders.0.icon', ['name' => 'users'])
->where('categories.0.folders.0.folders', 1)
->where('categories.1.folders.0.color', 'red')
->where('adminUrl', null));
$node = app(QmTree::class)->folder($sub->id);
$this->assertSame('teal', $node['color'], 'Farbe wird vererbt');
$this->assertSame(['name' => 'users'], $node['icon'], 'Symbol wird vererbt');
}
public function test_folder_page_with_intro_contacts_subfolders_and_entries(): void
{
$anna = User::factory()->create(['first_name' => 'Anna', 'last_name' => 'Schmidt', 'phone' => '+49 40 123', 'job_title' => 'Personalleitung', 'location' => 'Hamburg']);
$gone = User::factory()->inactive()->create();
$this->personal->contacts()->attach([$anna->id => ['sort' => 1], $gone->id => ['sort' => 2]]);
app(Settings::class)->set(Presenter::CONTACT_FIELDS, ['phone', 'location']);
QmFolder::query()->create(['name' => 'Urlaub', 'parent_id' => $this->personal->id, 'icon' => 'plane']);
$this->addFile($this->personal, 'Dienstplanregelung', $this->pdf('dienstplan.pdf', ['Dienstplan']));
$this->actingAs(User::factory()->create())->get("/qm/ordner/{$this->personal->id}")->assertOk()->assertInertia(fn (Assert $p) => $p
->component('qm::Folder')
->where('folder.intro', fn ($html) => str_contains($html, 'Personal') && ! str_contains($html, '