assertEquals(Principal::UNAUTHENTICATED, $principal->getType()); $this->assertNull($principal->getHref()); $principal = new Principal(Principal::AUTHENTICATED); $this->assertEquals(Principal::AUTHENTICATED, $principal->getType()); $this->assertNull($principal->getHref()); $principal = new Principal(Principal::HREF, 'admin'); $this->assertEquals(Principal::HREF, $principal->getType()); $this->assertEquals('admin/', $principal->getHref()); } /** * @depends testSimple * @expectedException Sabre\DAV\Exception */ function testNoHref() { $principal = new Principal(Principal::HREF); } /** * @depends testSimple */ function testSerializeUnAuthenticated() { $prin = new Principal(Principal::UNAUTHENTICATED); $xml = (new DAV\Server())->xml->write('{DAV:}principal', $prin); $this->assertXmlStringEqualsXmlString(' ', $xml); } /** * @depends testSerializeUnAuthenticated */ function testSerializeAuthenticated() { $prin = new Principal(Principal::AUTHENTICATED); $xml = (new DAV\Server())->xml->write('{DAV:}principal', $prin); $this->assertXmlStringEqualsXmlString(' ', $xml); } /** * @depends testSerializeUnAuthenticated */ function testSerializeHref() { $prin = new Principal(Principal::HREF, 'principals/admin'); $xml = (new DAV\Server())->xml->write('{DAV:}principal', $prin, '/'); $this->assertXmlStringEqualsXmlString(' /principals/admin/ ', $xml); } function testUnserializeHref() { $xml = ' ' . '/principals/admin' . ''; $principal = $this->parse($xml); $this->assertEquals(Principal::HREF, $principal->getType()); $this->assertEquals('/principals/admin/', $principal->getHref()); } function testUnserializeAuthenticated() { $xml = ' ' . ' ' . ''; $principal = $this->parse($xml); $this->assertEquals(Principal::AUTHENTICATED, $principal->getType()); } function testUnserializeUnauthenticated() { $xml = ' ' . ' ' . ''; $principal = $this->parse($xml); $this->assertEquals(Principal::UNAUTHENTICATED, $principal->getType()); } /** * @expectedException Sabre\DAV\Exception\BadRequest */ function testUnserializeUnknown() { $xml = ' ' . ' ' . ''; $this->parse($xml); } function parse($xml) { $reader = new Reader(); $reader->elementMap['{DAV:}principal'] = 'Sabre\\DAVACL\\Xml\\Property\\Principal'; $reader->xml($xml); $result = $reader->parse(); return $result['value']; } /** * @depends testSimple * @dataProvider htmlProvider */ function testToHtml($principal, $output) { $html = $principal->toHtml(new HtmlOutputHelper('/', [])); $this->assertXmlStringEqualsXmlString( $output, $html ); } /** * Provides data for the html tests * * @return array */ function htmlProvider() { return [ [ new Principal(Principal::UNAUTHENTICATED), 'unauthenticated', ], [ new Principal(Principal::AUTHENTICATED), 'authenticated', ], [ new Principal(Principal::ALL), 'all', ], [ new Principal(Principal::HREF, 'principals/admin'), '/principals/admin/', ], ]; } }