Browse files

fix query merge from constructor and add additional tests for query a…

…nd data
  • Loading branch information...
1 parent 6bad147 commit 4fff5b19e4cb417016a4428dfef22f12bfa554e6 @mikegreiling mikegreiling committed Mar 18, 2013
Showing with 33 additions and 3 deletions.
  1. +3 −1 net/http/Message.php
  2. +10 −0 net/http/Request.php
  3. +19 −1 tests/cases/action/RequestTest.php
  4. +1 −1 tests/cases/net/http/RequestTest.php
View
4 net/http/Message.php
@@ -83,7 +83,7 @@ public function __construct(array $config = array()) {
'auth' => null
);
$config += $defaults;
- parent::__construct($config);
+
foreach (array_intersect_key(array_filter($config), $defaults) as $key => $value) {
$this->{$key} = $value;
}
@@ -92,6 +92,8 @@ public function __construct(array $config = array()) {
}
$this->path = str_replace('//', '/', "/{$this->path}");
$this->protocol = $this->protocol ?: "HTTP/{$this->version}";
+
+ parent::__construct($config);
}
/**
View
10 net/http/Request.php
@@ -84,6 +84,16 @@ public function __construct(array $config = array()) {
'followLocation' => true
);
parent::__construct($config + $defaults);
+ }
+
+ /**
+ * Initialize request object method, content type, and headers
+ *
+ * @return void
+ */
+ protected function _init() {
+ parent::_init();
+
$this->method = $this->method ?: $this->_config['method'];
$this->headers = array(
View
20 tests/cases/action/RequestTest.php
@@ -19,15 +19,19 @@ class RequestTest extends \lithium\test\Unit {
protected $_get = array();
+ protected $_post = array();
+
public function setUp() {
$this->request = new Request(array('init' => false));
$this->_get = $_GET;
- unset($_GET);
+ $this->_post = $_POST;
+ unset($_GET, $_POST);
}
public function tearDown() {
unset($this->request);
$_GET = $this->_get;
+ $_POST = $this->_post;
}
public function testInitData() {
@@ -871,6 +875,13 @@ public function testDataFromConstructor() {
$expected = array('name' => 'bob');
$result = $request->data;
$this->assertEqual($expected, $result);
+
+ $_POST['organization'] = 'Union of Rad';
+ $request = new Request(array('data' => array('name' => 'bob')));
+
+ $expected = array('name' => 'bob', 'organization' => 'Union of Rad');
+ $result = $request->data;
+ $this->assertEqual($expected, $result);
}
public function testQueryFromConstructor() {
@@ -879,6 +890,13 @@ public function testQueryFromConstructor() {
$expected = array('page' => 1);
$result = $request->query;
$this->assertEqual($expected, $result);
+
+ $_GET = array('limit' => 10);
+ $request = new Request(array('query' => array('page' => 1)));
+
+ $expected = array('page' => 1, 'limit' => 10);
+ $result = $request->query;
+ $this->assertEqual($expected, $result);
}
public function testMethodOverrideFromData() {
View
2 tests/cases/net/http/RequestTest.php
@@ -15,7 +15,7 @@ class RequestTest extends \lithium\test\Unit {
public $request = null;
public function setUp() {
- $this->request = new Request(array('init' => false));
+ $this->request = new Request();
}
public function testConstruct() {

0 comments on commit 4fff5b1

Please sign in to comment.