weblog-3.t 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # Copyright (C) 2011 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software: you can redistribute it and/or modify it under
  4. # the terms of the GNU General Public License as published by the Free Software
  5. # Foundation, either version 3 of the License, or (at your option) any later
  6. # version.
  7. #
  8. # This program is distributed in the hope that it will be useful, but WITHOUT
  9. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License along with
  13. # this program. If not, see <http://www.gnu.org/licenses/>.
  14. require 't/test.pl';
  15. package OddMuse;
  16. use Test::More tests => 45;
  17. add_module('weblog-3.pl');
  18. update_page('This_paragraph', 'bla');
  19. update_page('link', 'bla');
  20. update_page('First_Item', 'bla');
  21. update_page('Second_Item', 'bla');
  22. # default empty homepage defaults to journal
  23. test_page(update_page('2012-12-31_Foo_Baz', 'bla'), 'bla');
  24. xpath_test(get_page('HomePage'),
  25. '//h1/a[text()="2012-12-31 Foo Baz"]');
  26. # update HomePage with some links for the goto-bar
  27. my $text = <<EOT;
  28. This is not a list.
  29. * [[This paragraph]] did not start with a list.
  30. * This does not start with a [[link]].
  31. * [[First Item]] in the goto-bar.
  32. ** [[Second Item]] in the goto-bar.
  33. EOT
  34. # check goto-bar
  35. $page = update_page('HomePage', $text);
  36. xpath_test($page,
  37. '//ul/li/a[text()="This paragraph"]',
  38. '//ul/li/a[text()="link"]',
  39. '//ul/li/a[text()="First Item"]',
  40. '//ul/li/a[text()="Second Item"]',
  41. '//span[@class="gotobar bar"]/a[text()="HomePage"]',
  42. '//span[@class="gotobar bar"]/a[text()="RecentChanges"]',
  43. '//span[@class="gotobar bar"]/a[text()="New"]',
  44. '//span[@class="gotobar bar"]/a[text()="First Item"]',
  45. '//span[@class="gotobar bar"]/a[text()="Second Item"]');
  46. xpath_test_negative($page,
  47. '//span[@class="gotobar bar"]/a[text()="This paragraph"]',
  48. '//span[@class="gotobar bar"]/a[text()="link"]');
  49. xpath_test($page,
  50. '//a[text()="HomePage"]/following-sibling::*[1][text()="RecentChanges"]',
  51. '//a[text()="RecentChanges"]/following-sibling::*[1][text()="First Item"]',
  52. '//a[text()="First Item"]/following-sibling::*[1][text()="Second Item"]',
  53. '//a[text()="Second Item"]/following-sibling::*[1][text()="New"]');
  54. # Create category pagse
  55. update_page('Foo', 'bla');
  56. update_page('Bar', 'bla');
  57. # don't create 'Quux'
  58. $text = <<EOT;
  59. This is not a list.
  60. * [[This paragraph]] did not start with a list.
  61. * This does not start with a [[link]].
  62. * [[Foo]] in the goto-bar.
  63. ** [[Bar]] in the goto-bar.
  64. * [[Quux]] in the goto-bar bit does not exist.
  65. EOT
  66. # Categories page
  67. $page = update_page('Categories', $text);
  68. xpath_test($page,
  69. '//ul/li/a[text()="This paragraph"]',
  70. '//ul/li/a[text()="link"]',
  71. '//ul/li/a[text()="Foo"]',
  72. '//ul/li/a[text()="Bar"]',
  73. '//ul/li/a[@title="Click to edit this page"]');
  74. xpath_test_negative($page,
  75. '//span[@class="gotobar bar"]/a[text()="This paragraph"]',
  76. '//span[@class="gotobar bar"]/a[text()="link"]');
  77. # New page lists categories, even if the page does not exist
  78. $page = get_page('action=new');
  79. xpath_test($page,
  80. '//a[text()="Categories"]',
  81. '//a[text()="First Item"]',
  82. '//a[text()="Second Item"]',
  83. '//a[text()="Quux"]');
  84. xpath_test_negative($page,
  85. '//a[text()="This paragraph"]',
  86. '//a[text()="link"]');
  87. # current category is added to the list
  88. $page = get_page('2012-12-31_Foo_Baz');
  89. xpath_test($page,
  90. '//a[text()="HomePage"]/following-sibling::*[1][text()="RecentChanges"]',
  91. '//a[text()="RecentChanges"]/following-sibling::*[1][text()="First Item"]',
  92. '//a[text()="First Item"]/following-sibling::*[1][text()="Second Item"]',
  93. '//a[text()="Second Item"]/following-sibling::*[1][text()="Foo"]',
  94. '//a[text()="Foo"]/following-sibling::*[1][text()="Baz"]',
  95. '//a[text()="Baz"]/following-sibling::*[1][text()="New"]');
  96. # links added from the HomePage are ordinary links
  97. # category links are ordinary links (because the code knows they are categories)
  98. # dynamic category links from the page name have stuff added (to make sure the code knows)
  99. xpath_test($page,
  100. '//a[text()="First Item"][@href="http://localhost/wiki.pl/First_Item"]',
  101. '//a[text()="Foo"][@href="http://localhost/wiki.pl/Foo"]',
  102. '//a[text()="Baz"][@href="http://localhost/wiki.pl?tag=1;action=browse;id=Baz"]');
  103. # Foo has existing content, thus no journal
  104. $page = get_page('Foo');
  105. xpath_test($page, '//p[text()="bla"]');
  106. xpath_test_negative($page, '//h1/a[text()="2012-12-31 Foo Baz"]');
  107. # Quux does not have existing content and defaults to a journal
  108. # because it is a known category (but there are no matching pages)
  109. $page = get_page('Quux');
  110. xpath_test($page, '//p[text()="Matching pages:"]');
  111. # Baz has no existing content and is no known category, thus without
  112. # the tag parameter, it doesn't exists
  113. $page = get_page('Baz');
  114. xpath_test($page, '//p[contains(text(),"This page does not exist")]');
  115. xpath_test_negative($page, '//h1/a[text()="2012-12-31 Foo Baz"]');
  116. # Baz with the tag parameter defaults to the journal.
  117. $page = get_page('tag=1 action=browse id=Baz');
  118. xpath_test($page, '//h1/a[text()="2012-12-31 Foo Baz"]');