Adding a test for the new json and xml detectors that were added to the CakeRequest class.

This commit is contained in:
Florian Krämer 2014-11-22 17:30:53 +01:00
parent 83eb8ce7de
commit 4ff07b745a
2 changed files with 20 additions and 2 deletions

View file

@ -503,7 +503,7 @@ class CakeRequest implements ArrayAccess {
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)) {

View file

@ -106,7 +106,7 @@ class CakeRequestTest extends CakeTestCase {
*/
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 @@ class CakeRequestTest extends CakeTestCase {
$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.
*