1<?php
2
3namespace Sabre\DAV\Mount;
4
5use Sabre\DAV;
6use Sabre\HTTP;
7
8require_once 'Sabre/DAV/AbstractServer.php';
9
10class PluginTest extends DAV\AbstractServer {
11
12    function setUp() {
13
14        parent::setUp();
15        $this->server->addPlugin(new Plugin());
16
17    }
18
19    function testPassThrough() {
20
21        $serverVars = array(
22            'REQUEST_URI'    => '/',
23            'REQUEST_METHOD' => 'GET',
24        );
25
26        $request = HTTP\Sapi::createFromServerArray($serverVars);
27        $this->server->httpRequest = ($request);
28        $this->server->exec();
29
30        $this->assertEquals(501, $this->response->status,'We expected GET to not be implemented for Directories. Response body: ' . $this->response->body);
31
32    }
33
34    function testMountResponse() {
35
36        $serverVars = array(
37            'REQUEST_URI'    => '/?mount',
38            'REQUEST_METHOD' => 'GET',
39            'QUERY_STRING'   => 'mount',
40            'HTTP_HOST'      => 'example.org',
41        );
42
43        $request = HTTP\Sapi::createFromServerArray($serverVars);
44        $this->server->httpRequest = ($request);
45        $this->server->exec();
46
47        $this->assertEquals(200, $this->response->status);
48
49        $xml = simplexml_load_string($this->response->body);
50        $this->assertInstanceOf('SimpleXMLElement',$xml, 'Response was not a valid xml document. The list of errors:' . print_r(libxml_get_errors(),true) . '. xml body: ' . $this->response->body . '. What type we got: ' . gettype($xml) . ' class, if object: ' . get_class($xml));
51
52        $xml->registerXPathNamespace('dm','http://purl.org/NET/webdav/mount');
53        $url = $xml->xpath('//dm:url');
54        $this->assertEquals('http://example.org/',(string)$url[0]);
55
56    }
57
58}
59