All checks were successful
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m30s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m34s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m41s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m45s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m35s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 3m42s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m7s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m15s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m8s
- Organigramm: grafischer Baum (Linien, Zoom, Verschieben) und Fokus-Ansicht mit Vorgesetzten, Team und direkt Unterstellten - Dokumente: Übersicht mit Bereichen und „Zuletzt aktualisiert“, sortierbare Dateiliste oder Kacheln (Wahl wird gemerkt) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
176 lines
8.6 KiB
PHP
176 lines
8.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Documents;
|
|
|
|
use App\Models\Role;
|
|
use App\Models\User;
|
|
use App\Pagebuilder\Content;
|
|
use App\Support\Permissions\Audiences;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
use Inhaus\Plugins\Documents\FolderTree;
|
|
use Inhaus\Plugins\Documents\Models\Document;
|
|
use Inhaus\Plugins\Documents\Models\DocumentFolder;
|
|
use Tests\TestCase;
|
|
|
|
class DocumentsTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private DocumentFolder $personal;
|
|
|
|
private DocumentFolder $vertraege;
|
|
|
|
private User $hr;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
Storage::fake('local');
|
|
$this->personal = DocumentFolder::query()->create(['name' => 'Personal']);
|
|
$this->vertraege = DocumentFolder::query()->create(['name' => 'Verträge', 'parent_id' => $this->personal->id]);
|
|
|
|
$role = Role::query()->create(['name' => 'Personalabteilung']);
|
|
$role->grants()->create(['ability' => 'documents.edit', 'resource_type' => 'document_folder', 'resource_id' => $this->personal->id, 'include_children' => true]);
|
|
$this->hr = User::factory()->withRoles([$role])->create();
|
|
}
|
|
|
|
private function uploadTo(DocumentFolder $folder, array $files)
|
|
{
|
|
return $this->actingAs($this->hr)->post("/dokumente/ordner/{$folder->id}/dateien", ['files' => $files]);
|
|
}
|
|
|
|
public function test_editors_upload_documents_with_versions(): void
|
|
{
|
|
$this->uploadTo($this->vertraege, [
|
|
UploadedFile::fake()->create('Arbeitsvertrag Vorlage.docx', 40),
|
|
UploadedFile::fake()->create('Dienstanweisung.pdf', 120, 'application/pdf'),
|
|
])->assertSessionHas('status', '2 Dokumente hochgeladen.');
|
|
|
|
$doc = Document::query()->where('title', 'Dienstanweisung')->sole();
|
|
$this->assertSame(1, $doc->currentVersion->version);
|
|
Storage::disk('local')->assertExists($doc->currentVersion->path);
|
|
|
|
$this->post("/dokumente/{$doc->id}/versionen", ['file' => UploadedFile::fake()->create('Dienstanweisung 2027.pdf', 130, 'application/pdf'), 'note' => 'Neue Pausenregelung'])->assertSessionHasNoErrors();
|
|
$doc->refresh();
|
|
$this->assertSame(2, $doc->currentVersion->version);
|
|
|
|
$versions = $this->getJson("/dokumente/{$doc->id}/versionen")->assertOk()->json('versions');
|
|
$this->assertSame([2, 1], array_column($versions, 'version'));
|
|
$this->assertSame('Neue Pausenregelung', $versions[0]['note']);
|
|
|
|
$this->get($versions[1]['download_url'])->assertOk()->assertDownload('Dienstanweisung.pdf');
|
|
$this->get($versions[0]['download_url'])->assertOk()->assertDownload('Dienstanweisung 2027.pdf');
|
|
}
|
|
|
|
public function test_dangerous_files_are_rejected(): void
|
|
{
|
|
$this->uploadTo($this->personal, [UploadedFile::fake()->create('ok.pdf', 10), UploadedFile::fake()->create('boese.php', 1)])
|
|
->assertSessionHasErrors('files.1');
|
|
$this->assertSame(0, Document::query()->count(), 'Nichts wird halb hochgeladen.');
|
|
}
|
|
|
|
public function test_rights_apply_per_folder_including_subfolders(): void
|
|
{
|
|
$other = DocumentFolder::query()->create(['name' => 'Technik']);
|
|
$employee = User::factory()->create();
|
|
|
|
$this->uploadTo($other, [UploadedFile::fake()->create('x.pdf', 1)])->assertForbidden();
|
|
$this->uploadTo($this->vertraege, [UploadedFile::fake()->create('x.pdf', 1)])->assertSessionHasNoErrors();
|
|
|
|
$this->actingAs($employee)->post("/dokumente/ordner/{$this->personal->id}/dateien", ['files' => [UploadedFile::fake()->create('y.pdf', 1)]])->assertForbidden();
|
|
$this->actingAs($employee)->get("/dokumente/ordner/{$this->vertraege->id}")->assertOk()->assertInertia(fn (Assert $p) => $p
|
|
->where('folder.can_edit', false)
|
|
->has('documents', 1));
|
|
|
|
// Unterordner anlegen darf die Personalabteilung, oberste Ebene nicht.
|
|
$this->actingAs($this->hr)->post('/dokumente/ordner', ['name' => 'Richtlinien', 'parent_id' => $this->personal->id])->assertRedirect();
|
|
$this->post('/dokumente/ordner', ['name' => 'Neu oben'])->assertForbidden();
|
|
|
|
// Neuer Unterordner ist sofort mit abgedeckt.
|
|
$new = DocumentFolder::query()->where('name', 'Richtlinien')->sole();
|
|
$this->uploadTo($new, [UploadedFile::fake()->create('z.pdf', 1)])->assertSessionHasNoErrors();
|
|
|
|
// Verschieben nur in Ordner, in denen man pflegen darf.
|
|
$doc = Document::query()->where('folder_id', $new->id)->sole();
|
|
$this->put("/dokumente/{$doc->id}", ['title' => 'Z', 'folder_id' => $other->id])->assertForbidden();
|
|
$this->put("/dokumente/{$doc->id}", ['title' => 'Z', 'folder_id' => $this->personal->id])->assertSessionHasNoErrors();
|
|
}
|
|
|
|
public function test_visibility_is_inherited_and_protects_downloads(): void
|
|
{
|
|
$this->uploadTo($this->vertraege, [UploadedFile::fake()->create('Gehaltstabelle.xlsx', 5)]);
|
|
$doc = Document::query()->sole();
|
|
Audiences::sync('document_folder', $this->personal->id, ['department' => ['Personal']]);
|
|
FolderTree::flush();
|
|
|
|
$clerk = User::factory()->create(['department' => 'Personal']);
|
|
$nurse = User::factory()->create(['department' => 'Pflege']);
|
|
|
|
$this->actingAs($clerk)->get($doc->downloadUrl())->assertOk();
|
|
$this->actingAs($nurse)->get($doc->downloadUrl())->assertNotFound();
|
|
$this->actingAs($nurse)->get("/dokumente/ordner/{$this->vertraege->id}")->assertNotFound();
|
|
$this->actingAs($nurse)->get('/dokumente?q=Gehalt')->assertInertia(fn (Assert $p) => $p->where('documents', []));
|
|
$this->actingAs($clerk)->get('/dokumente?q=Gehalt')->assertInertia(fn (Assert $p) => $p->where('documents.0.title', 'Gehaltstabelle'));
|
|
}
|
|
|
|
public function test_search_finds_titles_descriptions_and_file_names(): void
|
|
{
|
|
$this->uploadTo($this->personal, [UploadedFile::fake()->create('Formular-U12.pdf', 5)]);
|
|
Document::query()->sole()->update(['title' => 'Urlaubsantrag', 'description' => 'Für Erholungsurlaub']);
|
|
|
|
foreach (['Urlaub', 'Erholung', 'U12'] as $term) {
|
|
$this->get('/dokumente?q='.$term)->assertInertia(fn (Assert $p) => $p->has('documents', 1));
|
|
}
|
|
}
|
|
|
|
public function test_overview_lists_areas_and_recent_documents(): void
|
|
{
|
|
$this->personal->update(['description' => 'Alles rund ums Personal']);
|
|
$this->uploadTo($this->vertraege, [UploadedFile::fake()->create('Vertrag.pdf', 5)]);
|
|
|
|
$this->get('/dokumente')->assertInertia(fn (Assert $p) => $p
|
|
->where('children.0.description', 'Alles rund ums Personal')
|
|
->where('children.0.folders', 1)
|
|
->where('children.0.documents', 0)
|
|
->where('recent.0.title', 'Vertrag')
|
|
->where('recent.0.folder_name', 'Verträge')
|
|
->where('recent.0.updated_by', $this->hr->name));
|
|
|
|
$this->get("/dokumente/ordner/{$this->vertraege->id}")->assertInertia(fn (Assert $p) => $p->where('recent', [])->where('documents.0.folder_name', null));
|
|
}
|
|
|
|
public function test_folders_can_only_be_deleted_when_empty(): void
|
|
{
|
|
$this->actingAs($this->hr)->delete("/dokumente/ordner/{$this->vertraege->id}")->assertRedirect(route('documents.folder', $this->personal));
|
|
$this->assertNull(DocumentFolder::query()->find($this->vertraege->id));
|
|
|
|
$this->uploadTo($this->personal, [UploadedFile::fake()->create('a.pdf', 1)]);
|
|
$this->actingAs(User::factory()->admin()->create())->delete("/dokumente/ordner/{$this->personal->id}")->assertSessionHasErrors('folder');
|
|
}
|
|
|
|
public function test_folder_block_in_pages(): void
|
|
{
|
|
$this->uploadTo($this->personal, [UploadedFile::fake()->create('Checkliste.pdf', 5)]);
|
|
$content = app(Content::class);
|
|
$rendered = $content->render($content->sanitize(['blocks' => [['type' => 'documents.folder', 'data' => ['folder' => (string) $this->personal->id]]]]), User::factory()->create());
|
|
|
|
$this->assertSame('Checkliste', $rendered['blocks'][0]['props']['documents'][0]['title']);
|
|
}
|
|
|
|
public function test_deleting_a_document_removes_all_files(): void
|
|
{
|
|
$this->uploadTo($this->personal, [UploadedFile::fake()->create('a.pdf', 1)]);
|
|
$doc = Document::query()->sole();
|
|
$this->post("/dokumente/{$doc->id}/versionen", ['file' => UploadedFile::fake()->create('a2.pdf', 1)]);
|
|
$paths = $doc->versions()->pluck('path');
|
|
|
|
$this->delete("/dokumente/{$doc->id}")->assertSessionHasNoErrors();
|
|
foreach ($paths as $path) {
|
|
Storage::disk('local')->assertMissing($path);
|
|
}
|
|
}
|
|
}
|