public function testImport() { $xml = <<<XML <?xml version='1.0' encoding='UTF-8'?> <XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> <Subject>http://blog.example.com/article/id/314</Subject> <Expires>2010-01-30T09:30:00+00:00</Expires> <Alias>http://blog.example.com/cool_new_thing</Alias> <Alias>http://blog.example.com/steve/article/7</Alias> <Property type='http://blgx.example.net/ns/version'>1.3</Property> <Property type='http://blgx.example.net/ns/ext' xsi:nil='true' /> <Link rel='author' type='text/html' href='http://blog.example.com/author/steve'> <Title>About the Author</Title> <Title xml:lang='en-us'>Author Information</Title> <Property type='http://example.com/role'>editor</Property> </Link> <Link rel='author' href='http://example.com/author/john'> <Title>The other author</Title> </Link> <Link rel='copyright' template='http://example.com/copyright?id={uri}' /> </XRD> XML; $xrd = new Xrd(); $xrd->import(simplexml_load_string($xml)); $this->assertEquals('http://blog.example.com/article/id/314', $xrd->getSubject()); $this->assertEquals('Sat, 30 Jan 2010 09:30:00 +0000', $xrd->getExpires()->format('r')); $this->assertEquals(array('http://blog.example.com/cool_new_thing', 'http://blog.example.com/steve/article/7'), $xrd->getAliases()); $this->assertEquals(array('http://blgx.example.net/ns/version' => '1.3', 'http://blgx.example.net/ns/ext' => null), $xrd->getProperties()); $links = $xrd->getLinks(); $this->assertEquals('author', $links[0]->getRel()); $this->assertEquals('text/html', $links[0]->getType()); $this->assertEquals('http://blog.example.com/author/steve', $links[0]->getHref()); $this->assertEquals(array('default' => 'About the Author', 'en-us' => 'Author Information'), $links[0]->getTitles()); $this->assertEquals(array('http://example.com/role' => 'editor'), $links[0]->getProperties()); $this->assertEquals('author', $links[1]->getRel()); $this->assertEquals('http://example.com/author/john', $links[1]->getHref()); $this->assertEquals(array('default' => 'The other author'), $links[1]->getTitles()); $this->assertEquals('copyright', $links[2]->getRel()); $this->assertEquals('http://example.com/copyright?id={uri}', $links[2]->getTemplate()); $this->assertXmlStringEqualsXmlString($xml, $xrd->export()); }
public function testParseOasisSpecXrds() { $xml = <<<'XML' <XRDS xmlns="xri://$xrds" ref="xri://(tel:+1-201-555-0123)*foo"> <XRD xmlns="xri://$xrd*($v*2.0)" version="2.0"> <Query>*foo</Query> <Status code="100"/> <ServerStatus code="100"/> <Expires>2005-05-30T09:30:10Z</Expires> <ProviderID>xri://(tel:+1-201-555-0123)</ProviderID> <LocalID>*baz</LocalID> <EquivID>https://example.com/example/resource/</EquivID> <CanonicalID>xri://(tel:+1-201-555-0123)!1234</CanonicalID> <CanonicalEquivID> xri://=!4a76!c2f7!9033.78bd </CanonicalEquivID> <Service> <ProviderID> xri://(tel:+1-201-555-0123)!1234 </ProviderID> <Type>xri://$res*auth*($v*2.0)</Type> <MediaType>application/xrds+xml</MediaType> <URI priority="10">http://resolve.example.com</URI> <URI priority="15">http://resolve2.example.com</URI> <URI>https://resolve.example.com</URI> </Service> <Service> <ProviderID> xri://(tel:+1-201-555-0123)!1234 </ProviderID> <Type>xri://$res*auth*($v*2.0)</Type> <MediaType>application/xrds+xml;https=true</MediaType> <URI>https://resolve.example.com</URI> </Service> <Service> <Type match="null" /> <Path select="true">/media/pictures</Path> <MediaType select="true">image/jpeg</MediaType> <URI append="path" >http://pictures.example.com</URI> </Service> <Service> <Type match="null" /> <Path select="true">/media/videos</Path> <MediaType select="true">video/mpeg</MediaType> <URI append="path" >http://videos.example.com</URI> </Service> <Service> <ProviderID> xri://!!1000!1234.5678</ProviderID> <Type match="null" /> <Path match="default" /> <URI>http://example.com/local</URI> </Service> <Service> <Type>http://example.com/some/service/v3.1</Type> <URI>http://example.com/some/service/endpoint</URI> <LocalID>https://example.com/example/resource/</LocalID> </Service> </XRD> </XRDS> XML; $xrd = Xrd::fromXrds(simplexml_load_string($xml)); $this->assertEquals('*foo', $xrd->getQuery()); $this->assertEquals('100', $xrd->getStatus()->getCode()); $this->assertEquals('100', $xrd->getServerStatus()->getCode()); $this->assertEquals('Mon, 30 May 2005 09:30:10 +0000', $xrd->getExpires()->format('r')); $this->assertEquals('xri://(tel:+1-201-555-0123)', $xrd->getProviderId()); $this->assertEquals('*baz', $xrd->getLocalId()); $this->assertEquals('https://example.com/example/resource/', $xrd->getEquivId()); $this->assertEquals('xri://(tel:+1-201-555-0123)!1234', $xrd->getCanonicalId()); $this->assertEquals('xri://=!4a76!c2f7!9033.78bd', $xrd->getCanonicalEquivId()); $services = $xrd->getService(); $this->assertEquals('xri://(tel:+1-201-555-0123)!1234', $services[0]->getProviderId()); $this->assertEquals(array('xri://$res*auth*($v*2.0)'), $services[0]->getType()); $this->assertEquals('application/xrds+xml', $services[0]->getMediaType()); $this->assertEquals('http://resolve.example.com', $services[0]->getUri()); $this->assertEquals(array('http://resolve.example.com', 'http://resolve2.example.com', 'https://resolve.example.com'), $services[0]->getUris()); $this->assertEquals('xri://(tel:+1-201-555-0123)!1234', $services[1]->getProviderId()); $this->assertEquals(array('xri://$res*auth*($v*2.0)'), $services[1]->getType()); $this->assertEquals('application/xrds+xml;https=true', $services[1]->getMediaType()); $this->assertEquals('https://resolve.example.com', $services[1]->getUri()); $this->assertEquals('/media/pictures', $services[2]->getPath()); $this->assertEquals('image/jpeg', $services[2]->getMediaType()); $this->assertEquals('http://pictures.example.com', $services[2]->getUri()); $this->assertEquals('/media/videos', $services[3]->getPath()); $this->assertEquals('video/mpeg', $services[3]->getMediaType()); $this->assertEquals('http://videos.example.com', $services[3]->getUri()); $this->assertEquals('xri://!!1000!1234.5678', $services[4]->getProviderId()); $this->assertEquals('http://example.com/local', $services[4]->getUri()); $this->assertEquals(array('http://example.com/some/service/v3.1'), $services[5]->getType()); $this->assertEquals('http://example.com/some/service/endpoint', $services[5]->getUri()); $this->assertEquals('https://example.com/example/resource/', $services[5]->getLocalId()); $this->assertEquals(true, $services[5]->hasType('http://example.com/some/service/v3.1')); $service = $xrd->getServiceByType('http://example.com/some/service/v3.1'); $this->assertInstanceOf('PSX\\Xri\\Xrd\\Service', $service); $this->assertEquals(array('http://example.com/some/service/v3.1'), $service->getType()); $this->assertEquals('http://example.com/some/service/endpoint', $service->getUri()); $this->assertEquals('https://example.com/example/resource/', $service->getLocalId()); $this->assertEquals(true, $service->hasType('http://example.com/some/service/v3.1')); }