|
4 | 4 |
|
5 | 5 | namespace App\Tests\Unit\Utils;
|
6 | 6 |
|
| 7 | +use App\Entity\Magazine; |
7 | 8 | use App\Markdown\MarkdownConverter;
|
8 | 9 | use App\Markdown\RenderTarget;
|
9 | 10 | use App\Tests\WebTestCase;
|
10 | 11 |
|
| 12 | +use function PHPUnit\Framework\assertStringContainsString; |
| 13 | + |
11 | 14 | class MarkdownTest extends WebTestCase
|
12 | 15 | {
|
13 | 16 | public function testMagazineLinks(): void
|
@@ -89,4 +92,64 @@ public function testExternalMentionLink(): void
|
89 | 92 | // assert that this community does not exist, and we get a search link for it that does not link to the external instance
|
90 | 93 | self::assertStringContainsString('https://kbin.test2', $markdown);
|
91 | 94 | }
|
| 95 | + |
| 96 | + public function testExternalMagazineLocalEntryLink(): void |
| 97 | + { |
| 98 | + $m = new Magazine( '[email protected]', 'test', null, null, null, false, false, null); |
| 99 | + |
| 100 | + $m->apInboxUrl = 'https://kbin.test2/inbox'; |
| 101 | + $m->apPublicUrl = 'https://kbin.test2/m/test'; |
| 102 | + $m->apProfileId = 'https://kbin.test2/m/test'; |
| 103 | + $this->entityManager->persist($m); |
| 104 | + $entry = $this->getEntryByTitle('test', magazine: $m); |
| 105 | + $this->entityManager->flush(); |
| 106 | + $text = "Look at my post at https://kbin.test/m/[email protected]/t/{$entry->getId()}/some-slug"; |
| 107 | + $markdown = $this->markdownConverter->convertToHtml($text, [MarkdownConverter::RENDER_TARGET => RenderTarget::Page]); |
| 108 | + assertStringContainsString('entry-inline', $markdown); |
| 109 | + } |
| 110 | + |
| 111 | + public function testExternalMagazineLocalPostLink(): void |
| 112 | + { |
| 113 | + $m = new Magazine( '[email protected]', 'test', null, null, null, false, false, null); |
| 114 | + |
| 115 | + $m->apInboxUrl = 'https://kbin.test2/inbox'; |
| 116 | + $m->apPublicUrl = 'https://kbin.test2/m/test'; |
| 117 | + $m->apProfileId = 'https://kbin.test2/m/test'; |
| 118 | + $this->entityManager->persist($m); |
| 119 | + $post = $this->createPost('test', magazine: $m); |
| 120 | + $this->entityManager->flush(); |
| 121 | + $text = "Look at my post at https://kbin.test/m/[email protected]/p/{$post->getId()}/some-slug"; |
| 122 | + $markdown = $this->markdownConverter->convertToHtml($text, [MarkdownConverter::RENDER_TARGET => RenderTarget::Page]); |
| 123 | + assertStringContainsString('post-inline', $markdown); |
| 124 | + } |
| 125 | + |
| 126 | + public function testLocalNotMatchingUrl(): void |
| 127 | + { |
| 128 | + $m = new Magazine( '[email protected]', 'test', null, null, null, false, false, null); |
| 129 | + |
| 130 | + $m->apInboxUrl = 'https://kbin.test2/inbox'; |
| 131 | + $m->apPublicUrl = 'https://kbin.test2/m/test'; |
| 132 | + $m->apProfileId = 'https://kbin.test2/m/test'; |
| 133 | + $this->entityManager->persist($m); |
| 134 | + $entry = $this->getEntryByTitle('test', magazine: $m); |
| 135 | + $this->entityManager->flush(); |
| 136 | + $text = "Look at my post at https://kbin.test/m/[email protected]/t/{$entry->getId()}/some-slug/votes"; |
| 137 | + $markdown = $this->markdownConverter->convertToHtml($text, [MarkdownConverter::RENDER_TARGET => RenderTarget::Page]); |
| 138 | + assertStringContainsString( "https://kbin.test/m/[email protected]/t/{$entry->getId()}/some-slug/votes", $markdown); |
| 139 | + } |
| 140 | + |
| 141 | + public function testBracketsInLinkTitle(): void |
| 142 | + { |
| 143 | + $m = new Magazine( '[email protected]', 'test', null, null, null, false, false, null); |
| 144 | + |
| 145 | + $m->apInboxUrl = 'https://kbin.test2/inbox'; |
| 146 | + $m->apPublicUrl = 'https://kbin.test2/m/test'; |
| 147 | + $m->apProfileId = 'https://kbin.test2/m/test'; |
| 148 | + $this->entityManager->persist($m); |
| 149 | + $entry = $this->getEntryByTitle('test', magazine: $m); |
| 150 | + $this->entityManager->flush(); |
| 151 | + $text = "[Look at my post (or not, your choice)](https://kbin.test/m/[email protected]/t/{$entry->getId()}/some-slug/favourites)"; |
| 152 | + $markdown = $this->markdownConverter->convertToHtml($text, [MarkdownConverter::RENDER_TARGET => RenderTarget::Page]); |
| 153 | + assertStringContainsString( "https://kbin.test/m/[email protected]/t/{$entry->getId()}/some-slug/favourites", $markdown); |
| 154 | + } |
92 | 155 | }
|
0 commit comments