links.t 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # Copyright (C) 2006–2015 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 => 60;
  17. use utf8;
  18. add_module('links.pl');
  19. AppendStringToFile($ConfigFile, q{
  20. $WikiLinks = 1;
  21. });
  22. update_page('InterMap',
  23. " Oddmuse http://www.emacswiki.org/cgi-bin/oddmuse.pl?\n",
  24. 'required', 0, 1);
  25. update_page('a', 'Oddmuse:foo(no) [Oddmuse:bar] [Oddmuse:baz text] '
  26. . '[Oddmuse:bar(no)] [Oddmuse:baz(no) text] '
  27. . '[[Oddmuse:foo_(bar)]] [[[Oddmuse:foo (baz)]]] [[Oddmuse:foo (quux)|text]]');
  28. $InterInit = 0;
  29. InitVariables();
  30. my @Test = map { quotemeta } split('\n',<<'EOT');
  31. "a" -> "Oddmuse:foo"
  32. "a" -> "Oddmuse:bar"
  33. "a" -> "Oddmuse:baz"
  34. "a" -> "Oddmuse:foo_(bar)"
  35. "a" -> "Oddmuse:foo (baz)"
  36. "a" -> "Oddmuse:foo (quux)"
  37. EOT
  38. test_page_negative(get_page('action=links raw=1'), @Test);
  39. test_page(get_page('action=links raw=1 inter=1'), @Test);
  40. @Test = split('\n',<<'EOT');
  41. //a[@class="local"][@href="http://localhost/wiki.pl/a"][text()="a"]
  42. //a[@class="inter Oddmuse"][@href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?foo"]/span[@class="site"][text()="Oddmuse"]/following-sibling::span[@class="separator"][text()=":"]/following-sibling::span[@class="interpage"][text()="foo"]
  43. //a[@class="inter Oddmuse"][@href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?bar"]/span[@class="site"][text()="Oddmuse"]/following-sibling::span[@class="separator"][text()=":"]/following-sibling::span[@class="interpage"][text()="bar"]
  44. //a[@class="inter Oddmuse"][@href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?baz"]/span[@class="site"][text()="Oddmuse"]/following-sibling::span[@class="separator"][text()=":"]/following-sibling::span[@class="interpage"][text()="baz"]
  45. //a[@class="inter Oddmuse"][@href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?foo_(bar)"]/span[@class="site"][text()="Oddmuse"]/following-sibling::span[@class="separator"][text()=":"]/following-sibling::span[@class="interpage"][text()="foo_(bar)"]
  46. EOT
  47. negative_xpath_test(get_page('action=links'), @Test);
  48. xpath_test(get_page('action=links inter=1'), @Test);
  49. AppendStringToFile($ConfigFile, "\$BracketWiki = 0;\n");
  50. update_page('a', '[[b]] [[[c]]] [[d|e]] FooBar 𝖀𝖓𝖎𝖈𝖔𝖉𝖊𝓦𝓲𝓴𝓲𝓦𝓸𝓻𝓭𝓼 東京 [FooBaz] [FooQuux fnord] ');
  51. $page = get_page('action=links raw=1');
  52. test_page($page, split('\n',<<'EOT'));
  53. "a" -> "b"
  54. "a" -> "c"
  55. "a" -> "FooBar"
  56. "a" -> "𝖀𝖓𝖎𝖈𝖔𝖉𝖊𝓦𝓲𝓴𝓲𝓦𝓸𝓻𝓭𝓼"
  57. "a" -> "FooBaz"
  58. "a" -> "FooQuux"
  59. EOT
  60. test_page_negative($page, '"a" -> "d"');
  61. test_page_negative($page, '"a" -> "東京"'); # WikiWords can only work for languages where capitalization exists.
  62. AppendStringToFile($ConfigFile, "\$BracketWiki = 1;\n");
  63. update_page('a', '[[b]] [[[c]]] [[d|e]] FooBar 𝖀𝖓𝖎𝖈𝖔𝖉𝖊𝓦𝓲𝓴𝓲𝓦𝓸𝓻𝓭𝓼 [FooBaz] [FooQuux fnord] '
  64. . 'http://www.oddmuse.org/ [http://www.emacswiki.org/] '
  65. . '[http://www.communitywiki.org/ cw]');
  66. @Test1 = split('\n',<<'EOT');
  67. "a" -> "b"
  68. "a" -> "c"
  69. "a" -> "d"
  70. "a" -> "FooBar"
  71. "a" -> "𝖀𝖓𝖎𝖈𝖔𝖉𝖊𝓦𝓲𝓴𝓲𝓦𝓸𝓻𝓭𝓼"
  72. "a" -> "FooBaz"
  73. "a" -> "FooQuux"
  74. EOT
  75. @Test2 = split('\n',<<'EOT');
  76. "a" -> "http://www.oddmuse.org/"
  77. "a" -> "http://www.emacswiki.org/"
  78. "a" -> "http://www.communitywiki.org/"
  79. EOT
  80. $page = get_page('action=links raw=1');
  81. test_page($page, @Test1);
  82. test_page_negative($page, @Test2);
  83. $page = get_page('action=links raw=1 url=1');
  84. test_page($page, @Test1, @Test2);
  85. $page = get_page('action=links raw=1 links=0 url=1');
  86. test_page_negative($page, @Test1);
  87. test_page($page, @Test2);