Skip to content

Commit

Permalink
fix query merge from constructor and add additional tests for query a…
Browse files Browse the repository at this point in the history
…nd data
  • Loading branch information
mikegreiling committed Mar 20, 2013
1 parent 6bad147 commit 4fff5b1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
4 changes: 3 additions & 1 deletion net/http/Message.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function __construct(array $config = array()) {
'auth' => null 'auth' => null
); );
$config += $defaults; $config += $defaults;
parent::__construct($config);
foreach (array_intersect_key(array_filter($config), $defaults) as $key => $value) { foreach (array_intersect_key(array_filter($config), $defaults) as $key => $value) {
$this->{$key} = $value; $this->{$key} = $value;
} }
Expand All @@ -92,6 +92,8 @@ public function __construct(array $config = array()) {
} }
$this->path = str_replace('//', '/', "/{$this->path}"); $this->path = str_replace('//', '/', "/{$this->path}");
$this->protocol = $this->protocol ?: "HTTP/{$this->version}"; $this->protocol = $this->protocol ?: "HTTP/{$this->version}";

parent::__construct($config);
} }


/** /**
Expand Down
10 changes: 10 additions & 0 deletions net/http/Request.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ public function __construct(array $config = array()) {
'followLocation' => true 'followLocation' => true
); );
parent::__construct($config + $defaults); 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->method = $this->method ?: $this->_config['method'];


$this->headers = array( $this->headers = array(
Expand Down
20 changes: 19 additions & 1 deletion tests/cases/action/RequestTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ class RequestTest extends \lithium\test\Unit {


protected $_get = array(); protected $_get = array();


protected $_post = array();

public function setUp() { public function setUp() {
$this->request = new Request(array('init' => false)); $this->request = new Request(array('init' => false));
$this->_get = $_GET; $this->_get = $_GET;
unset($_GET); $this->_post = $_POST;
unset($_GET, $_POST);
} }


public function tearDown() { public function tearDown() {
unset($this->request); unset($this->request);
$_GET = $this->_get; $_GET = $this->_get;
$_POST = $this->_post;
} }


public function testInitData() { public function testInitData() {
Expand Down Expand Up @@ -871,6 +875,13 @@ public function testDataFromConstructor() {
$expected = array('name' => 'bob'); $expected = array('name' => 'bob');
$result = $request->data; $result = $request->data;
$this->assertEqual($expected, $result); $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() { public function testQueryFromConstructor() {
Expand All @@ -879,6 +890,13 @@ public function testQueryFromConstructor() {
$expected = array('page' => 1); $expected = array('page' => 1);
$result = $request->query; $result = $request->query;
$this->assertEqual($expected, $result); $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() { public function testMethodOverrideFromData() {
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/net/http/RequestTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RequestTest extends \lithium\test\Unit {
public $request = null; public $request = null;


public function setUp() { public function setUp() {
$this->request = new Request(array('init' => false)); $this->request = new Request();
} }


public function testConstruct() { public function testConstruct() {
Expand Down

0 comments on commit 4fff5b1

Please sign in to comment.