Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Filament\Schemas\Components\Group;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Modules\Announcements\Models\Announcement;

class AnnouncementForm
{
Expand All @@ -22,6 +23,9 @@
->schema([
RichEditor::make('text')
->hiddenLabel()
// 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 (?Announcement $record, mixed $state): mixed => $record?->getRawOriginal('text') ?? $state)

Check warning on line 28 in src/Filament/Resources/Announcements/Schemas/AnnouncementForm.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Split this 145 characters long line (which is greater than 120 authorized).

See more on https://sonarcloud.io/project/issues?id=saucebase-dev_announcements&issues=AaG3DK8RYqINDK50WG0d&open=AaG3DK8RYqINDK50WG0d&pullRequest=23
->required()
->toolbarButtons([
['bold', 'italic', 'underline', 'strike'],
Expand Down
19 changes: 19 additions & 0 deletions tests/Feature/AnnouncementResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
use Livewire\Livewire;
Expand Down Expand Up @@ -160,4 +161,22 @@ public function test_an_announcement_that_cannot_be_dismissed_is_not(): void
->assertNotFound()
->assertCookieMissing(config('announcements.cookie_name'));
}

/** 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_long_text_whole(): void
{
$text = str_repeat('<p>Long announcement.</p>', 25_000);
$announcement = Announcement::factory()->create(['text' => $text]);
$this->assertGreaterThan(500_000, strlen($text));

$this->actingAs($this->admin);

Livewire::test(EditAnnouncement::class, ['record' => $announcement->id])
->fillForm(['is_active' => true])
->call('save')
->assertHasNoFormErrors();

$stored = (string) DB::table('announcements')->where('id', $announcement->id)->value('text');
$this->assertSame(strlen($text), strlen($stored), 'the stored text was cut');
}
}
Loading