~jamesh/storage-provider-webdav/landing-20161118

« back to all changes in this revision

Viewing changes to tests/utils/sabredav-server.php

  • Committer: Tarmac
  • Author(s): James Henstridge
  • Date: 2016-09-23 05:03:11 UTC
  • mfrom: (7.1.13 provider-test-fixture)
  • Revision ID: tarmac-20160923050311-bb3m6zal58cpccqu
Add test infrastructure for testing DavProvider.

Approved by Michi Henning, unity-api-1-bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
// settings
 
4
date_default_timezone_set('UTC');
 
5
$publicDir = getcwd();
 
6
 
 
7
// The SabreDAV autoloader in Vivid is broken, so add one that just loads
 
8
// arbitrary files from /usr/share/php.
 
9
spl_autoload_register(function($class_name) {
 
10
    $file = "/usr/share/php/" . str_replace("\\", "/", $class_name) . ".php";
 
11
    if (file_exists($file)) {
 
12
        require_once $file;
 
13
    }
 
14
});
 
15
 
 
16
class DummyAuth extends \Sabre\DAV\Auth\Backend\AbstractBasic {
 
17
    protected function validateUserPass($username, $password) {
 
18
        return true;
 
19
    }
 
20
}
 
21
 
 
22
// Make sure there is a directory in your current directory named 'public'. We will be exposing that directory to WebDAV
 
23
$rootNode = new \Sabre\DAV\FS\Directory($publicDir);
 
24
 
 
25
// The rootNode needs to be passed to the server object.
 
26
$server = new \Sabre\DAV\Server($rootNode);
 
27
 
 
28
$server->addPlugin(new \Sabre\DAV\Auth\Plugin(new DummyAuth(), "realm"));
 
29
$server->addPlugin(new \Sabre\DAV\Browser\GuessContentType());
 
30
 
 
31
// And off we go!
 
32
$server->exec();