diff --git a/app/Models/Post.php b/app/Models/Post.php index 2c7c255..17119b8 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -5,6 +5,7 @@ namespace App\Models; use App\Enums\PostStatus; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Str; class Post extends Model { @@ -62,4 +63,12 @@ class Post extends Model return $this->body[$locale] ?? $this->body['ar'] ?? ''; } + + /** + * Get the excerpt by stripping HTML and limiting to 150 characters. + */ + public function getExcerpt(?string $locale = null): string + { + return Str::limit(strip_tags($this->getBody($locale)), 150); + } } diff --git a/config/purifier.php b/config/purifier.php new file mode 100644 index 0000000..1c63a17 --- /dev/null +++ b/config/purifier.php @@ -0,0 +1,106 @@ +set('Core.Encoding', $this->config->get('purifier.encoding')); + * $config->set('Cache.SerializerPath', $this->config->get('purifier.cachePath')); + * if ( ! $this->config->get('purifier.finalize')) { + * $config->autoFinalize = false; + * } + * $config->loadArray($this->getConfig()); + * + * You must NOT delete the default settings + * anything in settings should be compacted with params that needed to instance HTMLPurifier_Config. + * + * @link http://htmlpurifier.org/live/configdoc/plain.html + */ + +return [ + 'encoding' => 'UTF-8', + 'finalize' => true, + 'ignoreNonStrings' => false, + 'cachePath' => storage_path('app/purifier'), + 'cacheFileMode' => 0755, + 'settings' => [ + 'default' => [ + 'HTML.Doctype' => 'HTML 4.01 Transitional', + 'HTML.Allowed' => 'h2,h3,p,br,b,strong,i,em,u,ul,ol,li,a[href|title],blockquote', + 'AutoFormat.AutoParagraph' => true, + 'AutoFormat.RemoveEmpty' => true, + ], + 'test' => [ + 'Attr.EnableID' => 'true', + ], + 'youtube' => [ + 'HTML.SafeIframe' => 'true', + 'URI.SafeIframeRegexp' => '%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%', + ], + 'custom_definition' => [ + 'id' => 'html5-definitions', + 'rev' => 1, + 'debug' => false, + 'elements' => [ + // http://developers.whatwg.org/sections.html + ['section', 'Block', 'Flow', 'Common'], + ['nav', 'Block', 'Flow', 'Common'], + ['article', 'Block', 'Flow', 'Common'], + ['aside', 'Block', 'Flow', 'Common'], + ['header', 'Block', 'Flow', 'Common'], + ['footer', 'Block', 'Flow', 'Common'], + + // Content model actually excludes several tags, not modelled here + ['address', 'Block', 'Flow', 'Common'], + ['hgroup', 'Block', 'Required: h1 | h2 | h3 | h4 | h5 | h6', 'Common'], + + // http://developers.whatwg.org/grouping-content.html + ['figure', 'Block', 'Optional: (figcaption, Flow) | (Flow, figcaption) | Flow', 'Common'], + ['figcaption', 'Inline', 'Flow', 'Common'], + + // http://developers.whatwg.org/the-video-element.html#the-video-element + ['video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', [ + 'src' => 'URI', + 'type' => 'Text', + 'width' => 'Length', + 'height' => 'Length', + 'poster' => 'URI', + 'preload' => 'Enum#auto,metadata,none', + 'controls' => 'Bool', + ]], + ['source', 'Block', 'Flow', 'Common', [ + 'src' => 'URI', + 'type' => 'Text', + ]], + + // http://developers.whatwg.org/text-level-semantics.html + ['s', 'Inline', 'Inline', 'Common'], + ['var', 'Inline', 'Inline', 'Common'], + ['sub', 'Inline', 'Inline', 'Common'], + ['sup', 'Inline', 'Inline', 'Common'], + ['mark', 'Inline', 'Inline', 'Common'], + ['wbr', 'Inline', 'Empty', 'Core'], + + // http://developers.whatwg.org/edits.html + ['ins', 'Block', 'Flow', 'Common', ['cite' => 'URI', 'datetime' => 'CDATA']], + ['del', 'Block', 'Flow', 'Common', ['cite' => 'URI', 'datetime' => 'CDATA']], + ], + 'attributes' => [ + ['iframe', 'allowfullscreen', 'Bool'], + ['table', 'height', 'Text'], + ['td', 'border', 'Text'], + ['th', 'border', 'Text'], + ['tr', 'width', 'Text'], + ['tr', 'height', 'Text'], + ['tr', 'border', 'Text'], + ], + ], + 'custom_attributes' => [ + ['a', 'target', 'Enum#_blank,_self,_target,_top'], + ], + 'custom_elements' => [ + ['u', 'Inline', 'Inline', 'Common'], + ], + ], + +]; diff --git a/docs/qa/gates/5.1-post-creation-editing.yml b/docs/qa/gates/5.1-post-creation-editing.yml new file mode 100644 index 0000000..474534b --- /dev/null +++ b/docs/qa/gates/5.1-post-creation-editing.yml @@ -0,0 +1,43 @@ +schema: 1 +story: "5.1" +story_title: "Post Creation & Editing" +gate: PASS +status_reason: "All acceptance criteria met with comprehensive test coverage (30 tests), proper XSS protection via HTML Purifier, and complete bilingual support." +reviewer: "Quinn (Test Architect)" +updated: "2025-12-27T00:00:00Z" + +waiver: { active: false } + +top_issues: [] + +quality_score: 100 +expires: "2026-01-10T00:00:00Z" + +evidence: + tests_reviewed: 30 + risks_identified: 0 + trace: + ac_covered: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] + ac_gaps: [] + +nfr_validation: + security: + status: PASS + notes: "HTML Purifier with strict whitelist, admin middleware authorization, audit logging with IP tracking" + performance: + status: PASS + notes: "Auto-save only for drafts, pagination with configurable per-page, debounced search (300ms)" + reliability: + status: PASS + notes: "Comprehensive error handling, validation on all inputs, proper Livewire state management" + maintainability: + status: PASS + notes: "Clean Volt component structure, proper separation of concerns, complete bilingual translations" + +recommendations: + immediate: [] + future: + - action: "Consider adding delete functionality for posts" + refs: ["resources/views/livewire/admin/posts/index.blade.php"] + - action: "Consider extracting Trix editor setup to reusable Blade component" + refs: ["resources/views/livewire/admin/posts/create.blade.php", "resources/views/livewire/admin/posts/edit.blade.php"] diff --git a/docs/stories/story-5.1-post-creation-editing.md b/docs/stories/story-5.1-post-creation-editing.md index 5521924..6b6c894 100644 --- a/docs/stories/story-5.1-post-creation-editing.md +++ b/docs/stories/story-5.1-post-creation-editing.md @@ -19,33 +19,33 @@ So that **I can publish professional legal content for website visitors**. ## Acceptance Criteria ### Post Creation Form -- [ ] Title (required, bilingual: Arabic and English) -- [ ] Body content (required, bilingual) -- [ ] Status (draft/published) +- [x] Title (required, bilingual: Arabic and English) +- [x] Body content (required, bilingual) +- [x] Status (draft/published) ### Rich Text Editor -- [ ] Bold, italic, underline -- [ ] Headings (H2, H3) -- [ ] Bullet and numbered lists -- [ ] Links -- [ ] Blockquotes +- [x] Bold, italic, underline +- [x] Headings (H2, H3) +- [x] Bullet and numbered lists +- [x] Links +- [x] Blockquotes ### Saving Features -- [ ] Save as draft functionality -- [ ] Preview post before publishing -- [ ] Edit published posts -- [ ] Auto-save draft periodically (every 60 seconds) -- [ ] Immediate publishing (no scheduling) +- [x] Save as draft functionality +- [x] Preview post before publishing +- [x] Edit published posts +- [x] Auto-save draft periodically (every 60 seconds) +- [x] Immediate publishing (no scheduling) ### Timestamps -- [ ] created_at recorded on creation -- [ ] updated_at updated on edit +- [x] created_at recorded on creation +- [x] updated_at updated on edit ### Quality Requirements -- [ ] HTML sanitization for XSS prevention -- [ ] Bilingual form labels -- [ ] Audit log for create/edit -- [ ] Tests for CRUD operations +- [x] HTML sanitization for XSS prevention +- [x] Bilingual form labels +- [x] Audit log for create/edit +- [x] Tests for CRUD operations ## Technical Notes @@ -309,17 +309,17 @@ Include Trix editor assets in your layout or component: ## Definition of Done -- [ ] Can create post with bilingual content -- [ ] Rich text editor works -- [ ] Can save as draft -- [ ] Can publish directly -- [ ] Can edit existing posts -- [ ] Auto-save works for drafts -- [ ] Preview modal displays sanitized content -- [ ] HTML properly sanitized -- [ ] Audit log created -- [ ] Tests pass -- [ ] Code formatted with Pint +- [x] Can create post with bilingual content +- [x] Rich text editor works +- [x] Can save as draft +- [x] Can publish directly +- [x] Can edit existing posts +- [x] Auto-save works for drafts +- [x] Preview modal displays sanitized content +- [x] HTML properly sanitized +- [x] Audit log created +- [x] Tests pass +- [x] Code formatted with Pint ## Test Scenarios @@ -481,3 +481,148 @@ test('preview modal can be opened and closed', function () { **Complexity:** Medium **Estimated Effort:** 4-5 hours + +--- + +## Dev Agent Record + +### Status +**Ready for Review** + +### Agent Model Used +Claude Opus 4.5 (claude-opus-4-5-20251101) + +### File List + +**New Files:** +- `config/purifier.php` - HTML Purifier configuration for XSS prevention +- `resources/views/livewire/admin/posts/index.blade.php` - Posts listing Volt component +- `resources/views/livewire/admin/posts/create.blade.php` - Post creation Volt component with Trix editor +- `resources/views/livewire/admin/posts/edit.blade.php` - Post editing Volt component with Trix editor +- `lang/en/posts.php` - English translations for posts module +- `lang/ar/posts.php` - Arabic translations for posts module +- `tests/Feature/Admin/PostManagementTest.php` - Feature tests for post CRUD operations (30 tests) + +**Modified Files:** +- `app/Models/Post.php` - Added `getExcerpt()` method +- `routes/web.php` - Added admin posts routes +- `lang/en/common.php` - Added 'close' translation +- `lang/ar/common.php` - Added 'close' translation +- `lang/en/enums.php` - Added post_status translations +- `lang/ar/enums.php` - Added post_status translations + +### Change Log +1. Published and configured `mews/purifier` for HTML sanitization with allowed tags: h2, h3, p, br, b, strong, i, em, u, ul, ol, li, a[href|title], blockquote +2. Added `getExcerpt()` method to Post model for generating text excerpts +3. Created admin posts index page with filtering by status and search functionality +4. Created admin posts create page with Trix rich text editor, preview modal, and save draft/publish actions +5. Created admin posts edit page with auto-save (60s) for drafts, preview modal, and publish/unpublish actions +6. Added admin posts routes under `/admin/posts` prefix +7. Added bilingual translations (ar/en) for all post-related UI strings +8. Implemented audit logging via AdminLog for create/update actions +9. Wrote comprehensive feature tests covering CRUD, validation, authorization, and HTML sanitization + +### Completion Notes +- Post model already existed with JSON columns for bilingual title/body (different from story's suggested schema with separate columns - existing implementation is better) +- PostFactory and PostStatus enum already existed +- Used Trix editor (as suggested in story) via CDN with file upload toolbar hidden +- Auto-save only triggers for draft posts to prevent accidental changes to published content +- All 671 tests pass (30 new tests added for this story) + +--- + +## QA Results + +### Review Date: 2025-12-27 + +### Reviewed By: Quinn (Test Architect) + +### Code Quality Assessment + +**Overall Grade: Excellent** + +The implementation demonstrates high quality across all dimensions. The code follows established patterns in the codebase, uses appropriate architectural decisions (JSON columns for bilingual content instead of separate columns), and includes comprehensive test coverage with 30 passing tests. + +**Key Strengths:** +1. **Architecture**: JSON columns for bilingual content is cleaner than separate `_ar`/`_en` columns +2. **Security**: HTML sanitization via `mews/purifier` is properly configured with appropriate allowed tags +3. **Testing**: Comprehensive 30-test suite covering CRUD, authorization, validation, and model behavior +4. **UX**: Auto-save for drafts (60s interval), preview modal, and proper status management +5. **Bilingual Support**: Complete translations in both English and Arabic for all UI strings + +### Refactoring Performed + +None required - code quality is excellent as-is. + +### Compliance Check + +- Coding Standards: ✓ Code follows Laravel/Livewire conventions, uses Volt class-based pattern +- Project Structure: ✓ Files placed correctly in standard locations +- Testing Strategy: ✓ Feature tests using Pest and `Volt::test()` pattern +- All ACs Met: ✓ All 20 acceptance criteria items checked in story file + +### Improvements Checklist + +No mandatory improvements required. Optional considerations for future: + +- [ ] Consider adding delete functionality (not in current AC scope) +- [ ] Consider adding image upload capability for blog posts (not in current AC scope) +- [ ] Consider extracting common Trix editor setup to a reusable Blade component (minor DRY improvement) + +### Requirements Traceability + +| Acceptance Criteria | Test Coverage | Status | +|---------------------|---------------|--------| +| AC1: Title (bilingual) | `admin can create post with valid bilingual content`, `post has bilingual title accessor` | ✓ | +| AC2: Body content (bilingual) | `admin can create post with valid bilingual content`, `post has bilingual body accessor` | ✓ | +| AC3: Status (draft/published) | `save draft preserves draft status`, `publish changes status to published`, `posts list shows status badges` | ✓ | +| AC4-9: Rich Text Editor (bold, italic, headings, lists, links, blockquotes) | `HTML sanitization removes script tags but keeps allowed formatting` | ✓ | +| AC10: Save as draft | `save draft preserves draft status` | ✓ | +| AC11: Preview post | `preview modal can be opened and closed` | ✓ | +| AC12: Edit published posts | `edit existing post updates content` | ✓ | +| AC13: Auto-save (60s) | `auto-save only fires for draft posts`, `auto-save updates draft posts` | ✓ | +| AC14: Immediate publishing | `publish changes status to published` | ✓ | +| AC15-16: Timestamps | Verified in model via `$timestamps = true` | ✓ | +| AC17: HTML sanitization | `HTML sanitization removes script tags but keeps allowed formatting` | ✓ | +| AC18: Bilingual form labels | Verified in `lang/en/posts.php`, `lang/ar/posts.php` | ✓ | +| AC19: Audit log | `admin log created on post create`, `admin log created on post update` | ✓ | +| AC20: Tests for CRUD | 30 comprehensive tests covering all operations | ✓ | + +### Security Review + +**Status: PASS** + +1. **XSS Prevention**: HTML Purifier configured with strict whitelist (`h2,h3,p,br,b,strong,i,em,u,ul,ol,li,a[href|title],blockquote`) +2. **Authorization**: Admin middleware protects all post management routes +3. **CSRF**: Livewire handles CSRF protection automatically +4. **Input Validation**: Server-side validation rules for all fields +5. **Audit Logging**: All create/update actions logged with IP address + +**Security Tests Verified:** +- `non-admin cannot access posts index` +- `non-admin cannot access post creation` +- `non-admin cannot access post edit` +- `guest cannot access posts index` + +### Performance Considerations + +**Status: PASS** + +1. **Auto-save optimization**: Only fires for draft posts, preventing unnecessary database writes +2. **Pagination**: Index page uses Laravel pagination with configurable per-page count +3. **Debounced search**: 300ms debounce on search input prevents excessive queries +4. **No N+1**: No eager loading needed as post data is self-contained + +### Files Modified During Review + +None - no modifications required. + +### Gate Status + +Gate: **PASS** → `docs/qa/gates/5.1-post-creation-editing.yml` + +### Recommended Status + +**✓ Ready for Done** + +All acceptance criteria met, comprehensive test coverage (30 tests), proper security measures in place, and code quality is excellent. Story owner may proceed with marking as Done. diff --git a/lang/ar/common.php b/lang/ar/common.php index 69462e7..2107036 100644 --- a/lang/ar/common.php +++ b/lang/ar/common.php @@ -17,4 +17,5 @@ return [ 'clear' => 'مسح', 'unknown' => 'غير معروف', 'currency' => 'شيكل', + 'close' => 'إغلاق', ]; diff --git a/lang/ar/enums.php b/lang/ar/enums.php index 31f3db5..bb8578b 100644 --- a/lang/ar/enums.php +++ b/lang/ar/enums.php @@ -22,4 +22,8 @@ return [ 'active' => 'نشط', 'archived' => 'مؤرشف', ], + 'post_status' => [ + 'draft' => 'مسودة', + 'published' => 'منشور', + ], ]; diff --git a/lang/ar/posts.php b/lang/ar/posts.php new file mode 100644 index 0000000..2eb0db5 --- /dev/null +++ b/lang/ar/posts.php @@ -0,0 +1,38 @@ + 'المقالات', + 'posts_description' => 'إدارة المقالات والمحتوى القانوني.', + 'create_post' => 'إنشاء مقال', + 'no_posts' => 'لا توجد مقالات.', + 'search_placeholder' => 'البحث في المقالات...', + 'last_updated' => 'آخر تحديث', + 'created' => 'تاريخ الإنشاء', + + // Create/Edit page + 'edit_post' => 'تعديل المقال', + 'back_to_posts' => 'العودة للمقالات', + 'arabic_content' => 'المحتوى العربي', + 'english_content' => 'المحتوى الإنجليزي', + 'title' => 'العنوان', + 'body' => 'المحتوى', + 'arabic' => 'عربي', + 'english' => 'إنجليزي', + 'preview' => 'معاينة', + 'save_draft' => 'حفظ كمسودة', + 'publish' => 'نشر', + 'unpublish' => 'إلغاء النشر', + 'save_changes' => 'حفظ التغييرات', + 'auto_save_enabled' => 'الحفظ التلقائي مفعل', + + // Messages + 'post_saved' => 'تم حفظ المقال بنجاح.', + 'post_deleted' => 'تم حذف المقال بنجاح.', + + // Validation + 'title_ar_required' => 'العنوان العربي مطلوب.', + 'title_en_required' => 'العنوان الإنجليزي مطلوب.', + 'body_ar_required' => 'المحتوى العربي مطلوب.', + 'body_en_required' => 'المحتوى الإنجليزي مطلوب.', +]; diff --git a/lang/en/common.php b/lang/en/common.php index e49cc0f..fba31c2 100644 --- a/lang/en/common.php +++ b/lang/en/common.php @@ -17,4 +17,5 @@ return [ 'clear' => 'Clear', 'unknown' => 'Unknown', 'currency' => 'ILS', + 'close' => 'Close', ]; diff --git a/lang/en/enums.php b/lang/en/enums.php index 6a37c52..45ca092 100644 --- a/lang/en/enums.php +++ b/lang/en/enums.php @@ -22,4 +22,8 @@ return [ 'active' => 'Active', 'archived' => 'Archived', ], + 'post_status' => [ + 'draft' => 'Draft', + 'published' => 'Published', + ], ]; diff --git a/lang/en/posts.php b/lang/en/posts.php new file mode 100644 index 0000000..cceaa68 --- /dev/null +++ b/lang/en/posts.php @@ -0,0 +1,38 @@ + 'Posts', + 'posts_description' => 'Manage blog posts and legal content.', + 'create_post' => 'Create Post', + 'no_posts' => 'No posts found.', + 'search_placeholder' => 'Search posts...', + 'last_updated' => 'Last Updated', + 'created' => 'Created', + + // Create/Edit page + 'edit_post' => 'Edit Post', + 'back_to_posts' => 'Back to Posts', + 'arabic_content' => 'Arabic Content', + 'english_content' => 'English Content', + 'title' => 'Title', + 'body' => 'Body', + 'arabic' => 'Arabic', + 'english' => 'English', + 'preview' => 'Preview', + 'save_draft' => 'Save Draft', + 'publish' => 'Publish', + 'unpublish' => 'Unpublish', + 'save_changes' => 'Save Changes', + 'auto_save_enabled' => 'Auto-save enabled', + + // Messages + 'post_saved' => 'Post saved successfully.', + 'post_deleted' => 'Post deleted successfully.', + + // Validation + 'title_ar_required' => 'Arabic title is required.', + 'title_en_required' => 'English title is required.', + 'body_ar_required' => 'Arabic body content is required.', + 'body_en_required' => 'English body content is required.', +]; diff --git a/resources/views/livewire/admin/posts/create.blade.php b/resources/views/livewire/admin/posts/create.blade.php new file mode 100644 index 0000000..825dafa --- /dev/null +++ b/resources/views/livewire/admin/posts/create.blade.php @@ -0,0 +1,251 @@ + ['required', 'string', 'max:255'], + 'title_en' => ['required', 'string', 'max:255'], + 'body_ar' => ['required', 'string'], + 'body_en' => ['required', 'string'], + 'status' => ['required', 'in:draft,published'], + ]; + } + + public function messages(): array + { + return [ + 'title_ar.required' => __('posts.title_ar_required'), + 'title_en.required' => __('posts.title_en_required'), + 'body_ar.required' => __('posts.body_ar_required'), + 'body_en.required' => __('posts.body_en_required'), + ]; + } + + public function save(): void + { + $validated = $this->validate(); + + $postData = [ + 'title' => [ + 'ar' => $validated['title_ar'], + 'en' => $validated['title_en'], + ], + 'body' => [ + 'ar' => clean($validated['body_ar']), + 'en' => clean($validated['body_en']), + ], + 'status' => $validated['status'], + 'published_at' => $validated['status'] === 'published' ? now() : null, + ]; + + if ($this->post) { + $oldValues = $this->post->toArray(); + $this->post->update($postData); + $action = 'update'; + $newValues = $this->post->fresh()->toArray(); + } else { + $this->post = Post::create($postData); + $action = 'create'; + $oldValues = null; + $newValues = $this->post->toArray(); + } + + AdminLog::create([ + 'admin_id' => auth()->id(), + 'action' => $action, + 'target_type' => 'post', + 'target_id' => $this->post->id, + 'old_values' => $oldValues, + 'new_values' => $newValues, + 'ip_address' => request()->ip(), + 'created_at' => now(), + ]); + + session()->flash('success', __('posts.post_saved')); + + $this->redirect(route('admin.posts.edit', $this->post), navigate: true); + } + + public function saveDraft(): void + { + $this->status = 'draft'; + $this->save(); + } + + public function publish(): void + { + $this->status = 'published'; + $this->save(); + } + + public function autoSave(): void + { + if ($this->post && $this->status === 'draft') { + $this->post->update([ + 'title' => [ + 'ar' => $this->title_ar, + 'en' => $this->title_en, + ], + 'body' => [ + 'ar' => clean($this->body_ar), + 'en' => clean($this->body_en), + ], + ]); + } + } + + public function preview(): void + { + $this->showPreview = true; + } + + public function closePreview(): void + { + $this->showPreview = false; + } +}; ?> + +
+ {{ __('posts.last_updated') }}: {{ $post->updated_at->diffForHumans() }} + @if($status === 'draft') + ({{ __('posts.auto_save_enabled') }}) + @endif +
+{{ __('posts.posts_description') }}
+{{ __('posts.no_posts') }}
+محتوى المقال
') + ->set('body_en', 'Article content
') + ->call('saveDraft') + ->assertHasNoErrors(); + + expect(Post::where('title->en', 'Article Title')->exists())->toBeTrue(); +}); + +test('create post fails with missing required fields', function () { + $this->actingAs($this->admin); + + Volt::test('admin.posts.create') + ->set('title_ar', '') + ->set('title_en', 'Title') + ->set('body_ar', 'content') + ->set('body_en', 'content') + ->call('save') + ->assertHasErrors(['title_ar']); +}); + +test('save draft preserves draft status', function () { + $this->actingAs($this->admin); + + Volt::test('admin.posts.create') + ->set('title_ar', 'عنوان') + ->set('title_en', 'Title') + ->set('body_ar', 'محتوى') + ->set('body_en', 'Content') + ->call('saveDraft'); + + expect(Post::first()->status)->toBe(PostStatus::Draft); +}); + +test('publish changes status to published', function () { + $this->actingAs($this->admin); + + Volt::test('admin.posts.create') + ->set('title_ar', 'عنوان') + ->set('title_en', 'Title') + ->set('body_ar', 'محتوى') + ->set('body_en', 'Content') + ->call('publish'); + + expect(Post::first()->status)->toBe(PostStatus::Published); + expect(Post::first()->published_at)->not->toBeNull(); +}); + +test('HTML sanitization removes script tags but keeps allowed formatting', function () { + $this->actingAs($this->admin); + + Volt::test('admin.posts.create') + ->set('title_ar', 'عنوان') + ->set('title_en', 'Title') + ->set('body_ar', 'نص
') + ->set('body_en', 'Safe
Bold') + ->call('saveDraft'); + + $post = Post::first(); + expect($post->body['en'])->not->toContain('