Skip to content
Browse files

read request cookies from superglobals

  • Loading branch information...
1 parent 4fff5b1 commit 8e891894fc84a7466d79d3be42aaf5517fa239e6 @mikegreiling mikegreiling committed Mar 18, 2013
Showing with 26 additions and 1 deletion.
  1. +6 −0 action/Request.php
  2. +20 −1 tests/cases/action/RequestTest.php
View
6 action/Request.php
@@ -175,6 +175,12 @@ protected function _init() {
if (isset($_POST)) {
$this->data += $_POST;
}
+ if (!empty($this->_config['cookies'])) {
+ $this->cookies = $this->_config['cookies'];
+ }
+ if (isset($_COOKIE)) {
+ $this->cookies += $_COOKIE;
+ }
if (isset($this->data['_method'])) {
$this->_env['HTTP_X_HTTP_METHOD_OVERRIDE'] = strtoupper($this->data['_method']);
unset($this->data['_method']);
View
21 tests/cases/action/RequestTest.php
@@ -21,17 +21,21 @@ class RequestTest extends \lithium\test\Unit {
protected $_post = array();
+ protected $_cookie = array();
+
public function setUp() {
$this->request = new Request(array('init' => false));
$this->_get = $_GET;
$this->_post = $_POST;
- unset($_GET, $_POST);
+ $this->_cookie = $_COOKIE;
+ unset($_GET, $_POST, $_COOKIE);
}
public function tearDown() {
unset($this->request);
$_GET = $this->_get;
$_POST = $this->_post;
+ $_COOKIE = $this->_cookie;
}
public function testInitData() {
@@ -899,6 +903,21 @@ public function testQueryFromConstructor() {
$this->assertEqual($expected, $result);
}
+ public function testCookiesFromConstructor() {
+ $request = new Request(array('cookies' => array('sid' => 12345)));
+
+ $expected = array('sid' => 12345);
+ $result = $request->cookies;
+ $this->assertEqual($expected, $result);
+
+ $_COOKIE['token'] = 'foo';
+ $request = new Request(array('cookies' => array('sid' => 12345)));
+
+ $expected = array('sid' => 12345, 'token' => 'foo');
+ $result = $request->cookies;
+ $this->assertEqual($expected, $result);
+ }
+
public function testMethodOverrideFromData() {
$_POST['_method'] = 'put';
$request = new Request();

0 comments on commit 8e89189

Please sign in to comment.
Something went wrong with that request. Please try again.