permanent-anchors.t 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Copyright (C) 2006-2018 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. require './t/test.pl';
  16. package OddMuse;
  17. use Test::More tests => 30;
  18. use utf8; # tests contain UTF-8 characters and it matters
  19. add_module('permanent-anchors.pl');
  20. # define permanent anchor
  21. test_page(update_page('Jack_DeJohnette', 'A friend of [::Gary Peacock]'),
  22. 'A friend of',
  23. 'Gary Peacock',
  24. 'name="Gary_Peacock"',
  25. 'class="definition"',
  26. 'title="Click to search for references to this permanent anchor"');
  27. # get the page again to trigger a dirty/cache error
  28. negative_xpath_test(get_page('Jack_DeJohnette'),
  29. '//a[@class="definition"]/following-sibling::a[@class="definition"]');
  30. # link to a permanent anchor
  31. test_page(update_page('Keith_Jarret', 'Plays with [[Gary Peacock]]'),
  32. 'Plays with',
  33. 'wiki.pl/Jack_DeJohnette#Gary_Peacock',
  34. 'Keith Jarret',
  35. 'Gary Peacock');
  36. # verify that the link target redirects to the permanent anchor
  37. test_page(get_page('Gary_Peacock'),
  38. 'Status: 302',
  39. 'Location: .*wiki.pl/Jack_DeJohnette#Gary_Peacock');
  40. # undefine the permanent anchor
  41. test_page(update_page('Jack_DeJohnette', 'A friend of Gary Peacock.'),
  42. 'A friend of Gary Peacock.');
  43. # verify that the link to it turns into an edit link
  44. test_page(get_page('Keith_Jarret'),
  45. 'wiki.pl\?action=edit;id=Gary_Peacock');
  46. # repeat with an existing page
  47. test_page(update_page('Thelonius_Mönk', 'first revision', 'start here'),
  48. 'first revision');
  49. test_page(update_page('Thelonius_Mönk', 'second revision', 'this is next'),
  50. 'second revision');
  51. # check warning message for existing page
  52. $page = update_page('Keith_Jarret', 'plays unlike [::Thelonius Mönk]');
  53. like($page, qr(the page (.*?) also exists), 'the page ... also exists');
  54. $page =~ qr(the page (.*?) also exists);
  55. $link = $1;
  56. xpath_test($link, '//a[@class="local"][@href="http://localhost/wiki.pl?action=browse;anchor=0;id=Thelonius_M%c3%b6nk"][text()="Thelonius Mönk"]');
  57. # verify that the redirection works
  58. test_page(get_page('action=browse id=Thelonius_Mönk'),
  59. 'Status: 302',
  60. 'Location: .*wiki.pl/Keith_Jarret#Thelonius_M%c3%b6nk');
  61. # verify that the anchor=0 parameter has the desired effect
  62. test_page(get_page('action=browse anchor=0 id=Thelonius_Mönk'),
  63. 'second revision');
  64. # verify that the history page uses anchor=0 for its links
  65. xpath_test(get_page('action=history id=Thelonius_Mönk'),
  66. '//a[@class="revision"][@href="http://localhost/wiki.pl?action=browse;anchor=0;id=Thelonius_M%c3%b6nk;revision=1"][text()="Revision 1"]',
  67. # not sure whether it makes sure to have the class "local" here!
  68. '//a[@class="local"][@href="http://localhost/wiki.pl?action=browse;anchor=0;id=Thelonius_M%c3%b6nk"][text()="Revision 2"]');
  69. # verify that the history page of ordinary pages remains unaffected
  70. xpath_test(get_page('action=history id=Jack_DeJohnette'),
  71. '//a[@class="revision"][@href="http://localhost/wiki.pl?action=browse;id=Jack_DeJohnette;revision=1"][text()="Revision 1"]',
  72. # not sure whether it makes sure to have the class "local" here!
  73. '//a[@class="local"][@href="http://localhost/wiki.pl/Jack_DeJohnette"][text()="Revision 2"]');
  74. # create an anchored object
  75. update_page('TheGame', qq{The game has rules and props. [::TheRules] Simple and elegant. [::TheProps] Expensive and brittle.\n----\nThat's how not to do it!});
  76. update_page('TheTest', qq{The rules are supposed to be\n<include "TheRules">});
  77. # conflict
  78. add_module('creole.pl');
  79. InitVariables(); # need to call MarkupInit!
  80. run_tests(split('\n',<<'EOT'));
  81. **bold** and **bold**
  82. <strong>bold</strong> and <strong>bold</strong>
  83. **[::bold]** and **bold**
  84. <strong><span class="permanentanchor">bold</span></strong> and <strong>bold</strong>
  85. EOT
  86. # delete a page
  87. update_page('TheTest', $DeletedPage);
  88. OpenPage('TheTest');
  89. is(-f GetPageFile($OpenPageName), 1, 'Page file exists');
  90. is(DeletePage($OpenPageName), '', 'No error deleting a page');
  91. is(-e GetPageFile($OpenPageName), undef, 'Page file no longer exists');