From 4ff07b745aecb159a053067fea0a622d0b7b4af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Sat, 22 Nov 2014 17:30:53 +0100 Subject: [PATCH] Adding a test for the new json and xml detectors that were added to the CakeRequest class. --- lib/Cake/Network/CakeRequest.php | 2 +- .../Test/Case/Network/CakeRequestTest.php | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 452dcb047..307066299 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -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)) { diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index 99d51c8ac..14a3d63f4 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -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. *