1<?php
2
3include dirname(__FILE__) . '/../vendor/autoload.php';
4include dirname(__FILE__) . '/lib/DAVServerTest.php';
5
6use Sabre\HTTP;
7
8/**
9 * DAV tests for the webdav plugin
10 *
11 * @group plugin_webdav
12 * @group plugins
13 */
14class webdav_plugin_webdav_test extends DokuWikiTest
15{
16    public function setUp()
17    {
18        $this->server = new DAVServerTest;
19    }
20
21    public function testPropfindMethodStatus()
22    {
23        $response = $this->server->request(new HTTP\Request('PROPFIND', '/wiki'));
24        $this->assertEquals(207, $response->getStatus());
25    }
26
27    public function testGetMethodStatus()
28    {
29        $response = $this->server->request(new HTTP\Request('GET', '/wiki/pages/wiki/dokuwiki.txt'));
30        $this->assertEquals(200, $response->getStatus());
31    }
32
33    public function testNotFoundStatus()
34    {
35        $response = $this->server->request(new HTTP\Request('GET', '/wiki/pages/wiki/foo.txt'));
36        $this->assertEquals(404, $response->getStatus());
37    }
38
39    public function testProperties()
40    {
41        $propfind = <<<EOL
42<?xml version="1.0" encoding="utf-8" ?>
43<d:propfind xmlns:d="DAV:">
44    <d:prop xmlns:dw="http://dokuwiki.org/ns">
45        <d:creationdate/>
46        <d:getlastmodified/>
47        <d:getcontentlength/>
48        <d:getcontenttype/>
49        <d:resourcetype/>
50        <d:getetag/>
51        <d:displayname/>
52        <dw:id/>
53        <dw:title/>
54        <dw:description/>
55    </d:prop>
56</d:propfind>
57EOL;
58
59        $request = new HTTP\Request('PROPFIND', '/wiki/pages/wiki/dokuwiki.txt');
60        $request->setBody($propfind);
61        $response = $this->server->request($request);
62
63        $body = $response->getBodyAsString();
64
65        $xml = simplexml_load_string($body);
66        $xml->registerXPathNamespace('d', 'DAV:');
67        $xml->registerXPathNamespace('dw', 'http://dokuwiki.org/ns');
68
69        $paths = [
70            '/d:multistatus/d:response/d:href',
71            '/d:multistatus/d:response/d:propstat/d:prop/d:creationdate',
72            '/d:multistatus/d:response/d:propstat/d:prop/d:getlastmodified',
73            '/d:multistatus/d:response/d:propstat/d:prop/d:getcontentlength',
74            '/d:multistatus/d:response/d:propstat/d:prop/d:displayname',
75            '/d:multistatus/d:response/d:propstat/d:prop/dw:id',
76            '/d:multistatus/d:response/d:propstat/d:prop/dw:title',
77            '/d:multistatus/d:response/d:propstat/d:prop/dw:description',
78        ];
79
80        $this->assertEquals(207, $response->status);
81        $this->assertTrue(strpos($body, 'http://dokuwiki.org/ns') !== false, $body);
82
83        foreach ($paths as $path) {
84            $result = $xml->xpath($path);
85            $this->assertCount(1, $result, "XPath query $path");
86        }
87
88    }
89}
90