mojolicious-namespaces.t 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # Copyright (C) 2016 Alex Schroeder <alex@gnu.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. package OddMuse;
  16. use Test::More;
  17. use Test::Mojo;
  18. use utf8; # tests contain UTF-8 characters and it matters
  19. require './t/test.pl';
  20. add_module('namespaces.pl');
  21. # Before Perl 5.26, this appeared to be required because path_info is already
  22. # decoded!
  23. # AppendStringToFile($ConfigFile, <<'EOF');
  24. # sub GetNamespace {
  25. # my $ns = GetParam('ns', '');
  26. # if (not $ns and $UsePathInfo) {
  27. # my $path_info = $q->path_info();
  28. # # make sure ordinary page names are not matched!
  29. # if ($path_info =~ m|^/($InterSitePattern)(/.*)?|
  30. # and ($2 or $q->keywords or NamespaceRequiredByParameter())) {
  31. # $ns = $1;
  32. # }
  33. # }
  34. # ReportError(Ts('%s is not a legal name for a namespace', $ns))
  35. # if $ns and $ns !~ m/^($InterSitePattern)$/;
  36. # return $ns;
  37. # }
  38. # *GetId = \&NamespacesNewGetId;
  39. # sub NamespacesNewGetId {
  40. # my $id = UnquoteHtml(GetParam('id', GetParam('title', ''))); # id=x or title=x -> x
  41. # if (not $id and $q->keywords) {
  42. # $id = decode_utf8(join('_', $q->keywords)); # script?p+q -> p_q
  43. # }
  44. # if ($UsePathInfo and $q->path_info) {
  45. # my @path = split(/\//, $q->path_info);
  46. # $id ||= pop(@path); # script/p/q -> q
  47. # foreach my $p (@path) {
  48. # # https://campaignwiki.org/wiki/F%c3%bcnfWinde/G%c3%b6tter means that
  49. # # FünfWinde and Götter are both treated correctly.
  50. # SetParam($p, 1); # script/p/q -> p=1
  51. # }
  52. # }
  53. # # http://example.org/cgi-bin/wiki.pl?action=browse;ns=Test;id=Test means NamespaceCurrent=Test and id=Test
  54. # # http://example.org/cgi-bin/wiki.pl/Test/Test means NamespaceCurrent=Test and id=Test
  55. # # In this case GetId() will have set the parameter Test to 1.
  56. # # http://example.org/cgi-bin/wiki.pl/Test?rollback-1234=foo
  57. # # This doesn't set the Test parameter.
  58. # return if $id and $UsePathInfo and $id eq $NamespaceCurrent and not GetParam($id) and not GetParam('ns');
  59. # return $id;
  60. # }
  61. # EOF
  62. start_mojolicious_server();
  63. sleep(1);
  64. my $t = Test::Mojo->new;
  65. # Installation worked
  66. $t->get_ok("$ScriptName?action=version")
  67. ->content_like(qr/namespaces\.pl/);
  68. # Edit a page in the Main namespace
  69. $t->post_ok("$ScriptName"
  70. => form => {title => 'Some_Page',
  71. text => 'This is the Main namespace.'})
  72. ->status_is(302);
  73. $t->get_ok("$ScriptName/Some_Page")
  74. ->status_is(200)
  75. ->content_like(qr/This is the Main namespace/);
  76. # Edit a page in the Five Winds namespace
  77. $t->post_ok("$ScriptName/FiveWinds"
  78. => form => {title => 'Some_Page',
  79. text => 'This is the Five Winds namespace.'})
  80. ->status_is(302);
  81. $t->get_ok("$ScriptName/FiveWinds/Some_Page")
  82. ->status_is(200)
  83. ->content_like(qr/This is the Five Winds namespace/);
  84. # This didn't overwrite the Main namespace.
  85. $t->get_ok("$ScriptName/Some_Page")
  86. ->content_like(qr/This is the Main namespace/);
  87. # Umlauts
  88. $t->post_ok("$ScriptName/F%C3%BCnfWinde"
  89. => form => {title => 'Some_Page',
  90. text => 'Wir sind im Namensraum Fünf Winde.'})
  91. ->status_is(302);
  92. $t->get_ok("$ScriptName/F%C3%BCnfWinde/Some_Page")
  93. ->status_is(200)
  94. ->content_like(qr/Wir sind im Namensraum Fünf Winde/);
  95. ok(IsDir("$DataDir/FünfWinde"), '$DataDir FünfWinde exists');
  96. # Double trouble with Umlautes
  97. $t->post_ok("$ScriptName/F%C3%BCnfWinde"
  98. => form => {title => 'Zürich',
  99. text => 'Wir sind immer noch im Namensraum Fünf Winde.'})
  100. ->status_is(302);
  101. $t->get_ok("$ScriptName/F%C3%BCnfWinde/Z%c3%bcrich")
  102. ->status_is(200)
  103. ->content_like(qr/Wir sind immer noch im Namensraum Fünf Winde/);
  104. done_testing();