Permalink
Browse files

adding query() for CakeRequest

  • Loading branch information...
dereuromark committed Sep 18, 2012
1 parent 144761c commit e8cfac0eecd5323b0382d36b72b131902b9261c5
Showing with 28 additions and 0 deletions.
  1. +10 −0 lib/Cake/Network/CakeRequest.php
  2. +18 −0 lib/Cake/Test/Case/Network/CakeRequestTest.php
@@ -758,6 +758,16 @@ protected static function _parseAcceptWithQualifier($header) {
return $accept;
}
+/**
+ * Provides a read accessor for `$this->query`. Allows you
+ * to use a syntax similar to `CakeSession` for reading url query data.
+ *
+ * @return mixed The value being read
+ */
+ public function query($name) {
+ return Hash::get($this->query, $name);
+ }
+
/**
* Provides a read/write accessor for `$this->data`. Allows you
* to use a syntax similar to `CakeSession` for reading post data.
@@ -1678,6 +1678,24 @@ public function testEnvironmentDetection($name, $env, $expected) {
}
}
+/**
+ * test the query() method
+ *
+ * @return void
+ */
+ public function testQuery() {
+ $_GET = array();
+ $_GET['foo'] = 'bar';
+
+ $request = new CakeRequest();
+
+ $result = $request->query('foo');
+ $this->assertEquals('bar', $result);
+
+ $result = $request->query('imaginary');
+ $this->assertNull($result);
+ }
+
/**
* test the data() method reading
*

0 comments on commit e8cfac0

Please sign in to comment.