2013-10-21 22:46:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Sabre\DAV;
|
|
|
|
|
|
|
|
use Sabre\HTTP;
|
|
|
|
|
|
|
|
abstract class AbstractServer extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Sabre\HTTP\ResponseMock
|
|
|
|
*/
|
|
|
|
protected $response;
|
|
|
|
protected $request;
|
|
|
|
/**
|
|
|
|
* @var Sabre\DAV\Server
|
|
|
|
*/
|
|
|
|
protected $server;
|
|
|
|
protected $tempDir = SABRE_TEMPDIR;
|
|
|
|
|
|
|
|
function setUp() {
|
|
|
|
|
|
|
|
$this->response = new HTTP\ResponseMock();
|
|
|
|
$this->server = new Server($this->getRootNode());
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->server->sapi = new HTTP\SapiMock();
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->server->httpResponse = $this->response;
|
|
|
|
$this->server->debugExceptions = true;
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->deleteTree(SABRE_TEMPDIR, false);
|
2013-10-21 22:46:31 +00:00
|
|
|
file_put_contents(SABRE_TEMPDIR . '/test.txt', 'Test contents');
|
|
|
|
mkdir(SABRE_TEMPDIR . '/dir');
|
|
|
|
file_put_contents(SABRE_TEMPDIR . '/dir/child.txt', 'Child contents');
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function tearDown() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->deleteTree(SABRE_TEMPDIR, false);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getRootNode() {
|
|
|
|
|
|
|
|
return new FS\Directory(SABRE_TEMPDIR);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
private function deleteTree($path, $deleteRoot = true) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
foreach (scandir($path) as $node) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
if ($node == '.' || $node == '.svn' || $node == '..') continue;
|
|
|
|
$myPath = $path . '/' . $node;
|
2013-10-21 22:46:31 +00:00
|
|
|
if (is_file($myPath)) {
|
|
|
|
unlink($myPath);
|
|
|
|
} else {
|
|
|
|
$this->deleteTree($myPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if ($deleteRoot) rmdir($path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|