/** * @test */ public function testIfContentIsAppendedCorrectly() { $response = new Response(); $response->setContent('<html>'); $this->assertEquals('<html>', $response->getContent()); $response->appendContent('</html>'); $this->assertEquals('<html></html>', $response->getContent()); }
public function testRebuild() { $expectedContent = ['foo' => 'bar']; $expectedHeaders = new \Phalcon\Http\Response\Headers(); $expectedHeaders->set('Status', '200 OK'); $expectedHeaders->set('HTTP/1.1 200 OK', null); $this->response->rebuild(['foo' => 'bar']); $this->assertEquals($expectedContent, $this->response->getContent()); $this->assertEquals($expectedHeaders, $this->response->getHeaders()); }
/** * @param Response $response */ public function handle(Response $response) { foreach ($response->getHeaders() as $header) { header($header); } echo $response->getContent(); }
/** @dataProvider provideSetError */ public function testSetError($expected, $statusCode, $error, $error_description = null, $error_uri = null) { $response = new Response(); $response->setError($statusCode, $error, $error_description, $error_uri); $this->assertEquals($expected, $response->getContent()); $this->assertEquals($statusCode, $response->getStatusCode()); }
public function createTokenFromResponse(Response $response) { $token = json_decode($response->getContent(), true); if (isset($token['access_token'])) { return new Token($token['access_token'], $token['response_token']); } return false; }
public function buildMessage(Response $response) { $str = ''; $str .= $response->getStatus(); $str .= "\nURL:\n" . $response->getUrl(); $str .= "\nPARAMS:\n" . var_export($response->getParams(), true); $str .= "\nRESPONSE HEADER:\n" . var_export($response->getHeaders(), true); $str .= "\nRESPONSE CONTENT:\n" . substr($response->getContent(), 0, 200); return $str; }
/** * @param Response $response */ public function __construct(Response $response) { $content = json_decode($response->getContent(), TRUE); if ($content !== NULL && is_array($content)) { foreach ($content as $sectionIdentifier => $sectionData) { $section = new ResponseSection($sectionIdentifier, $sectionData); $this->sections[$sectionIdentifier] = $section; } } }
/** * * @param Response $response * @return string */ private function createTemplate($response) { $content = $response->getContent(); if ($content instanceof \Exception) { $templateContent = $this->createExceptionContent($content); } else { $templateContent = $this->createObjectContent($content); } $template = '<!DOCTYPE html> <HTML> <HEAD> </HEAD> <BODY>' . $templateContent . '</BODY> </HEAD> '; return $template; }
/** * Process this Request when an exception occured * * @param Request $request * @param Response $response * @param Exception $exception * @return Response */ public static function process_with_exception(Request $request, Response $response, Exception $exception) { $body = $response->getContent(); if (ob_get_length()) { ob_end_clean(); } $template = ActionView::factory('php'); $template->assign('error', $exception); $template->assign('request', $request); $template->assign('response', $response); $template->assign('body', $body); $text = $template->render_file(MEDICK_PATH . '/libs/action/controller/templates/error.phtml'); $response->setStatus(HTTPResponse::SC_INTERNAL_SERVER_ERROR); $response->setContent($text); return $response; }
public function testSetContent() { $response = new Response('first'); $response->setContent('second'); $this->assertEquals('second', $response->getContent()); }
/** * Converts the HttpKernel response to a BrowserKit response. * * @param Response $response A Response instance * * @return Response A Response instance */ protected function filterResponse($response) { return new DomResponse($response->getContent(), $response->getStatusCode(), $response->headers->all()); }
/** * Send Response to client * * @param $response * @param String|null $flash */ private function _sendResponse($response, $flash = null) { try { if ($response instanceof Response) { switch (strtolower($response->getType())) { case 'html': $view = $this->getMainLayout(); $wrapped = Controller::renderit($view, array('content' => $response->getContent())); //, 'flush' => $flash)); $response = new Response($wrapped); break; case 'ajax': $response = new Response($response->getContent()); break; } $response->send(); } else { throw new \Exception('Bad response', 500); } } catch (\Exception $e) { new Response($this->renderError($e)); } }
/** * @param Response $response * @return array */ public function parse(Response $response) { return $this->convertXmlToArray($response->getContent()); }
/** * @inheritdoc */ public function parse(Response $response) { return json_decode($response->getContent(), true); }
public function testWrite() { $this->object->write('1'); $this->object->write('2'); $this->assertThat($this->object->getContent(), $this->equalTo('12')); }
/** * Converts the HttpKernel response to a BrowserKit response. * * @param Response $response A Response instance * * @return Response A Response instance */ protected function filterResponse($response) { $headers = $response->headers->all(); if ($response->headers->getCookies()) { $cookies = array(); foreach ($response->headers->getCookies() as $cookie) { $cookies[] = new DomCookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); } $headers['Set-Cookie'] = $cookies; } return new DomResponse($response->getContent(), $response->getStatusCode(), $headers); }
/** * @param Response $response * * @return \Exception */ protected function handleResponse(Response $response) { if ($this->exception) { return $this->exception->create($response->getContent(), $response->getStatusCode()); } $content = json_decode($response->getContent()); return new \RuntimeException(sprintf('[%d] %s (%s)', $response->getStatusCode(), $content->message, $content->id)); }
/** * Checks the success state of a response * * @param Response $response Response object * @param bool $success to define whether the response is expected to be successful * @param string $type * * @return void */ public function isSuccessful($response, $success = true, $type = 'text/html') { try { $crawler = new Crawler(); $crawler->addContent($response->getContent(), $type); if (!count($crawler->filter('title'))) { $title = '[' . $response->getStatusCode() . '] - ' . $response->getContent(); } else { $title = $crawler->filter('title')->text(); } } catch (\Exception $e) { $title = $e->getMessage(); } if ($success) { $this->assertTrue($response->isSuccessful(), 'The Response was not successful: ' . $title); } else { $this->assertFalse($response->isSuccessful(), 'The Response was successful: ' . $title); } }
/** * マイページ画面に「メールマガジン送付について」項目を追加したHTMLを取得する. * * @param FilterResponseEvent $event * @param Request $request * @param Response $response */ protected function getNewMypageChangeHtml($event, $request, $response) { $app =& $this->app; $crawler = new Crawler($response->getContent()); $html = $this->getHtml($crawler); $mode = $request->get('mode'); try { // カスタマIDの取得 $Customer = $app->user(); if (is_null($Customer)) { return $html; } // Formの取得 $builder = $app['form.factory']->createBuilder('entry'); $form = $builder->getForm(); if ('POST' === $this->app['request']->getMethod()) { $form->handleRequest($request); } else { // DBからメルマガ送付情報を取得する $MailmagaCustomerRepository = $this->app['eccube.plugin.mail_magazine.repository.mail_magazine_mailmaga_customer']; $MailmagaCustomer = $MailmagaCustomerRepository->findOneBy(array('customer_id' => $Customer->getId())); if (!is_null($MailmagaCustomer)) { $form->get('mailmaga_flg')->setData($MailmagaCustomer->getMailmagaFlg()); } } // 追加先のノードを取得 if (!count($crawler->filter('.dl_table.not_required')->last())) { return $html; } $nodeHtml = $crawler->filter('.dl_table.not_required')->last()->html(); // 追加する情報のHTMLを取得する. $parts = $this->app['twig']->render('MailMagazine/View/entry_add_mailmaga.twig', array('form' => $form->createView())); $newNodeHtml = $nodeHtml . $parts; $html = str_replace($nodeHtml, $newNodeHtml, $html); } catch (\InvalidArgumentException $e) { // no-op } return $html; }
/** * (non-PHPdoc) * @see Response::getContent() */ public function getContent() { return $this->response->getContent(); }
/** * Filters the Response. * * @param Response $response The Response to filter * * @return Response */ protected function filterResponse($response) { $headers = $response->headers->all(); if ($cookies = $response->headers->getCookies()) { ///\out::e($cookies); /* $cookies = array(); foreach($response->headers->getCookies() as $cookie){ $cookies[] = new Cookie( $cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly() ); }//foreach */ $headers['Set-Cookie'] = implode(', ', $cookies); } //if $bk_response = new BrowserKitResponse($response->getContent(), $response->getStatusCode(), $headers); return $bk_response; }
public function testSetCnt() { $any_cnt = 123; $Response = new Response(); $Response->setCnt($any_cnt); $this->assertContains('"meta":{"cnt":123', $Response->getContent()); }
/** * Process this Request when an exception occured * * @param Request $request * @param Response $response * @param Exception $exception * @return Response */ public static function process_with_exception(Request $request, Response $response, Exception $exception) { $body = $response->getContent(); if (ob_get_length()) { ob_end_clean(); } if ($request->isXhr()) { $x = $exception->getTrace(); $text = sprintf("Got %s\nat line %d in %s\n%s", get_class($exception), @$x[0]['line'], @$x[0]['file'], $exception->getMessage()); } else { $template = ActionView::factory('php'); $template->assign('error', $exception); $template->assign('request', $request); $template->assign('response', $response); $template->assign('body', $body); $text = $template->render_file(MEDICK_PATH . '/libs/action/controller/templates/error.phtml'); } $response->setStatus(HTTPResponse::SC_INTERNAL_SERVER_ERROR); $response->setContent($text); return $response; }
/** * @param Response $response * @param int $statusCode */ protected function assertJsonResponse(Response $response, $statusCode = 200) { $this->assertEquals($statusCode, $response->getStatusCode(), $response->getContent()); $this->assertTrue($response->headers->contains('Content-Type', 'application/json'), $response->headers); }