near-links.t 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright (C) 2006, 2008, 2010 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify it under
  4. # the terms of the GNU General Public License as published by the Free Software
  5. # Foundation; either version 3 of the License, or (at your option) any later
  6. # version.
  7. #
  8. # This program is distributed in the hope that it will be useful, but WITHOUT
  9. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License along with
  13. # this program. If not, see <http://www.gnu.org/licenses/>.
  14. require './t/test.pl';
  15. package OddMuse;
  16. use Test::More tests => 16;
  17. add_module('near-links.pl');
  18. AppendStringToFile($ConfigFile, "\$WikiLinks = 1;\n");
  19. CreateDir($NearDir);
  20. WriteStringToFile("$NearDir/EmacsWiki", "AlexSchroeder\nFooBar\n"
  21. . "Comments_on_FooBar\nEmacsWiki\n");
  22. update_page('InterMap', " EmacsWiki http://www.emacswiki.org/cgi-bin/wiki/%s\n",
  23. 'required', 0, 1);
  24. update_page('NearMap', " EmacsWiki"
  25. . " http://www.emacswiki.org/cgi-bin/emacs?action=index;raw=1"
  26. . " http://www.emacswiki.org/cgi-bin/emacs?search=%s;raw=1;near=0\n",
  27. 'required', 0, 1);
  28. xpath_test(update_page('FooBaz', "Try FooBar instead!\n"),
  29. '//a[@class="near"][@title="EmacsWiki"][@href="http://www.emacswiki.org/cgi-bin/wiki/FooBar"][text()="FooBar"]',
  30. '//div[@class="near"]/p/a[@class="local"][@href="http://localhost/wiki.pl/EditNearLinks"][text()="EditNearLinks"]/following-sibling::text()[string()=": "]/following-sibling::a[@class="edit"][@title="Click to edit this page"][@href="http://localhost/wiki.pl?action=edit;id=FooBar"][text()="FooBar"]');
  31. xpath_test(update_page('FooBar', "Test by AlexSchroeder!\n"),
  32. '//div[@class="sister"]/p/a[@title="EmacsWiki:FooBar"][@href="http://www.emacswiki.org/cgi-bin/wiki/FooBar"]/img[@src="file:///tmp/oddmuse/EmacsWiki.png"][@alt="EmacsWiki:FooBar"]');
  33. xpath_test(get_page('search=alexschroeder'),
  34. '//p[text()="Near pages:"]',
  35. '//a[@class="near"][@title="EmacsWiki"][@href="http://www.emacswiki.org/cgi-bin/wiki/AlexSchroeder"][text()="AlexSchroeder"]');
  36. my $page = get_page('search=FooBar');
  37. xpath_test($page,
  38. '//a[@class="local"][@href="http://localhost/wiki.pl/FooBar"][text()="FooBar"]',
  39. '//a[@class="near"][@title="EmacsWiki"][@href="http://www.emacswiki.org/cgi-bin/wiki/Comments_on_FooBar"][text()="Comments on FooBar"]',
  40. # The pages found: FooBar (locally), FooBaz (locally, because FooBar is in the body), and Comments_on_FooBar
  41. # (remote). The remove FooBar must not be counted.
  42. '//p[@class="result"][text()="3 pages found."]');
  43. AppendStringToFile($ConfigFile, "\$CommentsPrefix = 'Comments on ';\n");
  44. xpath_test(get_page('FooBar'),
  45. '//a[@class="comment local"][@href="http://localhost/wiki.pl/Comments_on_FooBar"][text()="Comments on FooBar"]');
  46. xpath_test(get_page('Comments_on_FooBar'),
  47. qq{//div[\@class="content browse"]/p[contains(text(),"There are no comments")]});
  48. $page=get_page('action=rc rcfilteronly=alex');
  49. xpath_test($page, '//a[text()="FooBar"]',
  50. '//strong[text()="Test by AlexSchroeder! "]');
  51. xpath_test_negative($page, '//p[text()="Near pages:"]',
  52. '//a[@class="near"][@title="EmacsWiki"][text()="AlexSchroeder"]');
  53. my @matches = get_page('action=index raw=1 near=1') =~ m/^FooBar$/gm;
  54. is(scalar(@matches), 1, "FooBar listed once when including near pages");
  55. my @matches = get_page('action=index raw=1 pages=0 near=1') =~ m/^FooBar$/gm;
  56. is(scalar(@matches), 1, "FooBar listed once when excluding local pages");