crossbar.t 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/usr/bin/env perl
  2. # ====================[ crossbar.t ]====================
  3. # ....................{ INITIALIZATION }....................
  4. require 't/test.pl';
  5. package OddMuse;
  6. use Test::More tests => 22;
  7. add_module('crossbar.pl');
  8. # The crossbar page is editable only by administrators. Consequently, we enable
  9. # the administrator option when calling the update_page() function on the
  10. # crossbar page.
  11. my @update_crossbar_page_options = ('', '', 1);
  12. # ....................{ TESTS =vanilla }....................
  13. test_page(update_page($CrossbarPageName, 'mu', @update_crossbar_page_options),
  14. '<div class="crossbar"><p>mu</p></div>');
  15. test_page(get_page('HomePage'), '<div class="crossbar"><p>mu</p></div>');
  16. # Verify that raw pages are not mangled
  17. $page = get_page('action=browse raw=1 id=SomePage');
  18. test_page($page, 'This page does not exist');
  19. test_page_negative($page, 'mu');
  20. # Verify that images pages are not mangled
  21. AppendStringToFile($ConfigFile, "\$UploadAllowed = 1;\n");
  22. test_page(update_page('Alex', "#FILE image/png\niVBORw0KGgoAAAA"),
  23. 'This page contains an uploaded file:');
  24. {
  25. local $raw = 1;
  26. $page = get_page('action=download id=Alex');
  27. }
  28. $page =~ s/^.*\r\n\r\n//s; # strip headers
  29. require MIME::Base64;
  30. test_page(MIME::Base64::encode($page), '^iVBORw0KGgoAAAA');
  31. # ....................{ TESTS =sidebar }....................
  32. add_module('sidebar.pl');
  33. update_page('SideBar', 'mysidebar');
  34. update_page('Crossbar', 'mycrossbar');
  35. $page = get_page('HomePage');
  36. xpath_test($page,
  37. '//div[@class="sidebar"]/p[text()="mysidebar"]',
  38. '//div[@class="crossbar"]/p[text()="mycrossbar"]');
  39. # verify that these two are not nested
  40. negative_xpath_test($page,
  41. '//div[@class="sidebar"]/div[@class="crossbar"]',
  42. '//div[@class="crossbar"]/div[@class="sidebar"]');
  43. # uninstall sidebar.pl
  44. remove_module('sidebar.pl');
  45. *GetHeader = \&OldSideBarGetHeader;
  46. # ....................{ TESTS =toc }....................
  47. add_module('toc.pl');
  48. add_module('usemod.pl');
  49. AppendStringToFile($ConfigFile, "\$TocAutomatic = 0;\n");
  50. # Test a crossbar page without Table of Contents markup and a page with Table of
  51. # Contents markup.
  52. update_page($CrossbarPageName, "bla
  53. == mu ==
  54. bla", @update_crossbar_page_options);
  55. test_page(update_page('test', "bla
  56. <toc>
  57. murks
  58. ==two==
  59. bla
  60. ===three===
  61. bla
  62. =one="),
  63. quotemeta(qq{<div class="crossbar"><p>bla</p><h2>mu</h2>}),
  64. quotemeta(qq{bla </p><div class="toc"><h2>$TocHeaderText</h2>}),
  65. 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>}),
  66. quotemeta(qq{one</a></li></ol></div><p>murks}));
  67. quotemeta(qq{<h2 id="${TocAnchorPrefix}1">two</h2>}),
  68. quotemeta(qq{<h2 id="${TocAnchorPrefix}3">one</h2>}),
  69. # Test a crossbar page with Table of Contents markup and a page without Table of
  70. # Contents markup.
  71. update_page($CrossbarPageName, "bla
  72. == mu ==
  73. bla
  74. <toc>", @update_crossbar_page_options);
  75. test_page(update_page('test', "bla
  76. murks
  77. ==two==
  78. bla
  79. ===three===
  80. bla
  81. =one="),
  82. quotemeta(qq{<div class="crossbar"><p>bla</p><h2>mu</h2>}),
  83. quotemeta(qq{<p>bla </p><div class="toc"><h2>$TocHeaderText</h2>}),
  84. 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>}),
  85. quotemeta(qq{one</a></li></ol></div></div><div class="content browse"><p>bla}));
  86. quotemeta(qq{<h2 id="${TocAnchorPrefix}1">two</h2>}),
  87. quotemeta(qq{<h2 id="${TocAnchorPrefix}3">one</h2>}),
  88. remove_rule(\&TocRule);
  89. remove_rule(\&UsemodRule);
  90. # ....................{ TESTS =forms }....................
  91. add_module('forms.pl');
  92. # Markup the crossbar page prior to locking the crossbar page. This should ensure
  93. # that forms on that page are not interpreted.
  94. test_page(update_page($CrossbarPageName,
  95. '<form><h1>mu</h1></form>', @update_crossbar_page_options),
  96. '<div class="crossbar"><p>&lt;form&gt;&lt;h1&gt;mu&lt;/h1&gt;&lt;/form&gt;</p></div>');
  97. # Lock the crossbar page, mark it up again, and ensure that forms on that page
  98. # are now interpreted.
  99. xpath_test(get_page("action=pagelock id=$CrossbarPageName set=1 pwd=foo"),
  100. '//p/text()[string()="Lock for "]/following-sibling::a[@href="http://localhost/wiki.pl/Crossbar"][@class="local"][text()="Crossbar"]/following-sibling::text()[string()=" created."]');
  101. test_page(get_page("action=browse id=$CrossbarPageName cache=0"),
  102. '<div class="crossbar"><form><h1>mu</h1></form></div>');
  103. # While rendering the Crossbar as part of the HomePage, it should still
  104. # be considered "locked", and therefore the form should render
  105. # correctly.
  106. test_page(get_page('HomePage'),
  107. '<div class="crossbar"><form><h1>mu</h1></form></div>');
  108. =head1 COPYRIGHT AND LICENSE
  109. The information below applies to everything in this distribution,
  110. except where noted.
  111. Copyleft 2008 by B.w.Curry <http://www.raiazome.com>.
  112. Copyright (C) 2008 Alex Schroeder <alex@gnu.org>
  113. This program is free software; you can redistribute it and/or modify
  114. it under the terms of the GNU General Public License as published by
  115. the Free Software Foundation; either version 3 of the License, or
  116. (at your option) any later version.
  117. This program is distributed in the hope that it will be useful,
  118. but WITHOUT ANY WARRANTY; without even the implied warranty of
  119. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  120. GNU General Public License for more details.
  121. You should have received a copy of the GNU General Public License
  122. along with this program. If not, see L<http://www.gnu.org/licenses/>.
  123. =cut