From e628527c8a913d0ec6c3fcb69955822d400cf601 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Tue, 28 Dec 2021 17:49:46 +0100 Subject: improve image link generation and getAttachmentNamesFromContent(), implement basic tests Signed-off-by: Julien Veyssier --- tests/TextTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests') diff --git a/tests/TextTest.php b/tests/TextTest.php index 79376212e..aeaa8d0cc 100644 --- a/tests/TextTest.php +++ b/tests/TextTest.php @@ -3,10 +3,35 @@ namespace OCA\Text\Tests; use OCA\Text\AppInfo\Application; +use OCA\Text\Service\ImageService; class TextTest extends \PHPUnit\Framework\TestCase { public function testDummy() { $app = new Application(); $this->assertEquals('text', $app::APP_NAME); } + + public function testGetAttachmentNamesFromContent() { + $contentNames = [ + 'aaa.png', + 'a[a]a.png', + 'a(a)a.png', + 'a](a.png', + ',;:!?.ยง-_a_', + 'a`a`.png', + ]; + $content = "some content\n"; + foreach ($contentNames as $name) { + // this is how it's generated in MenuBar.vue + $linkText = preg_replace('/[[\]]/', '', $name); + $encodedName = urlencode($name); + $content .= '![' . $linkText . '](text://image?imageFileName=' . $encodedName . ")\n"; + } + $content .= 'some content'; + + $computedNames = ImageService::getAttachmentNamesFromContent($content); + foreach ($contentNames as $contentName) { + $this->assertContains($contentName, $computedNames); + } + } } -- cgit v1.2.3