public function testDiscover() { $testCase = $this; $http = new Http(new Callback(function ($request) use($testCase) { $response = <<<TEXT HTTP/1.1 200 OK Date: Thu, 26 Sep 2013 16:36:26 GMT Content-Type: application/json; charset=UTF-8 <html xmlns:og="http://ogp.me/ns#"> <head> \t<title>The Rock (1996)</title> \t<meta property="og:title" content="The Rock" /> \t<meta property="og:type" content="movie" /> \t<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" /> \t<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" /> </head> <body> \t<h1>Open Graph protocol</h1> \t<p>The Open Graph protocol enables any web page to become a rich object in a social graph.</p> </body> </html> TEXT; return Response::convert($response, ResponseParser::MODE_LOOSE)->toString(); })); $og = new Opengraph($http); $data = $og->discover(new Url('http://127.0.0.1/opengraph')); $this->assertEquals($data->get('og:title'), 'The Rock'); $this->assertEquals($data->get('og:url'), 'http://www.imdb.com/title/tt0117500/'); }
public function testDiscovery() { $testCase = $this; $http = new Http(new Callback(function ($request) use($testCase) { if ($request->getUrl()->getPath() == '/xrds') { $response = <<<'TEXT' HTTP/1.1 200 OK Date: Thu, 26 Sep 2013 16:36:26 GMT Content-Type: application/xrds+xml; charset=UTF-8 <?xml version="1.0" encoding="UTF-8"?> <xrds:XRDS xmlns="xri://$xrd*($v*2.0)" xmlns:xrds="xri://$xrds"> <XRD> <Service> <URI>http://test.phpsx.org</URI> <Type>http://ns.test.phpsx.org/2011/test</Type> </Service> </XRD> </xrds:XRDS> TEXT; } else { $response = <<<TEXT HTTP/1.1 200 OK Date: Thu, 26 Sep 2013 16:36:26 GMT Content-Type: text/html; charset=UTF-8 X-XRDS-Location: http://127.0.0.1/xrds <html> <body> \t<h1>Oo</h1> </body> </html> TEXT; } return Response::convert($response, ResponseParser::MODE_LOOSE)->toString(); })); $yadis = new Yadis($http); $xrd = $yadis->discover(new Url('http://127.0.0.1')); $this->assertInstanceOf('PSX\\Xri\\Xrd', $xrd); $service = $xrd->getService(); $this->assertEquals(1, count($service)); $this->assertInstanceOf('PSX\\Xri\\Xrd\\Service', $service[0]); $this->assertEquals('http://test.phpsx.org', $service[0]->getUri()); $this->assertEquals(array('http://ns.test.phpsx.org/2011/test'), $service[0]->getType()); }
public function testSend() { $testCase = $this; $http = new Http(new Callback(function ($request) use($testCase) { if ($request->getUrl()->getPath() == '/server') { $response = <<<TEXT HTTP/1.1 200 OK Date: Thu, 26 Sep 2013 16:36:26 GMT Content-Type: application/xml; charset=UTF-8 <?xml version="1.0" encoding="UTF-8"?> <methodResponse> <params> <param> <value> <string>Successful</string> </value> </param> </params> </methodResponse> TEXT; } else { if ($request->getUrl()->getPath() == '/resource') { $response = <<<TEXT HTTP/1.1 200 OK Date: Thu, 26 Sep 2013 16:36:26 GMT Content-Type: text/html; charset=UTF-8 X-Pingback: http://127.0.0.1/server <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> \t<title>PSX Testarea</title> \t<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> \t<meta http-equiv="X-XRDS-Location" content="http://test.phpsx.org/yadis/xrds" /> \t<meta http-equiv="Content-Style-Type" content="text/css" /> \t<meta name="generator" content="psx" /> \t<link rel="pingback" href="http://test.phpsx.org/pingback/server" /> </head> <body> <h1>Pingback-enabled resources</h1> </body> </html> TEXT; } } return Response::convert($response, ResponseParser::MODE_LOOSE)->toString(); })); $pingback = new Pingback($http); $response = $pingback->send('http://foobar.com', 'http://127.0.0.1/resource'); $this->assertEquals(true, $response); }
public function testVideoRequest() { $testCase = $this; $http = new Http(new Callback(function ($request) use($testCase) { $response = <<<TEXT HTTP/1.1 200 OK Date: Thu, 26 Sep 2013 16:36:26 GMT Content-Type: application/json; charset=UTF-8 { "type":"video", "version":"1.0", "title":"Beethoven - Rondo 'Die wut ueber den verlorenen groschen'", "author_name":"LukasSchuch", "author_url":"http:\\/\\/www.youtube.com\\/user\\/LukasSchuch", "provider_name":"YouTube", "provider_url":"http:\\/\\/www.youtube.com\\/", "thumbnail_url":"http:\\/\\/i2.ytimg.com\\/vi\\/AKjzEG1eItY\\/hqdefault.jpg", "thumbnail_width":480, "thumbnail_height":360, "html":"<iframe width=\\"459\\" height=\\"344\\" src=\\"http:\\/\\/www.youtube.com\\/embed\\/AKjzEG1eItY?fs=1&feature=oembed\\" frameborder=\\"0\\" allowfullscreen><\\/iframe>", "width":240, "height":160 } TEXT; return Response::convert($response, ResponseParser::MODE_LOOSE)->toString(); })); $oembed = new Oembed($http, getContainer()->get('importer')); $url = new Url('http://127.0.0.1/oembed/video?url=http%3A%2F%2Flocalhost.com%2Fresource'); $type = $oembed->request($url); $this->assertInstanceof('PSX\\Oembed\\Type\\Video', $type); $this->assertEquals('video', $type->getType()); $this->assertEquals('1.0', $type->getVersion()); $this->assertEquals('Beethoven - Rondo \'Die wut ueber den verlorenen groschen\'', $type->getTitle()); $this->assertEquals('LukasSchuch', $type->getAuthorName()); $this->assertEquals('http://www.youtube.com/user/LukasSchuch', $type->getAuthorUrl()); $this->assertEquals('YouTube', $type->getProviderName()); $this->assertEquals('http://www.youtube.com/', $type->getProviderUrl()); $this->assertEquals('http://i2.ytimg.com/vi/AKjzEG1eItY/hqdefault.jpg', $type->getThumbnailUrl()); $this->assertEquals('480', $type->getThumbnailWidth()); $this->assertEquals('360', $type->getThumbnailHeight()); $this->assertEquals('<iframe width="459" height="344" src="http://www.youtube.com/embed/AKjzEG1eItY?fs=1&feature=oembed" frameborder="0" allowfullscreen></iframe>', $type->getHtml()); $this->assertEquals('240', $type->getWidth()); $this->assertEquals('160', $type->getHeight()); }
public function testInitialize() { $testCase = $this; $http = new Http(new Callback(function ($request) use($testCase) { // association endpoint if ($request->getUrl()->getPath() == '/server') { $data = array(); parse_str($request->getBody(), $data); $testCase->assertEquals('http://specs.openid.net/auth/2.0', $data['openid_ns']); $testCase->assertEquals('associate', $data['openid_mode']); $testCase->assertEquals('HMAC-SHA256', $data['openid_assoc_type']); $testCase->assertEquals('DH-SHA256', $data['openid_session_type']); $dhGen = $data['openid_dh_gen']; $dhModulus = $data['openid_dh_modulus']; $dhConsumerPub = $data['openid_dh_consumer_public']; $dhFunc = 'SHA1'; $secret = ProviderAbstract::randomBytes(20); $res = ProviderAbstract::generateDh($dhGen, $dhModulus, $dhConsumerPub, $dhFunc, $secret); $testCase->assertEquals(true, isset($res['pubKey'])); $testCase->assertEquals(true, isset($res['macKey'])); $body = OpenId::keyValueEncode(array('ns' => 'http://specs.openid.net/auth/2.0', 'assoc_handle' => 'foobar', 'session_type' => 'DH-SHA256', 'assoc_type' => 'HMAC-SHA256', 'expires_in' => 60 * 60, 'dh_server_public' => $res['pubKey'], 'enc_mac_key' => $res['macKey'])); $response = <<<TEXT HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 Date: Sat, 04 Jan 2014 18:19:45 GMT {$body} TEXT; } else { if ($request->getUrl()->getPath() == '/identity') { $response = <<<TEXT HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 Date: Sat, 04 Jan 2014 18:19:45 GMT <html> \t<head> \t\t<link rel="openid.server" href="http://openid.com/server" /> \t\t<link rel="openid.delegate" href="http://foo.com" /> \t</head> </html> TEXT; } } return Response::convert($response, ResponseParser::MODE_LOOSE)->toString(); })); $store = new Store\Memory(); $openid = new OpenId($http, 'http://localhost.com', $store); $openid->initialize('http://foo.com/identity', 'http://localhost.com/callback'); // check whether the store has the association $assoc = $store->loadByHandle('http://openid.com/server', 'foobar'); $this->assertEquals('foobar', $assoc->getAssocHandle()); $this->assertEquals('HMAC-SHA256', $assoc->getAssocType()); $this->assertEquals('DH-SHA256', $assoc->getSessionType()); $this->assertEquals(3600, $assoc->getExpire()); // check redirect url $url = $openid->getRedirectUrl(); $this->assertEquals('http://specs.openid.net/auth/2.0', $url->getParam('openid.ns')); $this->assertEquals('checkid_setup', $url->getParam('openid.mode')); $this->assertEquals('http://localhost.com/callback', $url->getParam('openid.return_to')); $this->assertEquals('http://localhost.com', $url->getParam('openid.realm')); $this->assertEquals('http://foo.com/identity', $url->getParam('openid.claimed_id')); $this->assertEquals('http://foo.com', $url->getParam('openid.identity')); $this->assertEquals('foobar', $url->getParam('openid.assoc_handle')); // the user gets redirected from the openid provider to our callback now // we verfiy the data $signed = array('ns', 'mode', 'op_endpoint', 'return_to', 'response_nonce', 'assoc_handle'); $data = array('openid_ns' => 'http://specs.openid.net/auth/2.0', 'openid_mode' => 'id_res', 'openid_op_endpoint' => 'http://openid.com/server', 'openid_return_to' => 'http://localhost.com/callback', 'openid_response_nonce' => uniqid(), 'openid_assoc_handle' => $assoc->getAssocHandle(), 'openid_signed' => implode(',', $signed)); // generate signature $sig = OpenId::buildSignature(OpenId::extractParams($data), $signed, $assoc->getSecret(), $assoc->getAssocType()); $data['openid_sig'] = $sig; // verify $result = $openid->verify($data); $this->assertTrue($result); }
public function testDiscoverRss() { $testCase = $this; $http = new Http(new Callback(function ($request) use($testCase) { $response = <<<TEXT HTTP/1.1 200 OK Content-Type: application/rss+xml; charset=utf-8 Date: Sat, 04 Jan 2014 18:19:45 GMT <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> \t<channel> \t\t<atom:link rel="hub" href="http://127.0.0.1/pshb/hub" /> \t\t<atom:link rel="self" type="application/rss+xml" href="http://127.0.0.1/rss" /> \t\t<lastBuildDate>Fri, 25 Mar 2011 03:45:43 +0000</lastBuildDate> \t\t<item> \t\t\t<title>Heathcliff</title> \t\t\t<link>http://publisher.example.com/happycat25.xml</link> \t\t\t<guid>http://publisher.example.com/happycat25.xml</guid> \t\t\t<pubDate>Fri, 25 Mar 2011 03:45:43 +0000</pubDate> \t\t\t<description>What a happy cat. Full content goes here.</description> \t\t</item> \t</channel> </rss> TEXT; return Response::convert($response, ResponseParser::MODE_LOOSE)->toString(); })); $pshb = new PubSubHubBub($http); $url = $pshb->discover(new Url('http://127.0.0.1/rss', PubSubHubBub::RSS2)); $this->assertInstanceOf('PSX\\Url', $url); $this->assertEquals('http://127.0.0.1/pshb/hub', (string) $url); }