123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- # Copyright (C) 2006-2019 Alex Schroeder <alex@gnu.org>
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- require './t/test.pl';
- package OddMuse;
- use Test::More tests => 94;
- use utf8;
- add_module('tags.pl');
- InitVariables();
- # first, let's make sure the old search still works
- test_page(join(':', TagsTerms('a b "c d"')), 'a:b:c d');
- update_page('test', 'foo bar baz');
- test_page(get_page('search=foo'), 'test', 'Search for: foo', '<strong>foo</strong>');
- test_page(get_page('search=foo+bar'), 'test', 'Search for: foo bar', '<strong>foo</strong> <strong>bar</strong>');
- test_page(get_page('search=bar+foo'), 'test', 'Search for: bar foo', '<strong>foo</strong> <strong>bar</strong>');
- test_page(get_page('search=foo+baz'), 'test', 'Search for: foo baz', '<strong>foo</strong> bar <strong>baz</strong>');
- $page = get_page('search=%22foo+baz%22');
- test_page($page, 'Search for: "foo baz"');
- test_page_negative($page, 'test');
- test_page(get_page('search=%22foo+bar%22'), 'test', 'Search for: "foo bar"', '<strong>foo bar</strong>');
- # testing other stuff
- $TagFeedIcon = 'http://www.example.org/pics/rss.png';
- xpath_run_tests(split('\n',<<'EOT'));
- [[tag:foo bar]]
- //a[@class="outside tag"][@title="Tag"][@rel="tag"][text()="foo bar"][@href="http://localhost/test.pl?action=rc;rcfilteronly=tag:foo%20bar"]
- [[tag:foo bar]]
- //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"]
- EOT
- $TagUrl = 'http://technorati.com/tag/%s';
- $TagFeed = 'http://feeds.technorati.com/tag/%s';
- xpath_run_tests(split('\n',<<'EOT'));
- [[tag:foo bar]]
- //a[@class="outside tag"][@title="Tag"][@href="http://technorati.com/tag/foo%20bar"][@rel="tag"][text()="foo bar"]
- [[tag:foo bar]]
- //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"]
- [[tag:foo bar|mu muh!]]
- //a[@class="outside tag"][@title="Tag"][@href="http://technorati.com/tag/foo%20bar"][@rel="tag"][text()="mu muh!"]
- EOT
- update_page('Brilliant', 'Gameologists [[tag:podcast]] [[tag:mag]]');
- update_page('Pödgecäst´s', 'Another [[tag:podcast]]');
- update_page('Alex', 'Me! [[tag:Old School]]');
- # open the DB file
- my %h = TagReadHash();
- %tag = map {$_=>1} @{$h{"_Brilliant"}};
- ok($tag{podcast}, 'Brilliant page tagged podcast');
- ok($tag{mag}, 'Brilliant page tagged mag');
- %tag = map {$_=>1} @{$h{"_Pödgecäst´s"}};
- ok($tag{podcast}, 'Pödgecäst´s page tagged podcast');
- %file = map {$_=>1} @{$h{"podcast"}};
- ok($file{Brilliant}, 'Tag podcast applies to page Brilliant');
- ok($file{"Pödgecäst´s"}, 'Tag podcast applies to page Pödgecäst´s');
- %file = map {$_=>1} @{$h{"mag"}};
- ok($file{Brilliant}, 'Tag mag applies to page Brilliant');
- %file = map {$_=>1} @{$h{"old_school"}};
- ok($file{Alex}, 'Tag Old School applies to page Alex');
- # close the DB file before making changes via the wiki!
- TagWriteHash(\%h);
- update_page('Brilliant', 'Gameologists [[tag:mag]]');
- # reopen changed file
- %h = TagReadHash();
- %tag = map {$_=>1} @{$h{"_Brilliant"}};
- ok(!$tag{podcast}, 'Brilliant page no longer tagged podcast');
- ok($tag{mag}, 'Brilliant page still tagged mag');
- %file = map {$_=>1} @{$h{"podcast"}};
- ok(!$file{Brilliant}, 'Tag podcast no longer applies to page Brilliant');
- ok($file{"Pödgecäst´s"}, 'Tag podcast still applies to page Pödgecäst´s');
- # close the DB file before making changes via the wiki!
- TagWriteHash(\%h);
- DeletePage('Brilliant');
- # reopen changed file
- %h = TagReadHash();
- ok(!$h{"_Brilliant"}, 'Brilliant page no longer exists');
- ok(!exists($h{"mag"}), 'No page tagged mag exists');
- # close the DB file before making changes via the wiki!
- TagWriteHash(\%h);
- update_page('Brilliant', 'Gameologists [[tag:podcast]] [[tag:mag]]');
- update_page('Sons', 'of Kryos [[tag:Podcast]]');
- update_page('Alex', 'not a podcast');
- update_page('Jeff', 'a blog [[tag:Old School]]');
- # ordinary search finds Alex
- $page = get_page('search=podcast raw=1');
- test_page($page, qw(Pödgecäst´s Brilliant Sons Alex));
- # tag search skips Alex
- $page = get_page('search=tag:podcast raw=1');
- test_page($page, qw(Pödgecäst´s Brilliant Sons));
- test_page_negative($page, qw(Alex));
- # tag search is case insensitive
- $page = get_page('search=tag:PODCAST raw=1');
- test_page($page, qw(Pödgecäst´s Brilliant Sons));
- test_page_negative($page, qw(Alex));
- # exclude tag search skips Brilliant
- $page = get_page('search=-tag:mag raw=1');
- test_page($page, qw(Pödgecäst´s Sons Alex));
- test_page_negative($page, qw(Brilliant));
- # combine include and exclude tag search to exclude both Alex and
- # Brilliant
- $page = get_page('search=tag:podcast%20-tag:mag raw=1');
- test_page($page, qw(Pödgecäst´s Sons));
- test_page_negative($page, qw(Brilliant Alex));
- # combine ordinary search with include and exclude tag search to
- # exclude both Alex and Brilliant
- $page = get_page('search=kryos%20tag:podcast%20-tag:mag raw=1');
- test_page($page, qw(Sons));
- test_page_negative($page, qw(Pödgecäst´s Brilliant Alex));
- # search for a tag containing spaces
- $page = get_page('search=tag:old_school raw=1');
- test_page($page, qw(Jeff));
- test_page_negative($page, qw(Sons Pödgecäst´s Brilliant Alex));
- test_page(get_page('action=reindex pwd=foo'),
- qw(Pödgecäst´s Brilliant Sons Alex));
- # tag search skips Alex -- repeat test after reindexing
- $page = get_page('search=tag:podcast raw=1');
- test_page($page, qw(Pödgecäst´s Brilliant Sons));
- test_page_negative($page, qw(Alex));
- add_module('near-links.pl');
- CreateDir($NearDir);
- WriteStringToFile("$NearDir/EmacsWiki", "AlexSchroeder\nFoo\n");
- update_page('InterMap', " EmacsWiki http://www.emacswiki.org/cgi-bin/wiki/%s\n",
- 'required', 0, 1);
- update_page('NearMap', " EmacsWiki"
- . " http://www.emacswiki.org/cgi-bin/emacs?action=index;raw=1\n",
- 'required', 0, 1);
- # make sure the near pages are not listed
- $page = get_page('search=tag:podcast raw=1');
- test_page_negative($page, qw(AlexSchroeder Foo));
- # check journal pages
- $page = update_page('Podcasts', '<journal "." search tag:podcast>');
- test_page($page, qw(Pödgecäst´s Brilliant Sons));
- test_page_negative($page, qw(Alex Foo));
- # check recent changes
- test_page(get_page('action=rc'), qw(Brilliant Alex Jeff));
- $page = get_page('action=rc rcfilteronly=tag:Podcast');
- test_page($page, qw(Brilliant));
- test_page_negative($page, qw(Alex Jeff));
- # check the tag cloud
- xpath_test(get_page('action=tagcloud'),
- '//h1[text()="Tag Cloud"]',
- '//a[@href="http://localhost/wiki.pl?search=tag:podcast"][text()="podcast"]',
- '//a[@href="http://localhost/wiki.pl?search=tag:old_school"][text()="old school"]',
- '//a[@href="http://localhost/wiki.pl?search=tag:mag"][text()="mag"]');
- # check interference; in order for this test to work, we need to make
- # sure that localnames is loaded first
- add_module('localnames.pl');
- AppendStringToFile($ConfigFile, "\$LocalNamesCollect = 1;\n");
- update_page('LocalNames', 'test');
- update_page('Alex', 'is a [[tag:podcast]] after all');
- $page = get_page('search=tag:podcast raw=1');
- test_page($page, qw(Pödgecäst´s Brilliant Sons Alex));
|