Ejemplo n.º 1
0
 public function doRequest($request)
 {
     // redirector should not exit
     $redirector = \Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
     $redirector->setExit(false);
     // json helper should not exit
     $json = \Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $zendRequest = new \Zend_Controller_Request_HttpTestCase();
     $zendRequest->setMethod($request->getMethod());
     $zendRequest->setCookies($request->getCookies());
     $zendRequest->setParams($request->getParameters());
     // Sf2's BrowserKit does not distinguish between GET, POST, PUT etc.,
     // so we set all parameters in ZF's request here to not break apps
     // relying on $request->getPost()
     $zendRequest->setPost($request->getParameters());
     $zendRequest->setRawBody($request->getContent());
     $zendRequest->setRequestUri(str_replace('http://localhost', '', $request->getUri()));
     $zendRequest->setHeaders($this->extractHeaders($request));
     $_FILES = $this->remapFiles($request->getFiles());
     $_SERVER = array_merge($_SERVER, $request->getServer());
     $zendResponse = new \Zend_Controller_Response_HttpTestCase();
     $this->front->setRequest($zendRequest)->setResponse($zendResponse);
     ob_start();
     try {
         $this->bootstrap->run();
     } catch (\Exception $e) {
         ob_end_clean();
         throw $e;
     }
     ob_end_clean();
     $this->zendRequest = $zendRequest;
     $response = new Response($zendResponse->getBody(), $zendResponse->getHttpResponseCode(), $this->formatResponseHeaders($zendResponse));
     return $response;
 }
Ejemplo n.º 2
0
 /**
  * Set POST values method
  *
  * @param  string|array $spec
  * @param  null|mixed   $value
  * @return Zend_Controller_Request_Http
  */
 public function setPost($spec, $value = null)
 {
     if (!is_array($spec) && $value === null) {
         unset($_POST[$spec]);
         return $this;
     } elseif (is_array($spec) && empty($spec)) {
         $_POST = array();
         return $this;
     }
     return parent::setPost($spec, $value);
 }
Ejemplo n.º 3
0
 public function testFilterThemesFormForAllowedAndUnallowedElementsAndAttributes()
 {
     $dirtyHtml = '<p class="person" href="what"><strong>Bob</strong> is <em>dead</em>.</p><br />';
     $cleanHtml = '<p class="person">Bob is dead.</p><br />';
     // Create a request with dirty html for the collection description post variable
     $request = new Zend_Controller_Request_HttpTestCase();
     // post can be any nested array of strings
     $post = array('whatever' => $dirtyHtml, 'NestedArray' => array(0 => array(array('text' => $dirtyHtml), array('text' => $dirtyHtml)), 1 => array(array('text' => $dirtyHtml), array('text' => $dirtyHtml))), 'whatever2' => $dirtyHtml);
     $request->setPost($post);
     // Html purify the request
     $htmlPurifierPlugin = $this->_getHtmlPurifierPlugin(array('p', 'br'), array('*.class'));
     $htmlPurifierPlugin->filterThemesForm($request);
     // Make sure the description post variable is clean
     $post = $request->getPost();
     $this->assertEquals($cleanHtml, $post['whatever']);
     $this->assertEquals($cleanHtml, $post['NestedArray'][0][0]['text']);
     $this->assertEquals($cleanHtml, $post['NestedArray'][0][1]['text']);
     $this->assertEquals($cleanHtml, $post['NestedArray'][1][0]['text']);
     $this->assertEquals($cleanHtml, $post['NestedArray'][1][1]['text']);
     $this->assertEquals($cleanHtml, $post['whatever2']);
 }
 /**
  * Simulates POST parameters.
  *
  * The parameters may be passed as array...
  *
  *     $this->setPost(array('name' => 'Matthias'));
  *
  * ... or as Zend_Form object:
  *
  *     $form = new Zend_Form();
  *     $form->populate(array('name' => 'Matthias'));
  *     $this->setPost($form);
  *
  * @param array(string=>mixed)|Zend_Form $arrayOrForm
  */
 protected function setPost($arrayOrForm)
 {
     $this->request->setMethod('POST');
     $this->request->setPost($this->toStrings($this->toValues($arrayOrForm)));
 }