4 * PluginMarkdownTest.php
7 require_once 'application/Utils.php';
8 require_once 'plugins/markdown/markdown.php';
11 * Class PlugQrcodeTest
12 * Unit test for the QR-Code plugin
14 class PluginMarkdownTest
extends PHPUnit_Framework_TestCase
21 PluginManager
::$PLUGINS_PATH = 'plugins';
25 * Test render_linklist hook.
26 * Only check that there is basic markdown rendering.
28 function testMarkdownLinklist()
30 $markdown = '# My title' . PHP_EOL
. 'Very interesting content.';
34 'description' => $markdown,
39 $data = hook_markdown_render_linklist($data);
40 $this->assertNotFalse(strpos($data['links'][0]['description'], '<h1>'));
41 $this->assertNotFalse(strpos($data['links'][0]['description'], '<p>'));
45 * Test render_daily hook.
46 * Only check that there is basic markdown rendering.
48 function testMarkdownDaily()
50 $markdown = '# My title' . PHP_EOL
. 'Very interesting content.';
54 // First, second, third.
58 'formatedDescription' => $markdown,
64 $data = hook_markdown_render_daily($data);
65 $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<h1>'));
66 $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<p>'));
70 * Test reverse_text2clickable().
72 function testReverseText2clickable()
74 $text = 'stuff http://hello.there/is=someone#here otherstuff';
75 $clickableText = text2clickable($text, '');
76 $reversedText = reverse_text2clickable($clickableText);
77 $this->assertEquals($text, $reversedText);
81 * Test reverse_nl2br().
83 function testReverseNl2br()
85 $text = 'stuff' . PHP_EOL
. 'otherstuff';
86 $processedText = nl2br($text);
87 $reversedText = reverse_nl2br($processedText);
88 $this->assertEquals($text, $reversedText);
92 * Test reverse_space2nbsp().
94 function testReverseSpace2nbsp()
96 $text = ' stuff' . PHP_EOL
. ' otherstuff and another';
97 $processedText = space2nbsp($text);
98 $reversedText = reverse_space2nbsp($processedText);
99 $this->assertEquals($text, $reversedText);
103 * Test sanitize_html().
105 function testSanitizeHtml() {
106 $input = '< script src="js.js"/>';
107 $input .= '< script attr>alert(\'xss\');</script>';
108 $input .= '<style> * { display: none }</style>';
109 $output = escape($input);
110 $input .= '<a href="#" onmouseHover="alert(\'xss\');" attr="tt">link</a>';
111 $output .= '<a href="#" attr="tt">link</a>';
112 $this->assertEquals($output, sanitize_html($input));
113 // Do not touch escaped HTML.
114 $input = escape($input);
115 $this->assertEquals($input, sanitize_html($input));