Permalink
Browse files

Adding a test for the new json and xml detectors that were added to t…

…he CakeRequest class.
  • Loading branch information...
burzum committed Nov 22, 2014
1 parent 83eb8ce commit 4ff07b745aecb159a053067fea0a622d0b7b4af4
Showing with 20 additions and 2 deletions.
  1. +1 −1 lib/Cake/Network/CakeRequest.php
  2. +19 −1 lib/Cake/Test/Case/Network/CakeRequestTest.php
@@ -503,7 +503,7 @@ public function is($type) {
if (isset($detect['env']) && $this->_environmentDetector($detect)) {
return true;
}
if (isset($detect['header']) && $this->_environmentDetector($detect)) {
if (isset($detect['header']) && $this->_headerDetector($detect)) {
return true;
}
if (isset($detect['param']) && $this->_paramDetector($detect)) {
@@ -106,7 +106,7 @@ public function tearDown() {
*/
public function testHeaderDetector() {
$request = $this->getMock('TestCakeRequest', array('getAcceptHeaders'));
$_SERVER['HTTP_ACCEPT'] = 'application/json';
$_SERVER['HTTP_ACCEPT'] = 'application/json, text/plain, */*';
$detector = array('header' => array('application/json'), 'param' => 'ext', 'value' => 'json');
$request->expects($this->once())
->method('getAcceptHeaders')
@@ -776,6 +776,24 @@ public function testIsHttpMethods() {
$this->assertFalse($request->is('delete'));
}
/**
* Test is() with json and xml.
*
* @return void
*/
public function testIsJsonAndXml() {
$request = new CakeRequest('some/path');
$_SERVER['HTTP_ACCEPT'] = 'application/json, text/plain, */*';
$this->assertTrue($request->is(array('json')));
$_SERVER['HTTP_ACCEPT'] = 'application/xml, text/plain, */*';
$this->assertTrue($request->is(array('xml')));
$_SERVER['HTTP_ACCEPT'] = 'text/xml, */*';
$this->assertTrue($request->is(array('xml')));
}
/**
* Test is() with multiple types.
*

0 comments on commit 4ff07b7

Please sign in to comment.