moved deprecated communityhome, dav and yourls to the deprecated-addons repository

This commit is contained in:
Tobias Diekershoff 2018-06-02 11:23:11 +02:00
commit 31520f804d
675 changed files with 195144 additions and 0 deletions

View file

@ -0,0 +1,63 @@
<?php
class Sabre_DAV_Property_GetLastModifiedTest extends PHPUnit_Framework_TestCase {
function testConstructDateTime() {
$dt = new DateTime('2010-03-14 16:35', new DateTimeZone('UTC'));
$lastMod = new Sabre_DAV_Property_GetLastModified($dt);
$this->assertEquals($dt->format(DateTime::ATOM), $lastMod->getTime()->format(DateTime::ATOM));
}
function testConstructString() {
$dt = new DateTime('2010-03-14 16:35', new DateTimeZone('UTC'));
$lastMod = new Sabre_DAV_Property_GetLastModified('2010-03-14 16:35');
$this->assertEquals($dt->format(DateTime::ATOM), $lastMod->getTime()->format(DateTime::ATOM));
}
function testConstructInt() {
$dt = new DateTime('2010-03-14 16:35', new DateTimeZone('UTC'));
$lastMod = new Sabre_DAV_Property_GetLastModified((int)$dt->format('U'));
$this->assertEquals($dt->format(DateTime::ATOM), $lastMod->getTime()->format(DateTime::ATOM));
}
function testSerialize() {
$dt = new DateTime('2010-03-14 16:35', new DateTimeZone('UTC'));
$lastMod = new Sabre_DAV_Property_GetLastModified($dt);
$doc = new DOMDocument();
$root = $doc->createElement('d:getlastmodified');
$root->setAttribute('xmlns:d','DAV:');
$doc->appendChild($root);
$objectTree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('rootdir'));
$server = new Sabre_DAV_Server($objectTree);
$lastMod->serialize($server, $root);
$xml = $doc->saveXML();
$this->assertEquals(
'<?xml version="1.0"?>
<d:getlastmodified xmlns:d="DAV:" xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" b:dt="dateTime.rfc1123">' .
Sabre_HTTP_Util::toHTTPDate($dt) .
'</d:getlastmodified>
', $xml);
$ok = false;
try {
Sabre_DAV_Property_GetLastModified::unserialize(Sabre_DAV_XMLUtil::loadDOMDocument($xml)->firstChild);
} catch (Sabre_DAV_Exception $e) {
$ok = true;
}
if (!$ok) $this->markTestFailed('Unserialize should not be supported');
}
}

View file

@ -0,0 +1,88 @@
<?php
class Sabre_DAV_Property_HrefListTest extends PHPUnit_Framework_TestCase {
function testConstruct() {
$href = new Sabre_DAV_Property_HrefList(array('foo','bar'));
$this->assertEquals(array('foo','bar'),$href->getHrefs());
}
function testSerialize() {
$href = new Sabre_DAV_Property_HrefList(array('foo','bar'));
$this->assertEquals(array('foo','bar'),$href->getHrefs());
$doc = new DOMDocument();
$root = $doc->createElement('d:anything');
$root->setAttribute('xmlns:d','DAV:');
$doc->appendChild($root);
$server = new Sabre_DAV_Server();
$server->setBaseUri('/bla/');
$href->serialize($server, $root);
$xml = $doc->saveXML();
$this->assertEquals(
'<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href>/bla/foo</d:href><d:href>/bla/bar</d:href></d:anything>
', $xml);
}
function testSerializeNoPrefix() {
$href = new Sabre_DAV_Property_HrefList(array('foo','bar'), false);
$this->assertEquals(array('foo','bar'),$href->getHrefs());
$doc = new DOMDocument();
$root = $doc->createElement('d:anything');
$root->setAttribute('xmlns:d','DAV:');
$doc->appendChild($root);
$server = new Sabre_DAV_Server();
$server->setBaseUri('/bla/');
$href->serialize($server, $root);
$xml = $doc->saveXML();
$this->assertEquals(
'<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href>foo</d:href><d:href>bar</d:href></d:anything>
', $xml);
}
function testUnserialize() {
$xml = '<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href>/bla/foo</d:href><d:href>/bla/bar</d:href></d:anything>
';
$dom = new DOMDocument();
$dom->loadXML($xml);
$href = Sabre_DAV_Property_HrefList::unserialize($dom->firstChild);
$this->assertEquals(array('/bla/foo','/bla/bar'),$href->getHrefs());
}
function testUnserializeIncompatible() {
$xml = '<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href2>/bla/foo</d:href2></d:anything>
';
$dom = new DOMDocument();
$dom->loadXML($xml);
$href = Sabre_DAV_Property_HrefList::unserialize($dom->firstChild);
$this->assertEquals(array(), $href->getHrefs());
}
}

View file

@ -0,0 +1,88 @@
<?php
class Sabre_DAV_Property_HrefTest extends PHPUnit_Framework_TestCase {
function testConstruct() {
$href = new Sabre_DAV_Property_Href('path');
$this->assertEquals('path',$href->getHref());
}
function testSerialize() {
$href = new Sabre_DAV_Property_Href('path');
$this->assertEquals('path',$href->getHref());
$doc = new DOMDocument();
$root = $doc->createElement('d:anything');
$root->setAttribute('xmlns:d','DAV:');
$doc->appendChild($root);
$server = new Sabre_DAV_Server();
$server->setBaseUri('/bla/');
$href->serialize($server, $root);
$xml = $doc->saveXML();
$this->assertEquals(
'<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href>/bla/path</d:href></d:anything>
', $xml);
}
function testSerializeNoPrefix() {
$href = new Sabre_DAV_Property_Href('path',false);
$this->assertEquals('path',$href->getHref());
$doc = new DOMDocument();
$root = $doc->createElement('d:anything');
$root->setAttribute('xmlns:d','DAV:');
$doc->appendChild($root);
$server = new Sabre_DAV_Server();
$server->setBaseUri('/bla/');
$href->serialize($server, $root);
$xml = $doc->saveXML();
$this->assertEquals(
'<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href>path</d:href></d:anything>
', $xml);
}
function testUnserialize() {
$xml = '<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href>/bla/path</d:href></d:anything>
';
$dom = new DOMDocument();
$dom->loadXML($xml);
$href = Sabre_DAV_Property_Href::unserialize($dom->firstChild);
$this->assertEquals('/bla/path',$href->getHref());
}
function testUnserializeIncompatible() {
$xml = '<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href2>/bla/path</d:href2></d:anything>
';
$dom = new DOMDocument();
$dom->loadXML($xml);
$href = Sabre_DAV_Property_Href::unserialize($dom->firstChild);
$this->assertNull($href);
}
}

View file

@ -0,0 +1,107 @@
<?php
class Sabre_DAV_Property_ResourceTypeTest extends PHPUnit_Framework_TestCase {
function testConstruct() {
$resourceType = new Sabre_DAV_Property_ResourceType(array('{DAV:}collection'));
$this->assertEquals(array('{DAV:}collection'),$resourceType->getValue());
$resourceType = new Sabre_DAV_Property_ResourceType(Sabre_DAV_Server::NODE_FILE);
$this->assertEquals(array(),$resourceType->getValue());
$resourceType = new Sabre_DAV_Property_ResourceType(Sabre_DAV_Server::NODE_DIRECTORY);
$this->assertEquals(array('{DAV:}collection'),$resourceType->getValue());
$resourceType = new Sabre_DAV_Property_ResourceType('{DAV:}principal');
$this->assertEquals(array('{DAV:}principal'),$resourceType->getValue());
}
/**
* @depends testConstruct
*/
function testSerialize() {
$resourceType = new Sabre_DAV_Property_ResourceType(array('{DAV:}collection','{DAV:}principal'));
$doc = new DOMDocument();
$root = $doc->createElement('d:anything');
$root->setAttribute('xmlns:d','DAV:');
$doc->appendChild($root);
$server = new Sabre_DAV_Server();
$resourceType->serialize($server, $root);
$xml = $doc->saveXML();
$this->assertEquals(
'<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:collection/><d:principal/></d:anything>
', $xml);
}
/**
* @depends testSerialize
*/
function testSerializeCustomNS() {
$resourceType = new Sabre_DAV_Property_ResourceType(array('{http://example.org/NS}article'));
$doc = new DOMDocument();
$root = $doc->createElement('d:anything');
$root->setAttribute('xmlns:d','DAV:');
$doc->appendChild($root);
$server = new Sabre_DAV_Server();
$resourceType->serialize($server, $root);
$xml = $doc->saveXML();
$this->assertEquals(
'<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><custom:article xmlns:custom="http://example.org/NS"/></d:anything>
', $xml);
}
/**
* @depends testConstruct
*/
function testIs() {
$resourceType = new Sabre_DAV_Property_ResourceType(array('{DAV:}collection','{DAV:}principal'));
$this->assertTrue($resourceType->is('{DAV:}collection'));
$this->assertFalse($resourceType->is('{DAV:}blabla'));
}
/**
* @depends testConstruct
*/
function testAdd() {
$resourceType = new Sabre_DAV_Property_ResourceType(array('{DAV:}collection','{DAV:}principal'));
$resourceType->add('{DAV:}foo');
$this->assertEquals(array('{DAV:}collection','{DAV:}principal','{DAV:}foo'), $resourceType->getValue());
}
/**
* @depends testConstruct
*/
function testUnserialize() {
$xml ='<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:collection/><d:principal/></d:anything>
';
$dom = Sabre_DAV_XMLUtil::loadDOMDocument($xml);
$resourceType = Sabre_DAV_Property_ResourceType::unserialize($dom->firstChild);
$this->assertEquals(array('{DAV:}collection','{DAV:}principal'),$resourceType->getValue());
}
}

View file

@ -0,0 +1,231 @@
<?php
class Sabre_DAV_Property_ResponseTest extends PHPUnit_Framework_TestCase {
function testSimple() {
$innerProps = array(
200 => array(
'{DAV:}displayname' => 'my file',
),
404 => array(
'{DAV:}owner' => null,
)
);
$property = new Sabre_DAV_Property_Response('uri',$innerProps);
$this->assertEquals('uri',$property->getHref());
$this->assertEquals($innerProps,$property->getResponseProperties());
}
/**
* @depends testSimple
*/
function testSerialize() {
$innerProps = array(
200 => array(
'{DAV:}displayname' => 'my file',
),
404 => array(
'{DAV:}owner' => null,
)
);
$property = new Sabre_DAV_Property_Response('uri',$innerProps);
$doc = new DOMDocument();
$root = $doc->createElement('d:root');
$root->setAttribute('xmlns:d','DAV:');
$doc->appendChild($root);
$objectTree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('rootdir'));
$server = new Sabre_DAV_Server($objectTree);
$property->serialize($server, $root);
$xml = $doc->saveXML();
$this->assertEquals(
'<?xml version="1.0"?>
<d:root xmlns:d="DAV:">' .
'<d:response>' .
'<d:href>/uri</d:href>' .
'<d:propstat>' .
'<d:prop>' .
'<d:displayname>my file</d:displayname>' .
'</d:prop>' .
'<d:status>HTTP/1.1 200 OK</d:status>' .
'</d:propstat>' .
'<d:propstat>' .
'<d:prop>' .
'<d:owner/>' .
'</d:prop>' .
'<d:status>HTTP/1.1 404 Not Found</d:status>' .
'</d:propstat>' .
'</d:response>' .
'</d:root>
', $xml);
}
/**
* This one is specifically for testing properties with no namespaces, which is legal xml
*
* @depends testSerialize
*/
function testSerializeEmptyNamespace() {
$innerProps = array(
200 => array(
'{}propertyname' => 'value',
),
);
$property = new Sabre_DAV_Property_Response('uri',$innerProps);
$doc = new DOMDocument();
$root = $doc->createElement('d:root');
$root->setAttribute('xmlns:d','DAV:');
$doc->appendChild($root);
$objectTree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('rootdir'));
$server = new Sabre_DAV_Server($objectTree);
$property->serialize($server, $root);
$xml = $doc->saveXML();
$this->assertEquals(
'<?xml version="1.0"?>
<d:root xmlns:d="DAV:">' .
'<d:response>' .
'<d:href>/uri</d:href>' .
'<d:propstat>' .
'<d:prop>' .
'<propertyname xmlns="">value</propertyname>' .
'</d:prop>' .
'<d:status>HTTP/1.1 200 OK</d:status>' .
'</d:propstat>' .
'</d:response>' .
'</d:root>
', $xml);
}
/**
* This one is specifically for testing properties with no namespaces, which is legal xml
*
* @depends testSerialize
*/
function testSerializeCustomNamespace() {
$innerProps = array(
200 => array(
'{http://sabredav.org/NS/example}propertyname' => 'value',
),
);
$property = new Sabre_DAV_Property_Response('uri',$innerProps);
$doc = new DOMDocument();
$root = $doc->createElement('d:root');
$root->setAttribute('xmlns:d','DAV:');
$doc->appendChild($root);
$objectTree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('rootdir'));
$server = new Sabre_DAV_Server($objectTree);
$property->serialize($server, $root);
$xml = $doc->saveXML();
$this->assertEquals(
'<?xml version="1.0"?>
<d:root xmlns:d="DAV:">' .
'<d:response>' .
'<d:href>/uri</d:href>' .
'<d:propstat>' .
'<d:prop>' .
'<x2:propertyname xmlns:x2="http://sabredav.org/NS/example">value</x2:propertyname>' .
'</d:prop>' .
'<d:status>HTTP/1.1 200 OK</d:status>' .
'</d:propstat>' .
'</d:response>' .
'</d:root>
', $xml);
}
/**
* @depends testSerialize
*/
function testSerializeComplexProperty() {
$innerProps = array(
200 => array(
'{DAV:}link' => new Sabre_DAV_Property_Href('http://sabredav.org/', false)
),
);
$property = new Sabre_DAV_Property_Response('uri',$innerProps);
$doc = new DOMDocument();
$root = $doc->createElement('d:root');
$root->setAttribute('xmlns:d','DAV:');
$doc->appendChild($root);
$objectTree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('rootdir'));
$server = new Sabre_DAV_Server($objectTree);
$property->serialize($server, $root);
$xml = $doc->saveXML();
$this->assertEquals(
'<?xml version="1.0"?>
<d:root xmlns:d="DAV:">' .
'<d:response>' .
'<d:href>/uri</d:href>' .
'<d:propstat>' .
'<d:prop>' .
'<d:link><d:href>http://sabredav.org/</d:href></d:link>' .
'</d:prop>' .
'<d:status>HTTP/1.1 200 OK</d:status>' .
'</d:propstat>' .
'</d:response>' .
'</d:root>
', $xml);
}
/**
* @depends testSerialize
* @expectedException Sabre_DAV_Exception
*/
function testSerializeBreak() {
$innerProps = array(
200 => array(
'{DAV:}link' => new STDClass()
),
);
$property = new Sabre_DAV_Property_Response('uri',$innerProps);
$doc = new DOMDocument();
$root = $doc->createElement('d:root');
$root->setAttribute('xmlns:d','DAV:');
$doc->appendChild($root);
$objectTree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('rootdir'));
$server = new Sabre_DAV_Server($objectTree);
$property->serialize($server, $root);
}
}

View file

@ -0,0 +1,123 @@
<?php
require_once 'Sabre/HTTP/ResponseMock.php';
require_once 'Sabre/DAV/AbstractServer.php';
class Sabre_DAV_Property_SupportedReportSetTest extends Sabre_DAV_AbstractServer {
public function sendPROPFIND($body) {
$serverVars = array(
'REQUEST_URI' => '/',
'REQUEST_METHOD' => 'PROPFIND',
'HTTP_DEPTH' => '0',
);
$request = new Sabre_HTTP_Request($serverVars);
$request->setBody($body);
$this->server->httpRequest = ($request);
$this->server->exec();
}
/**
* @covers Sabre_DAV_Property_SupportedReportSet
*/
function testNoReports() {
$xml = '<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:">
<d:prop>
<d:supported-report-set />
</d:prop>
</d:propfind>';
$this->sendPROPFIND($xml);
$this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'We expected a multi-status response. Full response body: ' . $this->response->body);
$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"DAV:\"",$this->response->body);
$xml = simplexml_load_string($body);
$xml->registerXPathNamespace('d','DAV:');
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop');
$this->assertEquals(1,count($data),'We expected 1 \'d:prop\' element');
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set');
$this->assertEquals(1,count($data),'We expected 1 \'d:supported-report-set\' element');
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status');
$this->assertEquals(1,count($data),'We expected 1 \'d:status\' element');
$this->assertEquals('HTTP/1.1 200 OK',(string)$data[0],'The status for this property should have been 200');
}
/**
* @covers Sabre_DAV_Property_SupportedReportSet
* @depends testNoReports
*/
function testCustomReport() {
// Intercepting the report property
$this->server->subscribeEvent('afterGetProperties',array($this,'addProp'));
$xml = '<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:">
<d:prop>
<d:supported-report-set />
</d:prop>
</d:propfind>';
$this->sendPROPFIND($xml);
$this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'We expected a multi-status response. Full response body: ' . $this->response->body);
$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"DAV:\"",$this->response->body);
$xml = simplexml_load_string($body);
$xml->registerXPathNamespace('d','DAV:');
$xml->registerXPathNamespace('x','http://www.rooftopsolutions.nl/testnamespace');
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop');
$this->assertEquals(1,count($data),'We expected 1 \'d:prop\' element');
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set');
$this->assertEquals(1,count($data),'We expected 1 \'d:supported-report-set\' element');
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report');
$this->assertEquals(2,count($data),'We expected 2 \'d:supported-report\' elements');
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report/d:report');
$this->assertEquals(2,count($data),'We expected 2 \'d:report\' elements');
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report/d:report/x:myreport');
$this->assertEquals(1,count($data),'We expected 1 \'x:myreport\' element. Full body: ' . $this->response->body);
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report/d:report/d:anotherreport');
$this->assertEquals(1,count($data),'We expected 1 \'d:anotherreport\' element. Full body: ' . $this->response->body);
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status');
$this->assertEquals(1,count($data),'We expected 1 \'d:status\' element');
$this->assertEquals('HTTP/1.1 200 OK',(string)$data[0],'The status for this property should have been 200');
}
/**
* This method is used as a callback for afterGetProperties
*/
function addProp($path, &$properties) {
if (isset($properties[200]['{DAV:}supported-report-set'])) {
$properties[200]['{DAV:}supported-report-set']->addReport('{http://www.rooftopsolutions.nl/testnamespace}myreport');
$properties[200]['{DAV:}supported-report-set']->addReport('{DAV:}anotherreport');
}
}
}
?>