Exemplo n.º 1
0
 public function testCacheHit()
 {
     $request = new Request(new Url('http://localhost.com/foo/bar'), 'GET');
     $response = new Response();
     $response->setBody(new StringStream());
     $filters = array();
     $filters[] = function ($request, $response, $filterChain) {
         $response->getBody()->write('foobar');
         $filterChain->handle($request, $response);
     };
     $filterChain = new FilterChain($filters);
     $filterChain->handle($request, $response);
     $cache = new Cache(new CacheHandler\Memory());
     $item = $cache->getItem(md5('/foo/bar'));
     $item->set(array('headers' => array('Last-Modified' => 'Sat, 27 Dec 2014 15:54:49 GMT', 'Content-Type' => 'text/plain'), 'body' => 'foobar'));
     $cache->save($item);
     $filter = new StaticCache($cache);
     $filter->handle($request, $response, $filterChain);
     $result = $cache->getItem(md5('/foo/bar'))->get();
     $this->assertArrayHasKey('headers', $result);
     $this->assertArrayHasKey('Content-Type', $result['headers']);
     $this->assertEquals('text/plain', $result['headers']['Content-Type']);
     $this->assertArrayHasKey('Last-Modified', $result['headers']);
     $this->assertEquals('Sat, 27 Dec 2014 15:54:49 GMT', $result['headers']['Last-Modified']);
     $this->assertArrayHasKey('body', $result);
     $this->assertEquals('foobar', $result['body']);
 }
Exemplo n.º 2
0
 public static function buildResponseFromHeader(array $headers)
 {
     $line = array_shift($headers);
     if (!empty($line)) {
         $parts = explode(' ', trim($line), 3);
         if (isset($parts[0]) && isset($parts[1]) && isset($parts[2])) {
             $scheme = strval($parts[0]);
             $code = intval($parts[1]);
             $message = strval($parts[2]);
             $response = new Response();
             $response->setProtocolVersion($scheme);
             $response->setStatus($code, $message);
             // append header
             foreach ($headers as $line) {
                 $parts = explode(':', $line, 2);
                 if (isset($parts[0]) && isset($parts[1])) {
                     $key = $parts[0];
                     $value = trim($parts[1]);
                     $response->addHeader($key, $value);
                 }
             }
             return $response;
         } else {
             throw new ParseException('Invalid status line format');
         }
     } else {
         throw new ParseException('Couldnt find status line');
     }
 }
Exemplo n.º 3
0
 public function testFlow()
 {
     $testCase = $this;
     $http = new Http(new Callback(function ($request) use($testCase) {
         $body = new TempStream(fopen('php://memory', 'r+'));
         $response = new Response();
         $response->setBody($body);
         $testCase->loadController($request, $response);
         return $response;
     }));
     $oauth = new Oauth($http);
     // request token
     $response = $oauth->requestToken(new Url('http://127.0.0.1/request'), OauthTest::CONSUMER_KEY, OauthTest::CONSUMER_SECRET);
     $this->assertInstanceOf('PSX\\Oauth\\Provider\\Data\\Response', $response);
     $this->assertEquals(OauthTest::TMP_TOKEN, $response->getToken());
     $this->assertEquals(OauthTest::TMP_TOKEN_SECRET, $response->getTokenSecret());
     // authorize the user gets redirected and approves the application
     // access token
     $response = $oauth->accessToken(new Url('http://127.0.0.1/access'), OauthTest::CONSUMER_KEY, OauthTest::CONSUMER_SECRET, OauthTest::TMP_TOKEN, OauthTest::TMP_TOKEN_SECRET, OauthTest::VERIFIER);
     $this->assertInstanceOf('PSX\\Oauth\\Provider\\Data\\Response', $response);
     $this->assertEquals(OauthTest::TOKEN, $response->getToken());
     $this->assertEquals(OauthTest::TOKEN_SECRET, $response->getTokenSecret());
     // api request
     $url = new Url('http://127.0.0.1/api');
     $auth = $oauth->getAuthorizationHeader($url, OauthTest::CONSUMER_KEY, OauthTest::CONSUMER_SECRET, OauthTest::TOKEN, OauthTest::TOKEN_SECRET, 'HMAC-SHA1', 'GET');
     $request = new GetRequest($url, array('Authorization' => $auth));
     $response = $http->request($request);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals('SUCCESS', (string) $response->getBody());
 }
Exemplo n.º 4
0
 public function testSend()
 {
     $response = new Response();
     $response->setBody(new StringStream('foobar'));
     $sender = new Void();
     $actual = $this->captureOutput($sender, $response);
     $this->assertEmpty($actual);
 }
Exemplo n.º 5
0
 /**
  * Sends an request to the system and returns the http response
  *
  * @param string $url
  * @param string $method
  * @param array $headers
  * @param string $body
  * @return \PSX\Http\ResponseInterface
  */
 protected function sendRequest($url, $method, $headers = array(), $body = null)
 {
     $request = new Request(is_string($url) ? new Url($url) : $url, $method, $headers, $body);
     $response = new Response();
     $response->setBody(new TempStream(fopen('php://memory', 'r+')));
     $this->loadController($request, $response);
     return $response;
 }
Exemplo n.º 6
0
 public function createResponse()
 {
     $version = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
     $response = new Response();
     $response->setProtocolVersion($version);
     $response->setHeader('X-Powered-By', 'psx');
     $response->setBody(new TempStream(fopen('php://temp', 'r+')));
     return $response;
 }
Exemplo n.º 7
0
 public function testFileExists()
 {
     $request = new Request(new Url('http://localhost'), 'GET', array('Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'));
     $response = new Response();
     $response->setBody(new StringStream());
     $filterChain = $this->getMockBuilder('PSX\\Dispatch\\FilterChain')->setConstructorArgs(array(array()))->setMethods(array('handle'))->getMock();
     $filterChain->expects($this->never())->method('handle');
     $handle = new Backstage(__DIR__ . '/backstage.htm');
     $handle->handle($request, $response, $filterChain);
     $this->assertEquals('foobar', (string) $response->getBody());
 }
Exemplo n.º 8
0
 public function testWrongMethod()
 {
     $request = new Request(new Url('http://localhost'), 'GET');
     $response = new Response();
     $response->setBody(new StringStream());
     $filter = $this->getMockBuilder('PSX\\Dispatch\\FilterInterface')->setMethods(array('handle'))->getMock();
     $filter->expects($this->never())->method('handle');
     $filterChain = $this->getMockBuilder('PSX\\Dispatch\\FilterChain')->setConstructorArgs(array(array()))->setMethods(array('handle'))->getMock();
     $filterChain->expects($this->once())->method('handle')->with($this->equalTo($request), $this->equalTo($response));
     $handle = new RequestMethodChoice(array('POST', 'PUT', 'DELETE'), $filter);
     $handle->handle($request, $response, $filterChain);
 }
Exemplo n.º 9
0
 public function testHeaderExist()
 {
     $body = new TempStream(fopen('php://memory', 'r+'));
     $body->write('foobar');
     $request = new Request(new Url('http://localhost'), 'GET');
     $response = new Response();
     $response->setHeader('Content-MD5', 'foobar');
     $response->setBody($body);
     $filter = new ContentMd5();
     $filter->handle($request, $response, $this->getMockFilterChain($request, $response));
     $this->assertEquals('foobar', $response->getHeader('Content-MD5'));
 }
Exemplo n.º 10
0
 public function testToString()
 {
     $body = new StringStream();
     $body->write('foobar');
     $response = new Response(200);
     $response->setHeader('Content-Type', 'text/html; charset=UTF-8');
     $response->setBody($body);
     $httpResponse = 'HTTP/1.1 200 OK' . Http::$newLine;
     $httpResponse .= 'content-type: text/html; charset=UTF-8' . Http::$newLine;
     $httpResponse .= Http::$newLine;
     $httpResponse .= 'foobar';
     $this->assertEquals($httpResponse, (string) $response);
 }
Exemplo n.º 11
0
 /**
  * @param string $method
  * @param string $path
  * @param array|null $body
  * @return mixed
  */
 public function request($method, $path, $body = null, $verbose = false)
 {
     $header = ['User-Agent' => 'Fusio-System v' . Base::getVersion(), 'Authorization' => 'Bearer ' . $this->getAccessToken()];
     $body = $body !== null ? Parser::encode($body) : null;
     $request = new Request(new Url('http://127.0.0.1/backend/' . $path), $method, $header, $body);
     $response = new Response();
     $response->setBody(new TempStream(fopen('php://memory', 'r+')));
     $this->logger->pushHandler($verbose ? new StreamHandler(STDOUT) : new NullHandler());
     $this->dispatch->route($request, $response, null, false);
     $this->logger->popHandler();
     $body = (string) $response->getBody();
     $data = Parser::decode($body, false);
     return $data;
 }
Exemplo n.º 12
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // request
     $baseUrl = new Url($this->config['psx_url']);
     $baseUrl = $baseUrl->withPath(null);
     $parser = new RequestParser($baseUrl, RequestParser::MODE_LOOSE);
     $request = $parser->parse($this->reader->read());
     // response
     $response = new Response();
     $response->setHeader('X-Powered-By', 'psx');
     $response->setBody(new TempStream(fopen('php://memory', 'r+')));
     // dispatch request
     $this->dispatch->route($request, $response);
     // determine return code
     return $response->getStatusCode() >= 400 && $response->getStatusCode() < 600 ? 1 : 0;
 }
Exemplo n.º 13
0
    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/');
    }
Exemplo n.º 14
0
 public function testRequest()
 {
     $testCase = $this;
     $http = new Http(new Callback(function ($request) use($testCase) {
         $body = new TempStream(fopen('php://memory', 'r+'));
         $response = new Response();
         $response->setBody($body);
         $testCase->loadController($request, $response);
         return $response;
     }));
     $url = new Url('http://127.0.0.1/oembed?url=http%3A%2F%2F127.0.0.1%2Fresource');
     $request = new GetRequest($url);
     $response = $http->request($request);
     $expect = array('url' => 'http://127.0.0.1/resource.png', 'width' => 640, 'height' => 480, 'author_name' => 'foobar');
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertJsonStringEqualsJsonString(json_encode($expect), (string) $response->getBody());
 }
Exemplo n.º 15
0
 protected function assertResultSetResponse(Response $response)
 {
     $this->assertEquals(200, $response->getCode(), $response->getBody());
     $result = Json::decode($response->getBody());
     $this->assertEquals(true, isset($result['totalResults']), $response->getBody());
     $this->assertEquals(true, isset($result['startIndex']), $response->getBody());
     $this->assertEquals(true, isset($result['itemsPerPage']), $response->getBody());
     $tblActivity = getContainer()->get('handlerManager')->getTable('AmunService\\User\\Activity')->getName();
     $tblAccount = getContainer()->get('handlerManager')->getTable('AmunService\\User\\Account')->getName();
     $count = $this->sql->getField('SELECT COUNT(*) FROM ' . $tblActivity . ' INNER JOIN ' . $tblAccount . ' ON ' . $tblActivity . '.userId = ' . $tblAccount . '.id');
     $this->assertEquals($count, $result['totalResults']);
 }
Exemplo n.º 16
0
    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());
    }
Exemplo n.º 17
0
 protected function doCheckAuthentication(Url $url)
 {
     $params = $url->getParams();
     $params['openid_mode'] = 'check_authentication';
     $data = http_build_query($params, '', '&');
     $body = new TempStream(fopen('php://memory', 'r+'));
     $request = new Request(new Url('http://127.0.0.1/openid'), 'POST', array('Content-Type' => 'application/x-www-urlencoded'), $data);
     $response = new Response();
     $response->setBody($body);
     $controller = $this->loadController($request, $response);
     $body = (string) $response->getBody();
     $data = OpenId::keyValueDecode($body);
     $this->assertEquals('http://specs.openid.net/auth/2.0', $data['ns']);
     $this->assertEquals('true', $data['is_valid']);
 }
Exemplo n.º 18
0
 public function __doRequest($body, $location, $action, $version, $oneWay = null)
 {
     $method = parse_url($action, PHP_URL_FRAGMENT);
     $header = array('Content-Type' => 'application/soap+xml', 'Accept' => 'application/soap+xml');
     $request = new Request(new Url($location), $method, $header, $body);
     $body = new TempStream(fopen('php://memory', 'r+'));
     $response = new Response();
     $response->setBody($body);
     $controller = $this->testCase->doLoadController($request, $response);
     $body = (string) $response->getBody();
     return $body;
 }
Exemplo n.º 19
0
    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());
    }
Exemplo n.º 20
0
    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);
    }
Exemplo n.º 21
0
 protected function submitData(InstructionAbstract $instruction, $endpoint)
 {
     $header = ['User-Agent' => 'Fusio-Installer v' . Base::getVersion(), 'Authorization' => 'Bearer ' . $this->getAccessToken()];
     $body = Json::encode($this->substituteParameters($instruction->getPayload()));
     $request = new PostRequest(new Url('http://127.0.0.1/' . $endpoint), $header, $body);
     $response = new Response();
     $response->setBody(new TempStream(fopen('php://memory', 'r+')));
     $this->dispatch->route($request, $response);
     $body = (string) $response->getBody();
     $data = Json::decode($body, false);
     if (isset($data->success) && $data->success === true) {
         // installation successful
         $message = isset($data->message) ? $data->message : 'Insert ' . $instruction->getName() . ' successful';
         $this->logger->notice($message);
     } else {
         $message = isset($data->message) ? $data->message : 'Unknown error occured';
         throw new RuntimeException($message);
     }
 }
Exemplo n.º 22
0
 public function testVerify()
 {
     $request = new GetRequest(new Url('http://127.0.0.1/callback?hub.mode=subscribe&hub.topic=http%3A%2F%2F127.0.0.1%2Ftopic&hub.challenge=foobar'));
     $body = new TempStream(fopen('php://memory', 'r+'));
     $response = new Response();
     $response->setBody($body);
     $this->loadController($request, $response);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals('foobar', (string) $response->getBody());
 }
Exemplo n.º 23
0
 protected function assertNegativeResponse(Response $response)
 {
     //$this->assertEquals(200, $response->getCode(), $response->getBody());
     $resp = Json::decode($response->getBody());
     $this->assertEquals(true, isset($resp['text']), $response->getBody());
     $this->assertEquals(true, isset($resp['success']), $response->getBody());
     $this->assertEquals(false, $resp['success'], $response->getBody());
 }
Exemplo n.º 24
0
 public function testBuildStatusLineUnknownStausCodeWithReason()
 {
     $response = new Response();
     $response->setStatus(800, 'Foo');
     $this->assertEquals('HTTP/1.1 800 Foo', ResponseParser::buildStatusLine($response));
 }
Exemplo n.º 25
0
    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);
    }
Exemplo n.º 26
0
    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);
    }