Skip to content

Commit 487912d

Browse files
test(Mentions): implement test for rendering post without context
1 parent 00166cb commit 487912d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

extensions/mentions/tests/integration/api/PostMentionsTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
use Carbon\Carbon;
1313
use Flarum\Extend;
14+
use Flarum\Formatter\Formatter;
15+
use Flarum\Post\Post;
1416
use Flarum\Post\CommentPost;
1517
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
1618
use Flarum\Testing\integration\TestCase;
@@ -538,6 +540,41 @@ public function editing_a_post_with_a_mention_of_a_post_with_deleted_author_work
538540
$this->assertStringContainsString('PostMention', $response['data']['attributes']['contentHtml']);
539541
$this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsPosts->find(11));
540542
}
543+
544+
/**
545+
* @test
546+
*/
547+
public function rendering_post_mention_with_a_post_context_works()
548+
{
549+
/** @var Formatter $formatter */
550+
$formatter = $this->app()->getContainer()->make(Formatter::class);
551+
552+
$post = Post::find(4);
553+
$user = User::find(1);
554+
555+
$xml = $formatter->parse($post->content, $post, $user);
556+
$renderedHtml = $formatter->render($xml, $post);
557+
558+
$this->assertStringContainsString('TOBY$', $renderedHtml);
559+
}
560+
561+
/**
562+
* @test
563+
*/
564+
public function rendering_post_mention_without_a_context_works()
565+
{
566+
/** @var Formatter $formatter */
567+
$formatter = $this->app()->getContainer()->make(Formatter::class);
568+
569+
$post = Post::find(4);
570+
$user = User::find(1);
571+
572+
$xml = $formatter->parse($post->content, null, $user);
573+
$renderedHtml = $formatter->render($xml);
574+
575+
$this->assertStringContainsString('TOBY$', $renderedHtml);
576+
}
577+
541578
}
542579

543580
class CustomOtherDisplayNameDriver implements DriverInterface

0 commit comments

Comments
 (0)