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', 'Willkommen im QM
'); $settings->set(Presenter::HOME_CONTACTS, [$lead->id]); $settings->set(Presenter::OFFICERS, [ ['user_id' => $care->id, 'area' => 'Pflege', 'folder_id' => $this->personal->id], ['user_id' => $gone->id, 'area' => 'Alt', 'folder_id' => null], ['user_id' => $lead->id, 'area' => null, 'folder_id' => 99999], ]); $this->actingAs(User::factory()->create())->get('/qm')->assertInertia(fn (Assert $p) => $p ->where('intro', fn ($html) => str_contains($html, 'QM') && ! str_contains($html, 'script')) ->where('contacts.0.name', 'Petra Leitung') ->has('officers', 2) ->where('officers.0.name', 'Klaus Pflege') ->where('officers.0.area', 'Pflege') ->where('officers.0.folder.path', 'Personal') ->where('officers.1.folder', null)); } public function test_admin_maintains_the_start_page(): void { $lead = User::factory()->create(); $this->actingAs($this->qmb); Livewire::test(QmSettings::class) ->set('data.home_intro', 'Hallo
') ->set('data.home_contacts', [(string) $lead->id]) ->set('data.officers', ['a' => ['user_id' => (string) $lead->id, 'area' => 'Küche', 'folder_id' => (string) $this->personal->id]]) ->call('save') ->assertHasNoErrors(); $settings = app(Settings::class); $this->assertStringContainsString('Hallo', $settings->get(Presenter::HOME_INTRO)); $this->assertSame([$lead->id], $settings->get(Presenter::HOME_CONTACTS)); // assertEquals: MySQLs JSON-Spalte sortiert die Schlüssel um $this->assertEquals([['user_id' => $lead->id, 'area' => 'Küche', 'folder_id' => $this->personal->id]], $settings->get(Presenter::OFFICERS)); } 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, '