diff options
author | Julien Veyssier <eneiluj@posteo.net> | 2021-12-28 19:49:46 +0300 |
---|---|---|
committer | Julien Veyssier <eneiluj@posteo.net> | 2022-01-03 12:27:39 +0300 |
commit | e628527c8a913d0ec6c3fcb69955822d400cf601 (patch) | |
tree | 98d570577b91c2c314bd1ade3487a878ace283dd /tests | |
parent | dc92e028c2ecc2eca18ec1c045f16fd78b9eed35 (diff) |
improve image link generation and getAttachmentNamesFromContent(), implement basic tests
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/TextTest.php | 25 |
1 files changed, 25 insertions, 0 deletions
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); + } + } } |