<?php
+namespace Shaarli\Plugin\Markdown;
+
use Shaarli\Config\ConfigManager;
+use Shaarli\Plugin\PluginManager;
/**
* PluginMarkdownTest.php
*/
+require_once 'application/bookmark/LinkUtils.php';
require_once 'application/Utils.php';
require_once 'plugins/markdown/markdown.php';
* Class PluginMarkdownTest
* Unit test for the Markdown plugin
*/
-class PluginMarkdownTest extends PHPUnit_Framework_TestCase
+class PluginMarkdownTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ConfigManager instance.
$data = hook_markdown_render_linklist($data, $this->conf);
$this->assertNotFalse(strpos($data['links'][0]['description'], '<h1>'));
$this->assertNotFalse(strpos($data['links'][0]['description'], '<p>'));
+
+ $this->assertEquals($markdown, $data['links'][0]['description_src']);
+ }
+
+ /**
+ * Test render_feed hook.
+ */
+ public function testMarkdownFeed()
+ {
+ $markdown = '# My title' . PHP_EOL . 'Very interesting content.';
+ $markdown .= '— <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(
+ '— <a href="http://domain.tld/?0oc_VQ">Permalien</a></p></div>',
+ $data['links'][0]['description']
+ );
}
/**
public function testReverseText2clickable()
{
$text = 'stuff http://hello.there/is=someone#here otherstuff';
- $clickableText = text2clickable($text, '');
+ $clickableText = text2clickable($text);
$reversedText = reverse_text2clickable($clickableText);
$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().
*/
$this->assertEquals($text, $reversedText);
}
+ public function testReverseFeedPermalink()
+ {
+ $text = 'Description... ';
+ $text .= '— <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>';
+ $expected = 'Description... — [Permalien](http://domain.tld/?0oc_VQ)';
+ $processedText = reverse_feed_permalink($text);
+
+ $this->assertEquals($expected, $processedText);
+ }
+
+ public function testReverseLastFeedPermalink()
+ {
+ $text = 'Description... ';
+ $text .= '<br>— <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>';
+ $expected = $text;
+ $text .= '<br>— <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>';
+ $expected .= '<br>— [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().
*/
$this->conf->get('security.markdown_escape', true),
$this->conf->get('security.allowed_protocols')
);
- $this->assertEquals($html, $data);
+ $this->assertEquals($html, $data . PHP_EOL);
}
/**