localnames.t 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # Copyright (C) 2006 Alex Schroeder <alex@emacswiki.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 => 19;
  18. use Cwd;
  19. $dir = cwd;
  20. $uri = "file://$dir/t/feeds";
  21. $uri =~ s/ /%20/g; # for cygdrive stuff including spaces
  22. add_module('localnames.pl');
  23. xpath_test(update_page('LocalNames', "* [http://www.oddmuse.org/ OddMuse]\n"
  24. . "* [[ln:$uri/ln.txt]]\n"
  25. . "* [[ln:$uri/ln.txt Lion's Namespace]]\n"),
  26. '//ul/li/a[@class="url http outside"][@href="http://www.oddmuse.org/"][text()="OddMuse"]',
  27. '//ul/li/a[@class="url outside ln"][@href="' . $uri . '/ln.txt"][text()="' . $uri . '/ln.txt"]',
  28. '//ul/li/a[@class="url outside ln"][@href="' . $uri . '/ln.txt"][text()="Lion\'s Namespace"]');
  29. InitVariables();
  30. $WikiLinks = 1;
  31. xpath_run_tests(split('\n',<<'EOT'));
  32. [http://www.oddmuse.org/ OddMuse]
  33. //a[@class="url http outside"][@href="http://www.oddmuse.org/"][text()="OddMuse"]
  34. OddMuse
  35. //a[@class="near"][@title="LocalNames"][@href="http://www.oddmuse.org/"][text()="OddMuse"]
  36. EOT
  37. AppendStringToFile($ConfigFile, "\$WikiLinks = 1;\n");
  38. # now check whether the integration with InitVariables works
  39. $page = update_page('LocalNamesTest', 'OddMuse [[my blog]]');
  40. xpath_test($page, '//a[@class="near"][@title="LocalNames"][@href="http://www.oddmuse.org/"][text()="OddMuse"]');
  41. SKIP: {
  42. eval {
  43. require LWP::UserAgent;
  44. };
  45. skip "LWP::UserAgent not installed", 1 if $@;
  46. xpath_test($page, '//a[@class="near"][@title="LocalNames"][@href="http://lion.taoriver.net/"][text()="my blog"]');
  47. }
  48. # verify that automatic update is off by default
  49. xpath_test(update_page('LocalNamesTest', 'This is an [http://www.example.org/ Example].'),
  50. '//a[@class="url http outside"][@href="http://www.example.org/"][text()="Example"]');
  51. negative_xpath_test(get_page('LocalNames'),
  52. '//ul/li/a[@class="url http outside"][@href="http://www.example.org/"][text()="Example"]');
  53. # check automatic update
  54. AppendStringToFile($ConfigFile, "\$LocalNamesCollect = 1;\n");
  55. xpath_test(update_page('LocalNamesTest', 'This is an [http://www.example.com/ Example].'),
  56. '//a[@class="url http outside"][@href="http://www.example.com/"][text()="Example"]');
  57. xpath_test(get_page('LocalNames'),
  58. '//ul/li/a[@class="url http outside"][@href="http://www.example.com/"][text()="Example"]');
  59. $LocalNamesInit = 0;
  60. LocalNamesInit();
  61. xpath_run_tests(split('\n',<<'EOT'));
  62. OddMuse
  63. //a[@class="near"][@title="LocalNames"][@href="http://www.oddmuse.org/"][text()="OddMuse"]
  64. [[Example]]
  65. //a[@class="near"][@title="LocalNames"][@href="http://www.example.com/"][text()="Example"]
  66. EOT
  67. xpath_test(get_page('action=rc days=1 showedit=1'),
  68. '//a[@class="local"][text()="LocalNames"]/following-sibling::strong[text()="Local names defined on LocalNamesTest: Example"]');
  69. # more definitions on one page
  70. update_page('LocalNamesTest', 'This is an [http://www.example.org/ Example] for [http://www.emacswiki.org EmacsWiki].');
  71. xpath_test(get_page('action=rc days=1 showedit=1'),
  72. '//a[@class="local"][text()="LocalNames"]/following-sibling::strong[text()="Local names defined on LocalNamesTest: EmacsWiki, and Example"]');
  73. update_page('LocalNamesTest', 'This is an [http://www.example.com/ Example] for [http://www.emacswiki.org/ EmacsWiki] and [http://communitywiki.org/ Community Wiki].');
  74. xpath_test(get_page('action=rc days=1 showedit=1'),
  75. '//a[@class="local"][text()="LocalNames"]/following-sibling::strong[text()="Local names defined on LocalNamesTest: Community Wiki, EmacsWiki, and Example"]');
  76. update_page('LocalNamesTest', 'This is [http://www.example.com/ one Example].');
  77. xpath_test(get_page('LocalNames'),
  78. '//ul/li/a[@class="url http outside"][@href="http://www.example.com/"][text()="one Example"]');
  79. update_page('LocalNamesTest', 'This is [http://www.example.com/ one simple Example].');
  80. negative_xpath_test(get_page('LocalNames'),
  81. '//ul/li/a[@class="url http outside"][@href="http://www.example.com/"][text()="one simple Example"]');
  82. AppendStringToFile($ConfigFile, "\$LocalNamesCollectMaxWords = 1;\n");
  83. update_page('LocalNamesTest', 'This is [http://www.example.com/ Example one].');
  84. negative_xpath_test(get_page('LocalNames'),
  85. '//ul/li/a[@class="url http outside"][@href="http://www.example.com/"][text()="Example one"]');