journal-rss.t 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # Copyright (C) 2008, 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 => 48;
  18. add_module('journal-rss.pl');
  19. # summaries eq page content since no summaries are provided
  20. update_page('2008-09-21', 'first page');
  21. update_page('2008-09-22', 'second page'); # major
  22. sleep(1);
  23. update_page('2008-09-22', 'third edit', 'third edit', 1); # minor
  24. update_page('unrelated', 'wrong page');
  25. my $page = get_page('action=journal');
  26. test_page($page,
  27. '2008-09-21', 'first page',
  28. # ignore minor edits are ignored: show last major edit
  29. # instead
  30. '2008-09-22', 'second page',
  31. # reverse sort is the default
  32. '2008-09-22(.*\n)+.*2008-09-21');
  33. # make sure unrelated pages and minor edits don't show up
  34. test_page_negative($page, 'unrelated', 'wrong page',
  35. 'third edit');
  36. # verify the order of pages
  37. test_page(get_page('action=journal'),
  38. '2008-09-22(.*\n)+.*2008-09-21');
  39. # reverse the order
  40. test_page(get_page('action=journal reverse=1'),
  41. '2008-09-21(.*\n)+.*2008-09-22');
  42. # match parameter
  43. $page = get_page('action=journal match=21');
  44. test_page($page, '2008-09-21', 'first page');
  45. test_page_negative($page, '2008-09-22', 'second page');
  46. # search parameter
  47. $page = get_page('action=journal search=second');
  48. # no pages found, since this is for an old revision!
  49. test_page_negative($page,
  50. '2008-09-21', 'first page',
  51. '2008-09-22', 'second page',
  52. 'third edit');
  53. # strange but true: search returns a page based on the minor edit but
  54. # shows the latest major revision that doesn't actually match.
  55. $page = get_page('action=journal search=third');
  56. test_page($page, '2008-09-22', 'second page');
  57. test_page_negative($page, '2008-09-21', 'first page', 'third edit');
  58. # testing the limit default
  59. update_page('2008-09-05', 'page');
  60. update_page('2008-09-06', 'page');
  61. update_page('2008-09-07', 'page');
  62. update_page('2008-09-08', 'page');
  63. update_page('2008-09-09', 'page');
  64. update_page('2008-09-10', 'page');
  65. update_page('2008-09-11', 'page');
  66. update_page('2008-09-12', 'page');
  67. update_page('2008-09-13', 'page');
  68. update_page('2008-09-14', 'page');
  69. update_page('2008-09-15', 'page');
  70. update_page('2008-09-16', 'page');
  71. update_page('2008-09-17', 'page');
  72. update_page('2008-09-18', 'page');
  73. update_page('2008-09-19', 'page');
  74. update_page('2008-09-20', 'page');
  75. $page = get_page('action=journal');
  76. test_page($page, '2008-09-22', '2008-09-21', '2008-09-20', '2008-09-19',
  77. '2008-09-18', '2008-09-17', '2008-09-16', '2008-09-15',
  78. '2008-09-14', '2008-09-13');
  79. test_page_negative($page, '2008-09-12', '2008-09-11', '2008-09-10',
  80. '2008-09-09', '2008-09-08', '2008-09-07',
  81. '2008-09-06', '2008-09-05');
  82. # testing the rss limit parameter
  83. $page = get_page('action=journal rsslimit=1');
  84. test_page($page, '2008-09-22');
  85. test_page_negative($page, '2008-09-21');
  86. $page = get_page('action=journal rsslimit=all');
  87. test_page($page, '2008-09-22', '2008-09-05');
  88. # Now let's show that we're using the timestamp of the last major
  89. # change if possible.
  90. my @dates = get_page('action=rss showedit=1 all=1 match=2008-09-22')
  91. =~ m!<pubDate>(.*?)</pubDate>!g;
  92. # $dates[0] is the channel pubDate
  93. my $date2 = $dates[1]; # revision 2 comes first
  94. my $date1 = $dates[2]; # revision 1 comes second
  95. my ($item) = $page =~ m!(<item>\n<title>2008-09-22</title>\n(.*\n)+?</item>\n)!;
  96. test_page($item, "<pubDate>$date1</pubDate>");
  97. test_page_negative($item, "<pubDate>$date2</pubDate>");