]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/plugins/PluginMarkdownTest.php
Fix hashtags with markdown escape enabled
[github/shaarli/Shaarli.git] / tests / plugins / PluginMarkdownTest.php
index ddc2728d3ae22542f82dd9bd158de7a1bab73ec0..319a94ba835ccfaeadfc917e487d35cb7a584165 100644 (file)
@@ -49,6 +49,30 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
         $this->assertNotFalse(strpos($data['links'][0]['description'], '<p>'));
     }
 
+    /**
+     * Test render_feed hook.
+     */
+    public function testMarkdownFeed()
+    {
+        $markdown = '# My title' . PHP_EOL . 'Very interesting content.';
+        $markdown .= '&#8212; <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>';
+        $data = array(
+            'links' => array(
+                0 => array(
+                    'description' => $markdown,
+                ),
+            ),
+        );
+
+        $data = hook_markdown_render_feed($data, $this->conf);
+        $this->assertNotFalse(strpos($data['links'][0]['description'], '<h1>'));
+        $this->assertNotFalse(strpos($data['links'][0]['description'], '<p>'));
+        $this->assertStringEndsWith(
+            '&#8212; <a href="http://domain.tld/?0oc_VQ">Permalien</a></p></div>',
+            $data['links'][0]['description']
+        );
+    }
+
     /**
      * Test render_daily hook.
      * Only check that there is basic markdown rendering.
@@ -82,6 +106,18 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
         $this->assertEquals($text, $reversedText);
     }
 
+    /**
+     * Test reverse_text2clickable().
+     */
+    public function testReverseText2clickableHashtags()
+    {
+        $text = file_get_contents('tests/plugins/resources/hashtags.raw');
+        $md = file_get_contents('tests/plugins/resources/hashtags.md');
+        $clickableText = hashtag_autolink($text);
+        $reversedText = reverse_text2clickable($clickableText);
+        $this->assertEquals($md, $reversedText);
+    }
+
     /**
      * Test reverse_nl2br().
      */
@@ -104,6 +140,37 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
         $this->assertEquals($text, $reversedText);
     }
 
+    public function testReverseFeedPermalink()
+    {
+        $text = 'Description... ';
+        $text .= '&#8212; <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>';
+        $expected = 'Description... &#8212; [Permalien](http://domain.tld/?0oc_VQ)';
+        $processedText = reverse_feed_permalink($text);
+
+        $this->assertEquals($expected, $processedText);
+    }
+
+    public function testReverseLastFeedPermalink()
+    {
+        $text = 'Description... ';
+        $text .= '<br>&#8212; <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>';
+        $expected = $text;
+        $text .= '<br>&#8212; <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>';
+        $expected .= '<br>&#8212; [Permalien](http://domain.tld/?0oc_VQ)';
+        $processedText = reverse_feed_permalink($text);
+
+        $this->assertEquals($expected, $processedText);
+    }
+
+    public function testReverseNoFeedPermalink()
+    {
+        $text = 'Hello! Where are you from?';
+        $expected = $text;
+        $processedText = reverse_feed_permalink($text);
+
+        $this->assertEquals($expected, $processedText);
+    }
+
     /**
      * Test sanitize_html().
      */
@@ -191,7 +258,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
             $this->conf->get('security.markdown_escape', true),
             $this->conf->get('security.allowed_protocols')
         );
-        $this->assertEquals($html, $data);
+        $this->assertEquals($html, $data . PHP_EOL);
     }
 
     /**