tags.t 7.6 KB

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