From 01283b3fe2d61a543c6ff4c394258ed6741fd49f Mon Sep 17 00:00:00 2001 From: Davide Iadeluca Date: Wed, 10 Jan 2024 11:10:35 +0100 Subject: [PATCH] test(Mentions): implement test for rendering post without context --- .../integration/api/PostMentionsTest.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/extensions/mentions/tests/integration/api/PostMentionsTest.php b/extensions/mentions/tests/integration/api/PostMentionsTest.php index 9bb48d8c0c..93ff3dd5f2 100644 --- a/extensions/mentions/tests/integration/api/PostMentionsTest.php +++ b/extensions/mentions/tests/integration/api/PostMentionsTest.php @@ -11,6 +11,8 @@ use Carbon\Carbon; use Flarum\Extend; +use Flarum\Formatter\Formatter; +use Flarum\Post\Post; use Flarum\Post\CommentPost; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; @@ -538,6 +540,40 @@ public function editing_a_post_with_a_mention_of_a_post_with_deleted_author_work $this->assertStringContainsString('PostMention', $response['data']['attributes']['contentHtml']); $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsPosts->find(11)); } + + /** + * @test + */ + public function rendering_post_mention_with_a_post_context_works() + { + /** @var Formatter $formatter */ + $formatter = $this->app()->getContainer()->make(Formatter::class); + + $post = Post::find(4); + $user = User::find(1); + + $xml = $formatter->parse($post->content, $post, $user); + $renderedHtml = $formatter->render($xml, $post); + + $this->assertStringContainsString('TOBY$', $renderedHtml); + } + + /** + * @test + */ + public function rendering_post_mention_without_a_context_works() + { + /** @var Formatter $formatter */ + $formatter = $this->app()->getContainer()->make(Formatter::class); + + $post = Post::find(4); + $user = User::find(1); + + $xml = $formatter->parse($post->content, null, $user); + $renderedHtml = $formatter->render($xml); + + $this->assertStringContainsString('TOBY$', $renderedHtml); + } } class CustomOtherDisplayNameDriver implements DriverInterface