sidebar.t 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/env perl
  2. # Copyright (C) 2006–2016 Alex Schroeder <alex@gnu.org>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. require 't/test.pl';
  17. package OddMuse;
  18. use Test::More tests => 9;
  19. # basic test
  20. add_module('sidebar.pl');
  21. test_page(update_page($SidebarName, 'mu'), '<div class="sidebar"><p>mu</p></div>');
  22. test_page(get_page('HomePage'), '<div class="sidebar"><p>mu</p></div>');
  23. # with images
  24. add_module('image.pl');
  25. # enable uploads
  26. AppendStringToFile($ConfigFile, "\$UploadAllowed = 1;\n");
  27. update_page('pic', "#FILE image/png\niVBORw0KGgoAAAA");
  28. xpath_test(update_page($SidebarName, '[[image:pic|picture|Target]]'),
  29. '//div[@class="sidebar"]/p/a[@class="image"][@href="http://localhost/wiki.pl/Target"]/img[@class="upload"][@src="http://localhost/wiki.pl/download/pic"][@alt="picture"]');
  30. # with static-copy
  31. add_module('static-copy.pl');
  32. AppendStringToFile($ConfigFile, q{
  33. $StaticAlways = 1;
  34. $StaticDir = $DataDir . '/static';
  35. $StaticUrl = '/static/';
  36. %StaticMimeTypes = ('image/png' => 'png', );
  37. @UploadTypes = ('image/png', );
  38. });
  39. update_page('pic', "DeletedPage");
  40. update_page('pic', "#FILE image/png\niVBORw0KGgoAAAA", undef, 0, 1);
  41. ok(-f "$DataDir/static/pic.png", "$DataDir/static/pic.png exists");
  42. xpath_test(update_page($SidebarName, '[[image:pic|a picture|Target]]'),
  43. '//div[@class="sidebar"]/p/a[@class="image"][@href="http://localhost/wiki.pl/Target"]/img[@class="upload"][@src="/static/pic.png"][@alt="a picture"]');
  44. # with forms
  45. add_module('forms.pl');
  46. # Markup the sidebar page prior to locking the sidebar page. This should ensure
  47. # that forms on that page are not interpreted.
  48. test_page(update_page($SidebarName, '<form><h1>mu</h1></form>'),
  49. '<div class="sidebar"><p>&lt;form&gt;&lt;h1&gt;mu&lt;/h1&gt;&lt;/form&gt;</p></div>');
  50. # Lock the sidebar page, mark it up again, and ensure that forms on that page
  51. # are now interpreted.
  52. xpath_test(get_page("action=pagelock id=$SidebarName set=1 pwd=foo"),
  53. '//p/text()[string()="Lock for "]/following-sibling::a[@href="http://localhost/wiki.pl/SideBar"][@class="local"][text()="SideBar"]/following-sibling::text()[string()=" created."]');
  54. test_page(get_page("action=browse id=$SidebarName cache=0"), #update_page($SidebarName, '<form><h1>mu</h1></form>'),
  55. '<div class="sidebar"><form><h1>mu</h1></form></div>');
  56. # While rendering the SideBar as part of the HomePage, it should still
  57. # be considered "locked", and therefore the form should render
  58. # correctly.
  59. test_page(get_page('HomePage'),
  60. '<div class="sidebar"><form><h1>mu</h1></form></div>');
  61. # FIXME: Due to the recent refactoring of the Table of Contents module, the
  62. # Sidebar module is now known **not** to work as expected with that module.
  63. # This would appear to be an unavoidable consequence of that refactoring... The
  64. # Sidebar module, as currently implemented, **cannot** be made to work with the
  65. # Table of Contents module. As such, we disable all prior tests against the
  66. # Table of Contents module. It's hardly ideal. (But then, what is?)
  67. # with toc
  68. # add_module('toc.pl');
  69. # add_module('usemod.pl');
  70. # AppendStringToFile($ConfigFile, "\$TocAutomatic = 0;\n");
  71. # update_page($SidebarName, "bla\n\n"
  72. # . "== mu ==\n\n"
  73. # . "bla");
  74. # test_page(update_page('test', "bla\n"
  75. # . "<toc>\n"
  76. # . "murks\n"
  77. # . "==two=\n"
  78. # . "bla\n"
  79. # . "===three==\n"
  80. # . "bla\n"
  81. # . "=one=\n"),
  82. # quotemeta(qq{<ol><li><a href="#${TocAnchorPrefix}1">two</a><ol><li><a href="#${TocAnchorPrefix}2">three</a></li></ol></li><li><a href="#${TocAnchorPrefix}3">one</a></li></ol>}),
  83. # quotemeta('<h2>mu</h2>'),
  84. # quotemeta(qq{<h2 id="${TocAnchorPrefix}1">two</h2>}),
  85. # quotemeta(qq{<h2 id="${TocAnchorPrefix}3">one</h2>}),
  86. # quotemeta('bla </p><div class="toc"><h2>Contents</h2><ol><li><a '),
  87. # quotemeta('one</a></li></ol></div><p>murks'));
  88. # update_page($SidebarName, "<toc>");
  89. # test_page(update_page('test', "bla\n"
  90. # . "murks\n"
  91. # . "==two=\n"
  92. # . "bla\n"
  93. # . "===three==\n"
  94. # . "bla\n"
  95. # . "=one=\n"),
  96. # quotemeta(qq{<ol><li><a href="#${TocAnchorPrefix}1">two</a><ol><li><a href="#${TocAnchorPrefix}2">three</a></li></ol></li><li><a href="#${TocAnchorPrefix}3">one</a></li></ol>}),
  97. # quotemeta(qq{<h2 id="${TocAnchorPrefix}1">two</h2>}),
  98. # quotemeta(qq{<h2 id="${TocAnchorPrefix}3">one</h2>}),
  99. # quotemeta('<div class="content browse"><div class="sidebar"><div class="toc"><h2>Contents</h2><ol><li><a '),
  100. # quotemeta('one</a></li></ol></div></div><p>'));
  101. # remove_rule(\&TocRule);
  102. # remove_rule(\&UsemodRule);