localnames.t 4.9 KB

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