assertInstanceOf('Sabre\DAVACL\Xml\Property\ACL', $acl); } function testSerializeEmpty() { $acl = new Acl([]); $xml = (new DAV\Server())->xml->write('{DAV:}root', $acl); $expected = ' '; $this->assertXmlStringEqualsXmlString($expected, $xml); } function testSerialize() { $privileges = [ [ 'principal' => 'principals/evert', 'privilege' => '{DAV:}write', ], [ 'principal' => 'principals/foo', 'privilege' => '{DAV:}read', 'protected' => true, ], ]; $acl = new Acl($privileges); $xml = (new DAV\Server())->xml->write('{DAV:}root', $acl, '/'); $expected = ' /principals/evert/ /principals/foo/ '; $this->assertXmlStringEqualsXmlString($expected, $xml); } function testSerializeSpecialPrincipals() { $privileges = [ [ 'principal' => '{DAV:}authenticated', 'privilege' => '{DAV:}write', ], [ 'principal' => '{DAV:}unauthenticated', 'privilege' => '{DAV:}write', ], [ 'principal' => '{DAV:}all', 'privilege' => '{DAV:}write', ], ]; $acl = new Acl($privileges); $xml = (new DAV\Server())->xml->write('{DAV:}root', $acl, '/'); $expected = ' '; $this->assertXmlStringEqualsXmlString($expected, $xml); } function testUnserialize() { $source = ' /principals/evert/ /principals/foo/ '; $reader = new \Sabre\Xml\Reader(); $reader->elementMap['{DAV:}root'] = 'Sabre\DAVACL\Xml\Property\Acl'; $reader->xml($source); $result = $reader->parse(); $result = $result['value']; $this->assertInstanceOf('Sabre\\DAVACL\\Xml\\Property\\Acl', $result); $expected = [ [ 'principal' => '/principals/evert/', 'protected' => false, 'privilege' => '{DAV:}write', ], [ 'principal' => '/principals/foo/', 'protected' => true, 'privilege' => '{DAV:}read', ], ]; $this->assertEquals($expected, $result->getPrivileges()); } /** * @expectedException Sabre\DAV\Exception\BadRequest */ function testUnserializeNoPrincipal() { $source = ' '; $reader = new \Sabre\Xml\Reader(); $reader->elementMap['{DAV:}root'] = 'Sabre\DAVACL\Xml\Property\Acl'; $reader->xml($source); $result = $reader->parse(); } function testUnserializeOtherPrincipal() { $source = ' '; $reader = new \Sabre\Xml\Reader(); $reader->elementMap['{DAV:}root'] = 'Sabre\DAVACL\Xml\Property\Acl'; $reader->xml($source); $result = $reader->parse(); $result = $result['value']; $this->assertInstanceOf('Sabre\\DAVACL\\Xml\\Property\\Acl', $result); $expected = [ [ 'principal' => '{DAV:}authenticated', 'protected' => false, 'privilege' => '{DAV:}write', ], [ 'principal' => '{DAV:}unauthenticated', 'protected' => false, 'privilege' => '{DAV:}write', ], [ 'principal' => '{DAV:}all', 'protected' => false, 'privilege' => '{DAV:}write', ], ]; $this->assertEquals($expected, $result->getPrivileges()); } /** * @expectedException Sabre\DAV\Exception\NotImplemented */ function testUnserializeDeny() { $source = ' /principals/evert '; $reader = new \Sabre\Xml\Reader(); $reader->elementMap['{DAV:}root'] = 'Sabre\DAVACL\Xml\Property\Acl'; $reader->xml($source); $result = $reader->parse(); } function testToHtml() { $privileges = [ [ 'principal' => 'principals/evert', 'privilege' => '{DAV:}write', ], [ 'principal' => 'principals/foo', 'privilege' => '{http://example.org/ns}read', 'protected' => true, ], [ 'principal' => '{DAV:}authenticated', 'privilege' => '{DAV:}write', ], ]; $acl = new Acl($privileges); $html = new HtmlOutputHelper( '/base/', ['DAV:' => 'd'] ); $expected = '' . '' . '' . '' . '' . '
PrincipalPrivilege
/base/principals/evertd:write
/base/principals/foo{http://example.org/ns}read(protected)
d:authenticatedd:write
'; $this->assertEquals($expected, $acl->toHtml($html)); } }