|
2 | 2 |
|
3 | 3 | namespace Tonysm\RichTextLaravel\Tests; |
4 | 4 |
|
| 5 | +use Illuminate\Support\Facades\Log; |
| 6 | +use Tonysm\RichTextLaravel\Attachables\ContentAttachment; |
5 | 7 | use Tonysm\RichTextLaravel\Attachables\MissingAttachable; |
6 | 8 | use Tonysm\RichTextLaravel\Attachables\RemoteImage; |
7 | 9 | use Tonysm\RichTextLaravel\Attachment; |
@@ -208,6 +210,8 @@ public function converts_trix_formatetd_attachments_with_custom_tag_name() |
208 | 210 | /** @test */ |
209 | 211 | public function ignores_trix_formatteed_attachments_with_bad_json() |
210 | 212 | { |
| 213 | + Log::shouldReceive('notice')->once(); |
| 214 | + |
211 | 215 | $html = <<<'HTML' |
212 | 216 | <div data-trix-attachment='{"sgid": "pure garbate...}'></div> |
213 | 217 | HTML; |
@@ -505,44 +509,28 @@ public function renders_file_attachments() |
505 | 509 | } |
506 | 510 |
|
507 | 511 | /** @test */ |
508 | | - public function renders_horizontal_rules_as_content_attachment() |
| 512 | + public function renders_html_content_attachment() |
509 | 513 | { |
510 | | - $content = $this->fromHtml(<<<'HTML' |
511 | | - <div> |
512 | | - <figure |
513 | | - data-trix-attachment='{"contentType": "vnd.richtextlaravel.horizontal-rule.html", "content": "<hr>"}' |
514 | | - > |
515 | | - <hr> |
516 | | - </figure> |
517 | | - </div> |
518 | | - HTML); |
| 514 | + $attachment = $this->attachmentFromHtml('<rich-text-attachment content-type="text/html" content="abc"></rich-text-attachment>'); |
| 515 | + $attachable = $attachment->attachable; |
519 | 516 |
|
520 | | - $this->assertEquals(<<<'HTML' |
521 | | - <div> |
522 | | - <hr> |
| 517 | + $this->assertInstanceOf(ContentAttachment::class, $attachable); |
| 518 | + $this->assertEquals('text/html', $attachable->contentType); |
| 519 | + $this->assertEquals('abc', $attachable->content); |
523 | 520 |
|
524 | | - </div> |
525 | | - HTML, $content->renderWithAttachments()); |
| 521 | + $trixAttachment = $attachment->toTrixAttachment(); |
| 522 | + $this->assertEquals('text/html', $trixAttachment->attributes()['contentType']); |
| 523 | + $this->assertEquals('abc', $trixAttachment->attributes()['content']); |
526 | 524 | } |
527 | 525 |
|
528 | 526 | /** @test */ |
529 | | - public function renders_horizontal_rules_for_trix() |
| 527 | + public function renders_content_attachment() |
530 | 528 | { |
531 | | - $content = $this->fromHtml(<<<'HTML' |
532 | | - <div> |
533 | | - <figure |
534 | | - data-trix-attachment='{"contentType": "vnd.richtextlaravel.horizontal-rule.html", "content": "<hr>"}' |
535 | | - > |
536 | | - <hr> |
537 | | - </figure> |
538 | | - </div> |
539 | | - HTML); |
| 529 | + $attachment = $this->attachmentFromHtml('<rich-text-attachment content-type="text/html" content="<p>abc</p>"></rich-text-attachment>'); |
| 530 | + /** @var ContentAttachment $attachable */ |
| 531 | + $attachable = $attachment->attachable; |
540 | 532 |
|
541 | | - $this->assertEquals(<<<'HTML' |
542 | | - <div> |
543 | | - <figure data-trix-attachment='{"contentType":"vnd.richtextlaravel.horizontal-rule.html","content":"<hr>\n"}'></figure> |
544 | | - </div> |
545 | | - HTML, $content->toTrixHtml()); |
| 533 | + $this->assertEquals('<p>abc</p>', $attachable->renderTrixContentAttachment()); |
546 | 534 | } |
547 | 535 |
|
548 | 536 | /** @test */ |
@@ -584,6 +572,11 @@ private function fromHtml(string $html): Content |
584 | 572 | { |
585 | 573 | return tap(new Content($html), fn (Content $content) => $this->assertNotEmpty($content->toHtml())); |
586 | 574 | } |
| 575 | + |
| 576 | + private function attachmentFromHtml(string $html): Attachment |
| 577 | + { |
| 578 | + return $this->fromHtml($html)->attachments()->first(); |
| 579 | + } |
587 | 580 | } |
588 | 581 |
|
589 | 582 | class UserWithCustomRenderContent extends User |
|
0 commit comments