clusters.t 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # Copyright (C) 2006, 2007 Alex Schroeder <alex@emacswiki.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 => 33;
  18. AppendStringToFile($ConfigFile, "\$PageCluster = 'Cluster';\n");
  19. AppendStringToFile($ConfigFile, "\$WikiLinks = 1;\n");
  20. update_page('ClusterIdea', 'This is just a page.', 'one');
  21. update_page('ClusterIdea', "This is just a page.\nBut somebody has to do it.", 'two');
  22. update_page('ClusterIdea', "This is just a page.\nNobody wants it.", 'three', 1);
  23. sleep(1); # make sure the next revision has a different timestamp
  24. update_page('ClusterIdea', "MainPage\nThis is just a page.\nBut somebody has to do it.", 'four');
  25. # Shows both a change to the MainPage Cluster and a change to ClusterIdea.
  26. xpath_test(get_page('action=rc'),
  27. '//a[text()="Cluster"]/following-sibling::a[text()="MainPage"][@href="http://localhost/wiki.pl?action=browse;id=MainPage;rcclusteronly=MainPage"]',
  28. '//a[text()="ClusterIdea"]');
  29. # Show all the major changes. The last major change happened to a
  30. # cluster, so show a change to the MainPage cluster instead.
  31. $page = get_page('action=rc all=1');
  32. xpath_test($page,
  33. '//a[text()="Cluster"]/following-sibling::a[text()="MainPage"]/following-sibling::strong[text()="ClusterIdea: four"]',
  34. '//a[text()="ClusterIdea"]/following-sibling::strong[text()="two"]',
  35. '//a[text()="ClusterIdea"]/following-sibling::strong[text()="one"]');
  36. negative_xpath_test($page,
  37. '//a[text()="ClusterIdea"]/following-sibling::strong[text()="three"]');
  38. # Show minor edits as well.
  39. xpath_test(get_page('action=rc all=1 showedit=1'),
  40. '//a[text()="Cluster"]/following-sibling::a[text()="MainPage"]/following-sibling::strong[text()="ClusterIdea: four"]',
  41. '//a[text()="ClusterIdea"]/following-sibling::strong[text()="three"]/following-sibling::em[text()="(minor)"]',
  42. '//a[text()="ClusterIdea"]/following-sibling::strong[text()="two"]',
  43. '//a[text()="ClusterIdea"]/following-sibling::strong[text()="one"]');
  44. # Change the MainPage.
  45. update_page('MainPage', 'Finally the main page.', 'main summary');
  46. # Ordinary RecentChanges will just show the MainPage changed, now. The
  47. # latest change to ClusterIdea remains invisible.
  48. xpath_test(get_page('action=rc'),
  49. '//a[text()="MainPage"]/following-sibling::strong[text()="main summary"]',
  50. '//a[text()="ClusterIdea"]/following-sibling::strong[text()="two"]');
  51. # Visiting the MainPage as the cluster page shows RecentChanges for
  52. # this cluster only.
  53. xpath_test(get_page('action=browse id=MainPage rcclusteronly=MainPage'),
  54. '//p[text()="Finally the main page."]',
  55. '//b[text()="(for MainPage only)"]',
  56. '//li/a[text()="ClusterIdea"]/following-sibling::strong[text()="four"]',
  57. '//a[@href="http://localhost/wiki.pl?action=browse;id=MainPage;rcclusteronly=MainPage;days=1;all=0;showedit=0"]');
  58. # Now edit the page in the cluster again. Since this is a minor edit,
  59. # RecentChanges will remain unchanged.
  60. update_page('ClusterIdea', "MainPage\nSomebody has to do it.", 'five', 1);
  61. xpath_test(get_page('action=rc'),
  62. '//a[text()="MainPage"]/following-sibling::strong[text()="main summary"]',
  63. '//a[text()="ClusterIdea"]/following-sibling::strong[text()="two"]');
  64. # Things change if we include minor changes, however. Now we'll see
  65. # the last unclustered change ("three") as well as the effect the
  66. # cluster has.
  67. xpath_test(get_page('action=rc showedit=1'),
  68. '//a[text()="Cluster"]/following-sibling::a[text()="MainPage"][@href="http://localhost/wiki.pl?action=browse;id=MainPage;rcclusteronly=MainPage"]/following-sibling::strong[text()="ClusterIdea: five"]',
  69. '//a[text()="ClusterIdea"]/following-sibling::strong[text()="three"]');
  70. # Take another look at the MainPage, this time including all and minor
  71. # edits. We should see the two clustered revisions.
  72. $page = get_page('action=browse id=MainPage rcclusteronly=MainPage all=1 showedit=1');
  73. xpath_test($page,
  74. '//a[text()="ClusterIdea"]/following-sibling::strong[text()="five"]',
  75. '//a[text()="ClusterIdea"]/following-sibling::strong[text()="four"]');
  76. negative_xpath_test($page,
  77. '//a[text()="ClusterIdea"]/following-sibling::strong[text()="three"]',
  78. '//a[text()="ClusterIdea"]/following-sibling::strong[text()="two"]',
  79. '//a[text()="ClusterIdea"]/following-sibling::strong[text()="one"]');
  80. # Check the links in the RSS feed. First major changes only, then
  81. # including minor changes. The clustering will only apparent with
  82. # minor changes.
  83. test_page(get_page('action=rss'),
  84. '<link>http://localhost/wiki.pl/MainPage</link>',
  85. '<link>http://localhost/wiki.pl/ClusterIdea</link>');
  86. test_page(get_page('action=rss showedit=1'),
  87. '<link>http://localhost/wiki.pl\?action=browse;id=MainPage;rcclusteronly=MainPage</link>',
  88. '<link>http://localhost/wiki.pl/ClusterIdea</link>');
  89. # Just to make sure everything works, create a new page in the
  90. # cluster. This time check the raw output. Note that the output will
  91. # contain a link to the last unclustered major revision of
  92. # ClusterIdea, two.
  93. update_page('OtherIdea', "MainPage\nThis is another page.\n", 'new page in cluster');
  94. $page = get_page('action=rc raw=1');
  95. test_page($page, 'title: MainPage',
  96. 'description: OtherIdea: new page in cluster',
  97. 'description: two');
  98. # The summary of the MainPage edit will remain hidden.
  99. test_page_negative($page, 'main summary');