PluginMarkdownTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * PluginMarkdownTest.php
  4. */
  5. require_once 'application/Utils.php';
  6. require_once 'plugins/markdown/markdown.php';
  7. /**
  8. * Class PlugQrcodeTest
  9. * Unit test for the QR-Code plugin
  10. */
  11. class PluginMarkdownTest extends PHPUnit_Framework_TestCase
  12. {
  13. /**
  14. * Reset plugin path
  15. */
  16. function setUp()
  17. {
  18. PluginManager::$PLUGINS_PATH = 'plugins';
  19. }
  20. /**
  21. * Test render_linklist hook.
  22. * Only check that there is basic markdown rendering.
  23. */
  24. function testMarkdownLinklist()
  25. {
  26. $markdown = '# My title' . PHP_EOL . 'Very interesting content.';
  27. $data = array(
  28. 'links' => array(
  29. 0 => array(
  30. 'description' => $markdown,
  31. ),
  32. ),
  33. );
  34. $data = hook_markdown_render_linklist($data);
  35. $this->assertNotFalse(strpos($data['links'][0]['description'], '<h1>'));
  36. $this->assertNotFalse(strpos($data['links'][0]['description'], '<p>'));
  37. }
  38. /**
  39. * Test render_daily hook.
  40. * Only check that there is basic markdown rendering.
  41. */
  42. function testMarkdownDaily()
  43. {
  44. $markdown = '# My title' . PHP_EOL . 'Very interesting content.';
  45. $data = array(
  46. // Columns data
  47. 'cols' => array(
  48. // First, second, third.
  49. 0 => array(
  50. // nth link
  51. 0 => array(
  52. 'formatedDescription' => $markdown,
  53. ),
  54. ),
  55. ),
  56. );
  57. $data = hook_markdown_render_daily($data);
  58. $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<h1>'));
  59. $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<p>'));
  60. }
  61. /**
  62. * Test reverse_text2clickable().
  63. */
  64. function testReverseText2clickable()
  65. {
  66. $text = 'stuff http://hello.there/is=someone#here otherstuff';
  67. $clickableText = text2clickable($text, '');
  68. $reversedText = reverse_text2clickable($clickableText);
  69. $this->assertEquals($text, $reversedText);
  70. }
  71. /**
  72. * Test reverse_nl2br().
  73. */
  74. function testReverseNl2br()
  75. {
  76. $text = 'stuff' . PHP_EOL . 'otherstuff';
  77. $processedText = nl2br($text);
  78. $reversedText = reverse_nl2br($processedText);
  79. $this->assertEquals($text, $reversedText);
  80. }
  81. /**
  82. * Test reverse_space2nbsp().
  83. */
  84. function testReverseSpace2nbsp()
  85. {
  86. $text = ' stuff' . PHP_EOL . ' otherstuff and another';
  87. $processedText = space2nbsp($text);
  88. $reversedText = reverse_space2nbsp($processedText);
  89. $this->assertEquals($text, $reversedText);
  90. }
  91. /**
  92. * Test reset_quote_tags()
  93. */
  94. function testResetQuoteTags()
  95. {
  96. $text = '> quote1'. PHP_EOL . ' > quote2 ' . PHP_EOL . 'noquote';
  97. $processedText = escape($text);
  98. $reversedText = reset_quote_tags($processedText);
  99. $this->assertEquals($text, $reversedText);
  100. }
  101. }