public function testHandleResponseWithErrorStatusCode() { $this->setExpectedException('InoOicClient\\Oic\\Exception\\HttpErrorStatusException'); $httpResponse = new \Zend\Http\Response(); $httpResponse->setStatusCode(500); $this->handler->handleResponse($httpResponse); }
public function testFromUrl() { $data = '<?xml version="1.0" encoding="UTF-8" ?> <root> <item> <name>Foo</name> <value>1</value> </item> <item> <name>Bar</name> <value>2</value> </item> <item> <name>Baz</name> <value>3</value> </item> </root>'; $response = new \Zend\Http\Response(); $response->setContent($data); $response->getHeaders()->addHeaderLine('Content-Type: text/xml'); $client = $this->getMock('Zend\\Http\\Client', array('send')); $client->expects($this->once())->method('send')->will($this->returnValue($response)); Factory::setHttpClient($client); $url = 'http://www.domain.com'; $dataProvider = Factory::fromUrl($url); $this->assertInstanceOf('AmCharts\\Chart\\DataProvider', $dataProvider); $data = $dataProvider->toArray(); $this->assertCount(3, $data); }
public function testSearchByArea_ReturnResponse_WhenValidParams() { $response = new \Zend\Http\Response(); $response->setContent(json_encode(array('response' => array('item' => array('title' => 'hoge'))))); $this->_api->_request->expects($this->once())->method('request')->will($this->returnValue($response)); $this->assertEquals(array('title' => 'hoge'), $this->_api->searchByArea('tokyo')); }
public function response() { $resultJson = Json::encode($this->returnEntity); $response = new \Zend\Http\Response(); $response->getHeaders()->addHeaderLine('Content-Type', 'text/html; charset=utf-8'); $response->setContent($resultJson); return $response; }
public function exportXlsAction() { set_time_limit(0); $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); /*$orders = $em->getRepository("ErsBase\Entity\Order") ->findBy(array(), array('created' => 'ASC'));*/ $packages = $em->getRepository("ErsBase\\Entity\\Package")->findBy(array(), array('created' => 'ASC')); $filename = getcwd() . "/tmp/excel-" . date("m-d-Y") . ".xls"; $realPath = realpath($filename); if (false === $realPath) { touch($filename); chmod($filename, 0644); } $filename = realpath($filename); $finalData = array(); $finalData[] = array('code', 'participant firstname', 'participant surname', 'list of items', 'date of purchase', 'status'); foreach ($packages as $package) { $order = $package->getOrder(); $item_list = ''; foreach ($package->getItems() as $item) { $item_list .= $item->getName(); foreach ($item->getItemVariants() as $variant) { $item_list .= $variant->getName() . ' ' . $variant->getValue() . '; '; } $item_list .= "\r\n"; } $item_list = preg_replace('/\\r\\n$/', '', $item_list); $finalData[] = array(utf8_decode($package->getCode()->getValue()), utf8_decode($package->getParticipant()->getFirstname()), utf8_decode($package->getParticipant()->getSurname()), utf8_decode($item_list), utf8_decode($order->getCreated()->format('d.m.Y H:i:s')), utf8_decode($package->getStatus())); } $handle = fopen($filename, "w"); if (!$handle) { $logger = $this->getServiceLocator()->get('Logger'); $logger->warn('unable to open file ' . $filename); exit; } foreach ($finalData as $finalRow) { fputcsv($handle, $finalRow, "\t"); } fclose($handle); #$this->_helper->layout->disableLayout(); #$this->_helper->viewRenderer->setNoRender(); /*$this->getResponse()->setRawHeader( "Content-Type: application/vnd.ms-excel; charset=UTF-8" ) ->setRawHeader( "Content-Disposition: attachment; filename=excel.xls" ) ->setRawHeader( "Content-Transfer-Encoding: binary" ) ->setRawHeader( "Expires: 0" ) ->setRawHeader( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ) ->setRawHeader( "Pragma: public" ) ->setRawHeader( "Content-Length: " . filesize( $filename ) ) ->sendResponse(); readfile( $filename ); exit();*/ $response = new \Zend\Http\Response(); $response->getHeaders()->addHeaderLine('Content-Type', 'application/vnd.ms-excel; charset=utf-8')->addHeaderLine('Content-Disposition', 'attachment; filename=orders-' . date('Ymd\\THis') . '.xls')->addHeaderLine('Content-Length', filesize($filename)); $response->setContent(file_get_contents($filename)); return $response; }
public function testHandleResponseWithServerError() { $httpResponse = new \Zend\Http\Response(); $httpResponse->setStatusCode(401); $httpResponse->getHeaders()->addHeaders(array('WWW-Authenticate' => 'Bearer error="server_error",foo="bar"')); $this->handler->handleResponse($httpResponse); $this->assertTrue($this->handler->isError()); $error = $this->handler->getError(); $this->assertInstanceOf('InoOicClient\\Oic\\Error', $error); $this->assertSame('server_error', $error->getCode()); }
/** * Gets the document object for this response * * @return DOMDocument the DOM Document for this response. */ public function getDocument() { try { $body = $this->_httpResponse->getBody(); } catch (Http\Exception $e) { $body = false; } if ($this->_document === null) { if ($body !== false) { // turn off libxml error handling $errors = libxml_use_internal_errors(); $this->_document = new \DOMDocument(); if (!$this->_document->loadXML($body)) { $this->_document = false; } // reset libxml error handling libxml_clear_errors(); libxml_use_internal_errors($errors); } else { $this->_document = false; } } return $this->_document; }
public function tryRun() { $response = new \Zend\Http\Response(); $response->getHeaders()->addHeaderLine('Content-Type', 'application/json'); $apiRequest = new \RockEinstein\Lib\Api\Request\ApiRequestImp(); $resource = $apiRequest->getResource(); $controller = $this->getRouteProvider()->getRoute($resource); $controller->setRequest($apiRequest); $controller->setResponse($response); $controller->setStatusCode(); $parameters = array_merge($apiRequest->getBodyParameters(), $apiRequest->getURLParameters(), $apiRequest->getHeaderParameters()); $mapCall = new MapCallAdapter($controller); $callReponse = $mapCall->callWithMapArgs($apiRequest->getMethod(), $parameters); if (is_array($callReponse) && !empty($callReponse['ContentType'])) { $response->getHeaders()->addHeaderLine('Content-Type', $callReponse['ContentType']); $response->setContent($callReponse['Body']); } else { $response->setContent(\json_encode($callReponse)); } return $response; }
/** * Sends a request and returns a response * * @param CartRecover_Request $request * @return Cart_Recover_Response */ public function sendRequest(CartRecover_Request $request) { $this->client->setUri($request->getUri()); $this->client->setParameterGet($request->getParams()); $this->client->setMethod($request->getMethod()); $this->client->setHeaders(array('Accept' => 'application/json')); $this->response = $this->client->send(); if ($this->response->getHeaders()->get('Content-Type')->getFieldValue() != 'application/json') { throw new CartRecover_Exception_UnexpectedValueException("Unknown response format."); } $body = json_decode($this->response->getContent(), true); $response = new CartRecover_Response(); $response->setRawResponse($this->response->toString()); $response->setBody($body); $response->setHeaders($this->response->getHeaders()->toArray()); $response->setStatus($this->response->getReasonPhrase(), $this->response->getStatusCode()); return $response; }
/** * Parse result from Zend_Http_Response * * @param Zend_Http_Response $response Response from HTTP call * @return object * @throws Zend_Service_WindowsAzure_Exception */ protected function _parseResponse(Zend\Http\Response $response = null) { if ($response === null) { throw new Zend_Service_WindowsAzure_Exception('Response should not be null.'); } $xml = @simplexml_load_string($response->getBody()); if ($xml !== false) { // Fetch all namespaces $namespaces = array_merge($xml->getNamespaces(true), $xml->getDocNamespaces(true)); // Register all namespace prefixes foreach ($namespaces as $prefix => $ns) { if ($prefix != '') { $xml->registerXPathNamespace($prefix, $ns); } } } return $xml; }
/** * @group ZF-8330 */ public function testGetsFeedLinksAndNormalisesRelativeUrlsOnUriWithPath() { try { $currClient = Reader\Reader::getHttpClient(); $response = new \Zend\Http\Response(); $response->setContent('<!DOCTYPE html><html><head><link rel="alternate" type="application/rss+xml" href="../test.rss"><link rel="alternate" type="application/atom+xml" href="/test.atom"></head><body></body></html>'); $response->setStatusCode(200); $testAdapter = new \Zend\Http\Client\Adapter\Test(); $testAdapter->setResponse($response); Reader\Reader::setHttpClient(new \Zend\Http\Client(null, array('adapter' => $testAdapter))); $links = Reader\Reader::findFeedLinks('http://foo/bar'); Reader\Reader::setHttpClient($currClient); } catch (\Exception $e) { $this->fail($e->getMessage()); } $this->assertEquals('http://foo/test.rss', $links->rss); $this->assertEquals('http://foo/test.atom', $links->atom); }
public function getMockedInfoResponse() { $content = '{ "firstName": "John", "lastName": "Doe", "headline": "Inventor", }'; $response = new \Zend\Http\Response(); $response->setContent($content); return $response; }
public function encodingAction() { $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $order = $em->getRepository("ErsBase\\Entity\\Order")->findOneBy(array('id' => '17')); $viewModel = new ViewModel(array('order' => $order)); $viewModel->setTemplate('email/purchase-info.phtml'); $viewRender = $this->getServiceLocator()->get('ViewRenderer'); $html = $viewRender->render($viewModel); $response = new \Zend\Http\Response(); $response->getHeaders(); #->addHeaderLine('Content-Type', 'charset=utf-8'); #->addHeaderLine('Content-Disposition', 'attachment; filename=orders-'.date('Ymd\THis').'.xls') #->addHeaderLine('Content-Length', filesize($filename)); $response->setContent($html); return $response; }
public function getPDFResponse($template, $variables = [], $params = []) { $markup = $this->getPDFMarkup($template, $variables, $params); $response = new \Zend\Http\Response(); $response->setContent($markup); $headers = new \Zend\Http\Headers(); $filename = isset($params['fileName']) ? 'filename=' . $params['fileName'] . '.pdf' : 'filename=' . $this->defaultFileName; $headers->addHeaders(['Content-Type' => 'application/pdf', 'Content-Disposition' => 'inline; ' . $filename . '', 'Content-Transfer-Encoding' => 'binary', 'Content-Length' => strlen($markup), 'Accept-Ranges' => 'bytes']); $response->setHeaders($headers); return $response; }
/** * Get the last error type * * @return integer */ public function getHttpStatus() { return $this->_lastResponse->getStatusCode(); }
/** * Test unsuccessful query * * @return void * * @expectedException VuFind\Exception\Mail * @expectedExceptionMessage Problem sending text. */ public function testFailureResponse() { $client = $this->getMockClient(); $expectedUri = 'https://api.clickatell.com/http/sendmsg?api_id=api_id&user=user&password=password&to=1234567890&text=hello'; $response = new \Zend\Http\Response(); $response->setStatusCode(404); $client->expects($this->once())->method('setMethod')->with($this->equalTo('GET'))->will($this->returnValue($client)); $client->expects($this->once())->method('setUri')->with($this->equalTo($expectedUri))->will($this->returnValue($client)); $client->expects($this->once())->method('send')->will($this->returnValue($response)); $obj = $this->getClickatell($client); $obj->text('Clickatell', '1234567890', '*****@*****.**', 'hello'); }
public function testImportActionPostValidSuccess() { $fileSpec = array('tmp_name' => 'uploaded_file'); $this->getRequest()->getFiles()->set('File', $fileSpec); $postData = array('key' => 'value'); $form = $this->getApplicationServiceLocator()->get('FormElementManager')->get('Console\\Form\\Import'); $form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $form->expects($this->once())->method('setData')->with(array('File' => $fileSpec, 'key' => 'value')); $form->expects($this->once())->method('getData')->will($this->returnValue(array('File' => $fileSpec))); $form->expects($this->never())->method('render'); $response = new \Zend\Http\Response(); $response->setStatusCode(200); $this->_inventoryUploader->expects($this->once())->method('uploadFile')->with('uploaded_file')->will($this->returnValue($response)); $this->dispatch('/console/client/import/', 'POST', $postData); $this->assertRedirectTo('/console/client/index/'); }
public function getMockedInfoResponse() { $content = '{ "id": "500", "name": "John Doe", "first_name": "John", "last_name": "Doe", "link": "http:\\/\\/www.facebook.com\\/john.doe", "username": "******", "gender": "male", "timezone": 1, "locale": "sl_SI", "verified": true, "updated_time": "2012-09-14T12:37:27+0000" }'; $response = new \Zend\Http\Response(); $response->setContent($content); return $response; }
<?php include 'SplClassLoader.php'; include '../../../../vendor/autoload.php'; $loader = new SplClassLoader('Diggin', '../../../../src/'); $loader->register(); use Diggin\Http\Charset\WrapperFactory; $header = "HTTP/1.1 200 OK" . "\r\n" . "Content-Type: text/html; charset=Shift-JIS;"; // ... or SJIS-win ? $html = <<<HTML <html lang="ja" xml:lang="ja" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=Shift-JIS" http-equiv="Content-Type" /> </head> <body> <!--① ㈱① ㈱-->ああ </body> HTML; $html = mb_convert_encoding($html, 'SJIS-win', 'UTF-8'); $response = Zend\Http\Response::fromString("{$header}\r\n\r\n{$html}"); $wrap = WrapperFactory::factory($response); echo '[converted response body]', PHP_EOL, PHP_EOL; var_dump($wrap->getBody());