From a729d89cf3f9d327448984c41cf28d6bcc5efe26 Mon Sep 17 00:00:00 2001 From: roble Date: Sat, 7 Nov 2026 17:26:35 +0000 Subject: [PATCH] fix: load the stored product description into the editor, not the sanitised read Also narrows ViewPathsTest's finder for PHPStan. Co-Authored-By: Claude Opus 5.5 --- .../Resources/Products/Schemas/ProductForm.php | 3 +++ tests/Feature/EntitlementCatalogueTest.php | 17 +++++++++++++++++ tests/Feature/ViewPathsTest.php | 8 +++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Filament/Resources/Products/Schemas/ProductForm.php b/src/Filament/Resources/Products/Schemas/ProductForm.php index 730ecba..dc1387e 100644 --- a/src/Filament/Resources/Products/Schemas/ProductForm.php +++ b/src/Filament/Resources/Products/Schemas/ProductForm.php @@ -298,6 +298,9 @@ private static function groups(): array RichEditor::make('description') ->label(__('Description')) + // What is stored, not the sanitised read: the sanitiser cuts input + // at 500,000 bytes, and saving any field would write the cut copy back. + ->formatStateUsing(fn (?Product $record, mixed $state): mixed => $record?->getRawOriginal('description') ?? $state) ->nullable() ->columnSpanFull(), ]) diff --git a/tests/Feature/EntitlementCatalogueTest.php b/tests/Feature/EntitlementCatalogueTest.php index 58973e3..0257675 100644 --- a/tests/Feature/EntitlementCatalogueTest.php +++ b/tests/Feature/EntitlementCatalogueTest.php @@ -6,6 +6,7 @@ use Filament\Resources\Events\RecordSaved; use Filament\Support\Exceptions\Halt; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Event; use Livewire\Livewire; use Modules\Billing\Enums\PlanKind; @@ -115,4 +116,20 @@ public function test_a_rolled_back_save_sends_no_warning(): void ->call('save') ->assertNotNotified(__('Not in the catalogue: :keys', ['keys' => 'legacy_flag'])); } + + /** The sanitiser cuts input at 500,000 bytes: saving another field must not write the cut copy back. */ + public function test_saving_another_field_keeps_a_long_description_whole(): void + { + $description = str_repeat('

Long description.

', 25_000); + $plan = Product::factory()->create(['kind' => PlanKind::OneOff, 'description' => $description]); + $this->assertGreaterThan(500_000, strlen($description)); + + Livewire::test(EditProduct::class, ['record' => $plan->getKey()]) + ->fillForm(['name' => 'Renamed']) + ->call('save') + ->assertHasNoFormErrors(); + + $stored = (string) DB::table('products')->where('id', $plan->getKey())->value('description'); + $this->assertSame(strlen($description), strlen($stored), 'the stored description was cut'); + } } diff --git a/tests/Feature/ViewPathsTest.php b/tests/Feature/ViewPathsTest.php index 85514c9..7136e93 100644 --- a/tests/Feature/ViewPathsTest.php +++ b/tests/Feature/ViewPathsTest.php @@ -3,6 +3,7 @@ namespace Modules\Billing\Tests\Feature; use Illuminate\Support\Facades\View; +use Illuminate\View\FileViewFinder; use Tests\TestCase; /** @@ -13,12 +14,13 @@ class ViewPathsTest extends TestCase { public function test_every_view_folder_billing_registers_exists(): void { - $paths = View::getFinder()->getHints()['billing'] ?? []; + $finder = View::getFinder(); + $this->assertInstanceOf(FileViewFinder::class, $finder); + + $paths = $finder->getHints()['billing'] ?? []; foreach ($paths as $path) { $this->assertDirectoryExists($path); } - - $this->addToAssertionCount(1); } }