createElementNS('DAV:','d:root');
$dom->appendChild($root);
$acl = new Sabre_DAVACL_Property_Acl(array());
$acl->serialize(new Sabre_DAV_Server(), $root);
$xml = $dom->saveXML();
$expected = '
';
$this->assertEquals($expected, $xml);
}
function testSerialize() {
$dom = new DOMDocument('1.0');
$root = $dom->createElementNS('DAV:','d:root');
$dom->appendChild($root);
$privileges = array(
array(
'principal' => 'principals/evert',
'privilege' => '{DAV:}write',
'uri' => 'articles',
),
array(
'principal' => 'principals/foo',
'privilege' => '{DAV:}read',
'uri' => 'articles',
'protected' => true,
),
);
$acl = new Sabre_DAVACL_Property_Acl($privileges);
$acl->serialize(new Sabre_DAV_Server(), $root);
$dom->formatOutput = true;
$xml = $dom->saveXML();
$expected = '
/principals/evert/
/principals/foo/
';
$this->assertEquals($expected, $xml);
}
function testSerializeSpecialPrincipals() {
$dom = new DOMDocument('1.0');
$root = $dom->createElementNS('DAV:','d:root');
$dom->appendChild($root);
$privileges = array(
array(
'principal' => '{DAV:}authenticated',
'privilege' => '{DAV:}write',
'uri' => 'articles',
),
array(
'principal' => '{DAV:}unauthenticated',
'privilege' => '{DAV:}write',
'uri' => 'articles',
),
array(
'principal' => '{DAV:}all',
'privilege' => '{DAV:}write',
'uri' => 'articles',
),
);
$acl = new Sabre_DAVACL_Property_Acl($privileges);
$acl->serialize(new Sabre_DAV_Server(), $root);
$dom->formatOutput = true;
$xml = $dom->saveXML();
$expected = '
';
$this->assertEquals($expected, $xml);
}
function testUnserialize() {
$source = '
/principals/evert/
/principals/foo/
';
$dom = Sabre_DAV_XMLUtil::loadDOMDocument($source);
$result = Sabre_DAVACL_Property_Acl::unserialize($dom->firstChild);
$this->assertInstanceOf('Sabre_DAVACL_Property_Acl', $result);
$expected = array(
array(
'principal' => '/principals/evert/',
'protected' => false,
'privilege' => '{DAV:}write',
),
array(
'principal' => '/principals/foo/',
'protected' => true,
'privilege' => '{DAV:}read',
),
);
$this->assertEquals($expected, $result->getPrivileges());
}
/**
* @expectedException Sabre_DAV_Exception_BadRequest
*/
function testUnserializeNoPrincipal() {
$source = '
';
$dom = Sabre_DAV_XMLUtil::loadDOMDocument($source);
Sabre_DAVACL_Property_Acl::unserialize($dom->firstChild);
}
function testUnserializeOtherPrincipal() {
$source = '
';
$dom = Sabre_DAV_XMLUtil::loadDOMDocument($source);
$result = Sabre_DAVACL_Property_Acl::unserialize($dom->firstChild);
$this->assertInstanceOf('Sabre_DAVACL_Property_Acl', $result);
$expected = array(
array(
'principal' => '{DAV:}authenticated',
'protected' => false,
'privilege' => '{DAV:}write',
),
array(
'principal' => '{DAV:}unauthenticated',
'protected' => false,
'privilege' => '{DAV:}write',
),
array(
'principal' => '{DAV:}all',
'protected' => false,
'privilege' => '{DAV:}write',
),
);
$this->assertEquals($expected, $result->getPrivileges());
}
/**
* @expectedException Sabre_DAV_Exception_NotImplemented
*/
function testUnserializeDeny() {
$source = '
/principals/evert
';
$dom = Sabre_DAV_XMLUtil::loadDOMDocument($source);
Sabre_DAVACL_Property_Acl::unserialize($dom->firstChild);
}
/**
* @expectedException Sabre_DAV_Exception_BadRequest
*/
function testUnserializeMissingPriv() {
$source = '
/principals/evert
';
$dom = Sabre_DAV_XMLUtil::loadDOMDocument($source);
Sabre_DAVACL_Property_Acl::unserialize($dom->firstChild);
}
}