|
|
@@ -21,6 +21,34 @@ App::uses('Dispatcher', 'Routing');
|
|
|
App::uses('Xml', 'Utility');
|
|
|
App::uses('CakeRequest', 'Network');
|
|
|
|
|
|
+class TestCakeRequest extends CakeRequest {
|
|
|
+
|
|
|
+ public $input;
|
|
|
+
|
|
|
+ public function reConstruct($url = 'some/path', $parseEnvironment = true) {
|
|
|
+ $this->_base();
|
|
|
+ if (empty($url)) {
|
|
|
+ $url = $this->_url();
|
|
|
+ }
|
|
|
+ if ($url[0] == '/') {
|
|
|
+ $url = substr($url, 1);
|
|
|
+ }
|
|
|
+ $this->url = $url;
|
|
|
+
|
|
|
+ if ($parseEnvironment) {
|
|
|
+ $this->_processPost();
|
|
|
+ $this->_processGet();
|
|
|
+ $this->_processFiles();
|
|
|
+ }
|
|
|
+ $this->here = $this->base . '/' . $this->url;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function _readInput() {
|
|
|
+ return $this->input;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
class CakeRequestTest extends CakeTestCase {
|
|
|
|
|
|
/**
|
|
|
@@ -41,7 +69,7 @@ class CakeRequestTest extends CakeTestCase {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * tearDown-
|
|
|
+ * tearDown
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
@@ -205,6 +233,79 @@ class CakeRequestTest extends CakeTestCase {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * test parsing PUT data into the object.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testPutParsing() {
|
|
|
+ $_SERVER['REQUEST_METHOD'] = 'PUT';
|
|
|
+ $_SERVER['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
|
|
|
+
|
|
|
+ $data = array('data' => array(
|
|
|
+ 'Article' => array('title')
|
|
|
+ ));
|
|
|
+
|
|
|
+ $request = $this->getMock('TestCakeRequest', array('_readInput'));
|
|
|
+ $request->expects($this->at(0))->method('_readInput')
|
|
|
+ ->will($this->returnValue('data[Article][]=title'));
|
|
|
+ $request->reConstruct();
|
|
|
+ $this->assertEquals($data['data'], $request->data);
|
|
|
+
|
|
|
+ $data = array('one' => 1, 'two' => 'three');
|
|
|
+ $request = $this->getMock('TestCakeRequest', array('_readInput'));
|
|
|
+ $request->expects($this->at(0))->method('_readInput')
|
|
|
+ ->will($this->returnValue('one=1&two=three'));
|
|
|
+ $request->reConstruct();
|
|
|
+ $this->assertEquals($data, $request->data);
|
|
|
+
|
|
|
+ $data = array(
|
|
|
+ 'data' => array(
|
|
|
+ 'Article' => array('title' => 'Testing'),
|
|
|
+ ),
|
|
|
+ 'action' => 'update'
|
|
|
+ );
|
|
|
+ $request = $this->getMock('TestCakeRequest', array('_readInput'));
|
|
|
+ $request->expects($this->at(0))->method('_readInput')
|
|
|
+ ->will($this->returnValue('data[Article][title]=Testing&action=update'));
|
|
|
+ $request->reConstruct();
|
|
|
+ $expected = array(
|
|
|
+ 'Article' => array('title' => 'Testing'),
|
|
|
+ 'action' => 'update'
|
|
|
+ );
|
|
|
+ $this->assertEquals($expected, $request->data);
|
|
|
+
|
|
|
+ $data = array('data' => array(
|
|
|
+ 'Article' => array('title'),
|
|
|
+ 'Tag' => array('Tag' => array(1, 2))
|
|
|
+ ));
|
|
|
+ $request = $this->getMock('TestCakeRequest', array('_readInput'));
|
|
|
+ $request->expects($this->at(0))->method('_readInput')
|
|
|
+ ->will($this->returnValue('data[Article][]=title&Tag[Tag][]=1&Tag[Tag][]=2'));
|
|
|
+ $request->reConstruct();
|
|
|
+ $this->assertEquals($data['data'], $request->data);
|
|
|
+
|
|
|
+ $data = array('data' => array(
|
|
|
+ 'Article' => array('title' => 'some title'),
|
|
|
+ 'Tag' => array('Tag' => array(1, 2))
|
|
|
+ ));
|
|
|
+ $request = $this->getMock('TestCakeRequest', array('_readInput'));
|
|
|
+ $request->expects($this->at(0))->method('_readInput')
|
|
|
+ ->will($this->returnValue('data[Article][title]=some%20title&Tag[Tag][]=1&Tag[Tag][]=2'));
|
|
|
+ $request->reConstruct();
|
|
|
+ $this->assertEquals($data['data'], $request->data);
|
|
|
+
|
|
|
+ $data = array(
|
|
|
+ 'a' => array(1, 2),
|
|
|
+ 'b' => array(1, 2)
|
|
|
+ );
|
|
|
+ $request = $this->getMock('TestCakeRequest', array('_readInput'));
|
|
|
+ $request->expects($this->at(0))->method('_readInput')
|
|
|
+ ->will($this->returnValue('a[]=1&a[]=2&b[]=1&b[]=2'));
|
|
|
+ $request->reConstruct();
|
|
|
+ $this->assertEquals($data, $request->data);
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
* test parsing of FILES array
|
|
|
*
|
|
|
* @return void
|