clusters.t 5.9 KB

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