id(); $t->foreignId('parent_id')->nullable()->constrained('document_folders'); $t->string('name'); $t->string('description', 500)->nullable(); $t->unsignedInteger('sort')->default(0); $t->foreignId('created_by')->nullable(); $t->timestamps(); }); Schema::create('documents', function (Blueprint $t) { $t->id(); $t->foreignId('folder_id')->constrained('document_folders'); $t->string('title'); $t->text('description')->nullable(); $t->unsignedBigInteger('current_version_id')->nullable(); $t->foreignId('created_by')->nullable(); $t->foreignId('updated_by')->nullable(); $t->unsignedInteger('downloads')->default(0); $t->timestamps(); }); Schema::create('document_versions', function (Blueprint $t) { $t->id(); $t->foreignId('document_id')->constrained('documents')->cascadeOnDelete(); $t->unsignedInteger('version'); $t->string('name'); $t->string('path'); $t->string('mime')->nullable(); $t->unsignedBigInteger('size')->default(0); $t->string('note', 500)->nullable(); $t->foreignId('uploaded_by')->nullable(); $t->timestamp('created_at')->nullable(); }); Schema::create('document_favorites', function (Blueprint $t) { $t->foreignId('user_id')->constrained()->cascadeOnDelete(); $t->foreignId('document_id')->constrained()->cascadeOnDelete(); $t->timestamp('created_at')->nullable(); $t->primary(['user_id', 'document_id']); }); $user = User::factory()->create(); $role = Role::query()->create(['name' => 'Personal']); $folder = DB::table('document_folders')->insertGetId(['name' => 'Personal']); $doc = DB::table('documents')->insertGetId(['folder_id' => $folder, 'title' => 'Urlaubsantrag', 'downloads' => 42]); DB::table('document_versions')->insert(['document_id' => $doc, 'version' => 1, 'name' => 'a.pdf', 'path' => 'documents/1/a.pdf']); DB::table('document_favorites')->insert(['user_id' => $user->id, 'document_id' => $doc]); DB::table('grants')->insert(['role_id' => $role->id, 'ability' => 'documents.edit', 'resource_type' => 'document_folder', 'resource_id' => $folder, 'include_children' => true]); DB::table('audiences')->insert(['resource_type' => 'document_folder', 'resource_id' => $folder, 'rule_type' => 'department', 'rule_value' => 'Personal']); app(Settings::class)->set(Navigation::MENU_SETTING, [['id' => 'a', 'type' => 'group', 'label' => 'Service', 'children' => [['id' => 'b', 'type' => 'module', 'module' => 'documents']]]]); app(Settings::class)->set('dashboard.layout', ['documents.favorites' => ['sort' => 5, 'visible' => false]]); DB::table('pages')->insert(['title' => 'Seite', 'slug' => 'seite', 'path' => 'seite', 'content' => json_encode(['blocks' => [['id' => 'x', 'type' => 'documents.folder', 'data' => ['folder' => (string) $folder]]]])]); (require base_path('plugins-core/downloads/database/migrations/2026_09_29_000002_rename_documents_to_downloads.php'))->up(); $this->assertFalse(Schema::hasTable('documents')); $this->assertSame(42, (int) DB::table('downloads')->where('id', $doc)->value('download_count')); $this->assertSame($doc, (int) DB::table('download_versions')->value('download_id')); $this->assertSame($doc, (int) DB::table('download_favorites')->value('download_id')); $this->assertSame(['downloads.edit', 'download_folder'], array_values((array) DB::table('grants')->where('role_id', $role->id)->first(['ability', 'resource_type']))); $this->assertSame('download_folder', DB::table('audiences')->value('resource_type')); $this->assertSame('downloads', app(Settings::class)->get(Navigation::MENU_SETTING)[0]['children'][0]['module']); $this->assertSame(['downloads.favorites'], array_keys(app(Settings::class)->get('dashboard.layout'))); $this->assertStringContainsString('"downloads.folder"', DB::table('pages')->value('content')); // Zweiter Lauf ändert nichts. (require base_path('plugins-core/downloads/database/migrations/2026_09_29_000002_rename_documents_to_downloads.php'))->up(); $this->assertSame(42, (int) DB::table('downloads')->where('id', $doc)->value('download_count')); } public function test_old_links_redirect(): void { $this->get('/dokumente/ordner/5?q=urlaub')->assertRedirect('/downloads/ordner/5?q=urlaub')->assertStatus(301); $this->get('/dokumente')->assertRedirect('/downloads'); } }