xref: /plugin/davcal/vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\DAV;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehleruse Sabre\HTTP;
6*a1a3b679SAndreas Boehler
7*a1a3b679SAndreas Boehlerabstract class AbstractServer extends \PHPUnit_Framework_TestCase {
8*a1a3b679SAndreas Boehler
9*a1a3b679SAndreas Boehler    /**
10*a1a3b679SAndreas Boehler     * @var Sabre\HTTP\ResponseMock
11*a1a3b679SAndreas Boehler     */
12*a1a3b679SAndreas Boehler    protected $response;
13*a1a3b679SAndreas Boehler    protected $request;
14*a1a3b679SAndreas Boehler    /**
15*a1a3b679SAndreas Boehler     * @var Sabre\DAV\Server
16*a1a3b679SAndreas Boehler     */
17*a1a3b679SAndreas Boehler    protected $server;
18*a1a3b679SAndreas Boehler    protected $tempDir = SABRE_TEMPDIR;
19*a1a3b679SAndreas Boehler
20*a1a3b679SAndreas Boehler    function setUp() {
21*a1a3b679SAndreas Boehler
22*a1a3b679SAndreas Boehler        $this->response = new HTTP\ResponseMock();
23*a1a3b679SAndreas Boehler        $this->server = new Server($this->getRootNode());
24*a1a3b679SAndreas Boehler        $this->server->sapi = new HTTP\SapiMock();
25*a1a3b679SAndreas Boehler        $this->server->httpResponse = $this->response;
26*a1a3b679SAndreas Boehler        $this->server->debugExceptions = true;
27*a1a3b679SAndreas Boehler        $this->deleteTree(SABRE_TEMPDIR,false);
28*a1a3b679SAndreas Boehler        file_put_contents(SABRE_TEMPDIR . '/test.txt', 'Test contents');
29*a1a3b679SAndreas Boehler        mkdir(SABRE_TEMPDIR . '/dir');
30*a1a3b679SAndreas Boehler        file_put_contents(SABRE_TEMPDIR . '/dir/child.txt', 'Child contents');
31*a1a3b679SAndreas Boehler
32*a1a3b679SAndreas Boehler
33*a1a3b679SAndreas Boehler    }
34*a1a3b679SAndreas Boehler
35*a1a3b679SAndreas Boehler    function tearDown() {
36*a1a3b679SAndreas Boehler
37*a1a3b679SAndreas Boehler        $this->deleteTree(SABRE_TEMPDIR,false);
38*a1a3b679SAndreas Boehler
39*a1a3b679SAndreas Boehler    }
40*a1a3b679SAndreas Boehler
41*a1a3b679SAndreas Boehler    protected function getRootNode() {
42*a1a3b679SAndreas Boehler
43*a1a3b679SAndreas Boehler        return new FS\Directory(SABRE_TEMPDIR);
44*a1a3b679SAndreas Boehler
45*a1a3b679SAndreas Boehler    }
46*a1a3b679SAndreas Boehler
47*a1a3b679SAndreas Boehler    private function deleteTree($path,$deleteRoot = true) {
48*a1a3b679SAndreas Boehler
49*a1a3b679SAndreas Boehler        foreach(scandir($path) as $node) {
50*a1a3b679SAndreas Boehler
51*a1a3b679SAndreas Boehler            if ($node=='.' || $node=='.svn' || $node=='..') continue;
52*a1a3b679SAndreas Boehler            $myPath = $path.'/'. $node;
53*a1a3b679SAndreas Boehler            if (is_file($myPath)) {
54*a1a3b679SAndreas Boehler                unlink($myPath);
55*a1a3b679SAndreas Boehler            } else {
56*a1a3b679SAndreas Boehler                $this->deleteTree($myPath);
57*a1a3b679SAndreas Boehler            }
58*a1a3b679SAndreas Boehler
59*a1a3b679SAndreas Boehler        }
60*a1a3b679SAndreas Boehler        if ($deleteRoot) rmdir($path);
61*a1a3b679SAndreas Boehler
62*a1a3b679SAndreas Boehler    }
63*a1a3b679SAndreas Boehler
64*a1a3b679SAndreas Boehler}
65