journal.t 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # Copyright (C) 2006, 2009 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 => 51;
  18. $today = CalcDay($Now);
  19. $tomorrow = CalcDay($Now + 24*60*60);
  20. $yesterday = CalcDay($Now - 24*60*60);
  21. $beforeyesterday = CalcDay($Now - 2*24*60*60);
  22. update_page($yesterday, "Freitag");
  23. update_page($today, "Samstag");
  24. update_page($tomorrow, "Sonntag");
  25. # auch die reihenfolge wird getestet
  26. @test = ('This is my journal', $today, 'Samstag', $tomorrow,
  27. 'Sonntag', "$tomorrow.*$today");
  28. # check that the limit is taken into account
  29. $page = update_page('Summary', "This is my journal:\n\n<journal 2>");
  30. test_page($page, @test);
  31. test_page_negative($page, $yesterday);
  32. # catch loops
  33. test_page(update_page($beforeyesterday, "This is my journal -- recursive:\n\n<journal>"), @test);
  34. test_page(update_page('Summary', "Counting up:\n\n<journal 3 reverse>"),
  35. "$beforeyesterday.*$yesterday.*$today");
  36. # now check all pages
  37. $page = update_page('Summary', "Counting down:\n\n<journal>");
  38. test_page($page, "$tomorrow.*$today.*$yesterday.*$beforeyesterday");
  39. # make sure there are no empty pages being printed (this used to be a bug)
  40. negative_xpath_test($page, '//h1/a[not(text())]');
  41. # check reverse order
  42. test_page(update_page('Summary', "Counting up:\n\n<journal reverse>"),
  43. "$beforeyesterday.*$yesterday.*$today.*$tomorrow");
  44. # check past; use xpath because $today will also match "Last edited ... by ..."
  45. $page = update_page('Summary', "Only past pages:\n\n<journal past>");
  46. xpath_test($page, "//a[text()='$yesterday']",
  47. "//a[text()='$beforeyesterday']");
  48. negative_xpath_test($page, "//a[text()='$today']",
  49. "//a[text()='$tomorrow']");
  50. # check future
  51. $page = update_page('Summary', "Only future pages:\n\n<journal future>");
  52. xpath_test($page, "//a[text()='$tomorrow']");
  53. negative_xpath_test($page, "//a[text()='$today']",
  54. "//a[text()='$yesterday']",
  55. "//a[text()='$beforeyesterday']");
  56. # Check that ,0 disables More... link
  57. test_page_negative(update_page('Summary', "No 'More' link:\n\n<journal 3,0>"), 'More\.\.\.');
  58. # But otherwise More... button is present and ,XX syntax works correctly
  59. test_page(update_page('Summary', "'More' button works correctly:\n\n<journal 2,69>"), 'More\.\.\.', 'num=69');
  60. # <titles> should not display page content
  61. $page = update_page('Summary', "No page contents:\n\n<titles 3>");
  62. test_page_negative($page, '(Freitag|Samstag|Sonntag)'); # no content
  63. test_page($page, "$tomorrow.*$today.*$yesterday"); # but titles are there!
  64. # :OFFSET
  65. $page = update_page('Summary', "Using offset:\n\n<journal:1>");
  66. test_page_negative($page, 'Sonntag'); # tomorrow should not appear
  67. test_page($page, 'Samstag.*Freitag'); # but everything else should
  68. # check $JournalLimit option and comments
  69. AppendStringToFile($ConfigFile, "\$JournalLimit = 2;\n\$CommentsPrefix = 'Talk about ';\n");
  70. $page = update_page('Summary', "Testing the limit of two:\n\n<journal>");
  71. test_page($page, $tomorrow, "Talk_about_$tomorrow", $today, "Talk_about_$today");
  72. test_page_negative($page, $yesterday, $beforeyesterday);
  73. # $JournalLimit does not apply to admins
  74. test_page(get_page('action=browse id=Summary pwd=foo'),
  75. "$tomorrow.*$today.*$yesterday.*$beforeyesterday");
  76. # make sure deleted pages don't count (limit is set to two):
  77. update_page($tomorrow, $DeletedPage);
  78. $page = update_page('Summary', "Tomorrow is gone:\n\n<journal>");
  79. test_page($page, "$today.*$yesterday");
  80. test_page_negative($page, $tomorrow, $beforeyesterday);
  81. # Test for page corruption. Start with an empty set of pages and a
  82. # fresh config file because of the $JournalLimit and dynamic pagenames
  83. # used above.
  84. clear_pages();
  85. # Don't use update_page for the first update
  86. # because we don't want to render the page right after creating it.
  87. get_page('title=2009-06-22 text=hugglifuzbubs');
  88. $page = get_page('action=browse raw=1 id=2009-06-22');
  89. test_page($page, 'hugglifuzbubs');
  90. test_page_negative($page, 'blocks');
  91. test_page(update_page('Journal', "This is the journal.\n\n<journal>\n"),
  92. 'This is the journal',
  93. '2009-06-22',
  94. 'hugglifuzbubs');
  95. test_page(ReadFileOrDie(GetPageFile('2009-06-22')),
  96. 'blocks: <p>hugglifuzbubs</p>');
  97. # Same test, but with search and tags
  98. add_module('tags.pl');
  99. update_page('2009-06-23', 'penta figurazza [[tag:foo]]');
  100. test_page(update_page('Journal', "This is the journal.\n\n"
  101. . "<journal search tag:foo>\n"),
  102. '2009-06-23',
  103. 'penta figurazza');
  104. test_page(ReadFileOrDie(GetPageFile('2009-06-23')),
  105. 'blocks: <p>penta figurazza');