webdav.t 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (C) 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. require './t/test.pl';
  16. package OddMuse;
  17. use Test::More tests => 7;
  18. use LWP::UserAgent;
  19. add_module('webdav.pl');
  20. start_mojolicious_server();
  21. # Check whether the child is up and running
  22. my $ua = LWP::UserAgent->new;
  23. my $response = $ua->get("$ScriptName?action=version");
  24. ok($response->is_success, "There is a wiki running at $ScriptName");
  25. like($response->content, qr/\bwebdav\.pl/, "The server has the WebDAV extension installed");
  26. use HTTP::Request;
  27. my $request = HTTP::Request->new(OPTIONS => "$ScriptName/dav/");
  28. $response = $ua->request($request);
  29. ok($response->is_success, "WebDAV response coming from $ScriptName");
  30. ok($response->header('DAV'), "DAV header is set");
  31. ok($response->header('allow'), "Allow header is set: " . $response->header('allow'));
  32. SKIP: {
  33. $ENV{PATH} .= ':/usr/local/bin'; # maybe cadaver is installed locally
  34. if (qx'cadaver --version' !~ /^cadaver \d+\.\d+.\d+/, ) {
  35. skip("Cadaver is not installed", 2);
  36. }
  37. like(qx"echo ls | cadaver $ScriptName/dav/",
  38. qr/^Listing collection `\/wiki\/dav\/': collection is empty\./m,
  39. "ls");
  40. open(my $fh, ">", "$TempDir/foo") or die "Cannot write $TempDir/foo: $!";
  41. print $fh "this is a test\n";
  42. close($fh);
  43. like(qx"echo put $TempDir/foo | cadaver $ScriptName/dav/",
  44. qr/^Uploading $TempDir\/foo to `\/wiki\/dav\/foo'/m,
  45. "put");
  46. }