mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
Adding a test for the new json and xml detectors that were added to the CakeRequest class.
This commit is contained in:
parent
83eb8ce7de
commit
4ff07b745a
2 changed files with 20 additions and 2 deletions
|
@ -503,7 +503,7 @@ class CakeRequest implements ArrayAccess {
|
||||||
if (isset($detect['env']) && $this->_environmentDetector($detect)) {
|
if (isset($detect['env']) && $this->_environmentDetector($detect)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (isset($detect['header']) && $this->_environmentDetector($detect)) {
|
if (isset($detect['header']) && $this->_headerDetector($detect)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (isset($detect['param']) && $this->_paramDetector($detect)) {
|
if (isset($detect['param']) && $this->_paramDetector($detect)) {
|
||||||
|
|
|
@ -106,7 +106,7 @@ class CakeRequestTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testHeaderDetector() {
|
public function testHeaderDetector() {
|
||||||
$request = $this->getMock('TestCakeRequest', array('getAcceptHeaders'));
|
$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');
|
$detector = array('header' => array('application/json'), 'param' => 'ext', 'value' => 'json');
|
||||||
$request->expects($this->once())
|
$request->expects($this->once())
|
||||||
->method('getAcceptHeaders')
|
->method('getAcceptHeaders')
|
||||||
|
@ -776,6 +776,24 @@ class CakeRequestTest extends CakeTestCase {
|
||||||
$this->assertFalse($request->is('delete'));
|
$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.
|
* Test is() with multiple types.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue