public static function __set_state($data) { return parent::__set_state($data); }
/** * Restore a \Phalcon\Http\Response\Headers object * * @param array $data * @return \Phalcon\Http\Response\Headers * @throws Exception */ public static function __set_state($data) { if (is_array($data) === false) { throw new Exception('Invalid parameter type.'); } $headers = new Headers(); if (isset($data['_headers']) === true && is_array($data['_headers']) === true) { foreach ($data['_headers'] as $key => $value) { //@note this doesn't work for raw headers! $headers->set($key, $value); } } return $headers; }
/** * Tests redirect remotely 301 * * @author Nikolaos Dimopoulos <*****@*****.**> * @since 2014-10-08 */ public function testHttpResponseRedirectRemoteLUrl301() { $this->specify("redirect is not redirecting remote 301 properly", function () { $response = $this->getResponseObject(); $response->resetHeaders(); $response->redirect("http://google.com", true, 301); $actual = $response->getHeaders(); $expected = PhResponseHeaders::__set_state(['_headers' => ['Status' => '301 Moved Permanently', 'Location' => 'http://google.com', 'HTTP/1.1 301 Moved Permanently' => null]]); expect($actual)->equals($expected); }); }
/** * Tests setCache * * @author Sid Roberts <*****@*****.**> * @since 2015-07-14 */ public function testHttpResponseSetCache() { $this->specify("setCache is not producing the correct results", function () { $response = $this->getResponseObject(); $expiry = new \DateTime(); $expiry->setTimezone(new \DateTimeZone("UTC")); $expiry->modify("+60 minutes"); $response->setCache(60); $expected = Headers::__set_state(['_headers' => ["Expires" => $expiry->format("D, d M Y H:i:s") . " GMT", "Cache-Control" => "max-age=3600"]]); expect($response->getHeaders())->equals($expected); }); }
public function testRedirect() { //local URI $this->_response->resetHeaders(); $this->_response->redirect("some/local/uri"); $this->assertEquals(\Phalcon\Http\Response\Headers::__set_state(array('_headers' => array('HTTP/1.1 302 Found' => false, 'Status' => '302 Found', 'Location' => '/some/local/uri'))), $this->_response->getHeaders()); //Full URL $this->_response->resetHeaders(); $this->_response->redirect("http://google.com", true); $this->assertEquals(\Phalcon\Http\Response\Headers::__set_state(array('_headers' => array('HTTP/1.1 302 Found' => false, 'Status' => '302 Found', 'Location' => 'http://google.com'))), $this->_response->getHeaders()); //HTTP code $this->_response->resetHeaders(); $this->_response->redirect("http://google.com", true, 301); $this->assertEquals(\Phalcon\Http\Response\Headers::__set_state(array('_headers' => array('HTTP/1.1 301 Moved Permanently' => false, 'Status' => '301 Moved Permanently', 'Location' => 'http://google.com'))), $this->_response->getHeaders()); }
/** * Tests toArray in response headers * * @author Nikolaos Dimopoulos <*****@*****.**> * @since 2014-10-05 */ public function testHttpResponseHeadersToArray() { $this->specify("toArray in Response Headers is not correct", function () { $responseHeaders = new PhResponseHeaders(); $responseHeaders->set('Content-Type', 'text/html'); $expected = $responseHeaders->toArray(); $actual = ['Content-Type' => 'text/html']; expect($actual)->equals($expected); }); }