mojolicious-namespaces.t 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # Copyright (C) 2016-2019 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. my $t = Test::Mojo->new;
  64. # Installation worked
  65. $t->get_ok("$ScriptName?action=version")
  66. ->content_like(qr/namespaces\.pl/);
  67. # Edit a page in the Main namespace
  68. $t->post_ok("$ScriptName"
  69. => form => {title => 'Some_Page',
  70. text => 'This is the Main namespace.'})
  71. ->status_is(302);
  72. $t->get_ok("$ScriptName/Some_Page")
  73. ->status_is(200)
  74. ->content_like(qr/This is the Main namespace/);
  75. # Edit a page in the Five Winds namespace
  76. $t->post_ok("$ScriptName/FiveWinds"
  77. => form => {title => 'Some_Page',
  78. text => 'This is the Five Winds namespace.'})
  79. ->status_is(302);
  80. $t->get_ok("$ScriptName/FiveWinds/Some_Page")
  81. ->status_is(200)
  82. ->content_like(qr/This is the Five Winds namespace/);
  83. # This didn't overwrite the Main namespace.
  84. $t->get_ok("$ScriptName/Some_Page")
  85. ->content_like(qr/This is the Main namespace/);
  86. # Umlauts
  87. $t->post_ok("$ScriptName/F%C3%BCnfWinde"
  88. => form => {title => 'Some_Page',
  89. text => 'Wir sind im Namensraum Fünf Winde.'})
  90. ->status_is(302);
  91. $t->get_ok("$ScriptName/F%C3%BCnfWinde/Some_Page")
  92. ->status_is(200)
  93. ->content_like(qr/Wir sind im Namensraum Fünf Winde/);
  94. ok(IsDir("$DataDir/FünfWinde"), '$DataDir FünfWinde exists');
  95. # Double trouble with Umlautes
  96. $t->post_ok("$ScriptName/F%C3%BCnfWinde"
  97. => form => {title => 'Zürich',
  98. text => 'Wir sind immer noch im Namensraum Fünf Winde.'})
  99. ->status_is(302);
  100. $t->get_ok("$ScriptName/F%C3%BCnfWinde/Z%c3%bcrich")
  101. ->status_is(200)
  102. ->content_like(qr/Wir sind immer noch im Namensraum Fünf Winde/);
  103. done_testing();