mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +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)) {
|
||||
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 @@ 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.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue