tags.t 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 => 70;
  18. use utf8;
  19. add_module('tags.pl');
  20. InitVariables();
  21. $TagFeedIcon = 'http://www.example.org/pics/rss.png';
  22. xpath_run_tests(split('\n',<<'EOT'));
  23. [[tag:foo bar]]
  24. //a[@class="outside tag"][@title="Tag"][@rel="tag"][text()="foo bar"][@href="http://localhost/test.pl?action=rc;rcfilteronly=tag:foo%20bar"]
  25. [[tag:foo bar]]
  26. //a[@class="feed tag"][@title="Feed for this tag"][@href="http://localhost/test.pl?action=rss;rcfilteronly=tag:foo%20bar"][@rel="feed"]/img[@src="http://www.example.org/pics/rss.png"]
  27. EOT
  28. $TagUrl = 'http://technorati.com/tag/%s';
  29. $TagFeed = 'http://feeds.technorati.com/tag/%s';
  30. xpath_run_tests(split('\n',<<'EOT'));
  31. [[tag:foo bar]]
  32. //a[@class="outside tag"][@title="Tag"][@href="http://technorati.com/tag/foo%20bar"][@rel="tag"][text()="foo bar"]
  33. [[tag:foo bar]]
  34. //a[@class="feed tag"][@title="Feed for this tag"][@href="http://feeds.technorati.com/tag/foo%20bar"][@rel="feed"]/img[@src="http://www.example.org/pics/rss.png"]
  35. [[tag:foo bar|mu muh!]]
  36. //a[@class="outside tag"][@title="Tag"][@href="http://technorati.com/tag/foo%20bar"][@rel="tag"][text()="mu muh!"]
  37. EOT
  38. update_page('Brilliant', 'Gameologists [[tag:podcast]] [[tag:mag]]');
  39. update_page('Pödgecäst´s', 'Another [[tag:podcast]]');
  40. update_page('Alex', 'Me! [[tag:Old School]]');
  41. # open the DB file
  42. my %h = TagReadHash();
  43. %tag = map {$_=>1} @{$h{"_Brilliant"}};
  44. ok($tag{podcast}, 'Brilliant page tagged podcast');
  45. ok($tag{mag}, 'Brilliant page tagged mag');
  46. %tag = map {$_=>1} @{$h{"_Pödgecäst´s"}};
  47. ok($tag{podcast}, 'Pödgecäst´s page tagged podcast');
  48. %file = map {$_=>1} @{$h{"podcast"}};
  49. ok($file{Brilliant}, 'Tag podcast applies to page Brilliant');
  50. ok($file{"Pödgecäst´s"}, 'Tag podcast applies to page Pödgecäst´s');
  51. %file = map {$_=>1} @{$h{"mag"}};
  52. ok($file{Brilliant}, 'Tag mag applies to page Brilliant');
  53. %file = map {$_=>1} @{$h{"old_school"}};
  54. ok($file{Alex}, 'Tag Old School applies to page Alex');
  55. # close the DB file before making changes via the wiki!
  56. TagWriteHash(\%h);
  57. update_page('Brilliant', 'Gameologists [[tag:mag]]');
  58. # reopen changed file
  59. %h = TagReadHash();
  60. %tag = map {$_=>1} @{$h{"_Brilliant"}};
  61. ok(!$tag{podcast}, 'Brilliant page no longer tagged podcast');
  62. ok($tag{mag}, 'Brilliant page still tagged mag');
  63. %file = map {$_=>1} @{$h{"podcast"}};
  64. ok(!$file{Brilliant}, 'Tag podcast no longer applies to page Brilliant');
  65. ok($file{"Pödgecäst´s"}, 'Tag podcast still applies to page Pödgecäst´s');
  66. # close the DB file before making changes via the wiki!
  67. TagWriteHash(\%h);
  68. DeletePage('Brilliant');
  69. # reopen changed file
  70. %h = TagReadHash();
  71. ok(!$h{"_Brilliant"}, 'Brilliant page no longer exists');
  72. ok(!exists($h{"mag"}), 'No page tagged mag exists');
  73. # close the DB file before making changes via the wiki!
  74. TagWriteHash(\%h);
  75. update_page('Brilliant', 'Gameologists [[tag:podcast]] [[tag:mag]]');
  76. update_page('Sons', 'of Kryos [[tag:Podcast]]');
  77. update_page('Alex', 'not a podcast');
  78. update_page('Jeff', 'a blog [[tag:Old School]]');
  79. # ordinary search finds Alex
  80. $page = get_page('search=podcast raw=1');
  81. test_page($page, qw(Pödgecäst´s Brilliant Sons Alex));
  82. # tag search skips Alex
  83. $page = get_page('search=tag:podcast raw=1');
  84. test_page($page, qw(Pödgecäst´s Brilliant Sons));
  85. test_page_negative($page, qw(Alex));
  86. # tag search is case insensitive
  87. $page = get_page('search=tag:PODCAST raw=1');
  88. test_page($page, qw(Pödgecäst´s Brilliant Sons));
  89. test_page_negative($page, qw(Alex));
  90. # exclude tag search skips Brilliant
  91. $page = get_page('search=-tag:mag raw=1');
  92. test_page($page, qw(Pödgecäst´s Sons Alex));
  93. test_page_negative($page, qw(Brilliant));
  94. # combine include and exclude tag search to exclude both Alex and
  95. # Brilliant
  96. $page = get_page('search=tag:podcast%20-tag:mag raw=1');
  97. test_page($page, qw(Pödgecäst´s Sons));
  98. test_page_negative($page, qw(Brilliant Alex));
  99. # combine ordinary search with include and exclude tag search to
  100. # exclude both Alex and Brilliant
  101. $page = get_page('search=kryos%20tag:podcast%20-tag:mag raw=1');
  102. test_page($page, qw(Sons));
  103. test_page_negative($page, qw(Pödgecäst´s Brilliant Alex));
  104. # search for a tag containing spaces
  105. $page = get_page('search=tag:old_school raw=1');
  106. test_page($page, qw(Jeff));
  107. test_page_negative($page, qw(Sons Pödgecäst´s Brilliant Alex));
  108. test_page(get_page('action=reindex pwd=foo'),
  109. qw(Pödgecäst´s Brilliant Sons Alex));
  110. # tag search skips Alex -- repeat test after reindexing
  111. $page = get_page('search=tag:podcast raw=1');
  112. test_page($page, qw(Pödgecäst´s Brilliant Sons));
  113. test_page_negative($page, qw(Alex));
  114. add_module('near-links.pl');
  115. CreateDir($NearDir);
  116. WriteStringToFile("$NearDir/EmacsWiki", "AlexSchroeder\nFoo\n");
  117. update_page('InterMap', " EmacsWiki http://www.emacswiki.org/cgi-bin/wiki/%s\n",
  118. 'required', 0, 1);
  119. update_page('NearMap', " EmacsWiki"
  120. . " http://www.emacswiki.org/cgi-bin/emacs?action=index;raw=1\n",
  121. 'required', 0, 1);
  122. # make sure the near pages are not listed
  123. $page = get_page('search=tag:podcast raw=1');
  124. test_page_negative($page, qw(AlexSchroeder Foo));
  125. # check journal pages
  126. $page = update_page('Podcasts', '<journal "." search tag:podcast>');
  127. test_page($page, qw(Pödgecäst´s Brilliant Sons));
  128. test_page_negative($page, qw(Alex Foo));
  129. # check the tag cloud
  130. xpath_test(get_page('action=tagcloud'),
  131. '//h1[text()="Tag Cloud"]',
  132. '//a[@style="font-size: 200%;"][@href="http://localhost/wiki.pl?search=tag:podcast"][@title="3"][text()="podcast"]',
  133. '//a[@style="font-size: 80%;"][@href="http://localhost/wiki.pl?search=tag:old_school"][@title="1"][text()="old school"]',
  134. '//a[@style="font-size: 80%;"][@href="http://localhost/wiki.pl?search=tag:mag"][@title="1"][text()="mag"]');
  135. # check interference; in order for this test to work, we need to make
  136. # sure that localnames is loaded first
  137. add_module('localnames.pl');
  138. AppendStringToFile($ConfigFile, "\$LocalNamesCollect = 1;\n");
  139. update_page('LocalNames', 'test');
  140. update_page('Alex', 'is a [[tag:podcast]] after all');
  141. $page = get_page('search=tag:podcast raw=1');
  142. test_page($page, qw(Pödgecäst´s Brilliant Sons Alex));