mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Add CakeRequest::isAll().
Provides a way to test multiple request types at the same time. And assert that all pass. This replaces longer conditionals with a terser syntax. Refs #3714
This commit is contained in:
parent
d4a3594e4f
commit
ce04d6afa1
2 changed files with 32 additions and 0 deletions
|
@ -509,6 +509,22 @@ class CakeRequest implements ArrayAccess {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a request matches all the given types.
|
||||
*
|
||||
* Allows you to test multiple types and union the results.
|
||||
* See CakeRequest::is() for how to add additional types and the
|
||||
* built-in types.
|
||||
*
|
||||
* @param array $types The types to check.
|
||||
* @return boolean Success.
|
||||
* @see CakeRequest::is()
|
||||
*/
|
||||
public function isAll(array $types) {
|
||||
$result = array_filter(array_map(array($this, 'is'), $types));
|
||||
return count($result) === count($types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new detector to the list of detectors that a request can use.
|
||||
* There are several different formats and types of detectors that can be set.
|
||||
|
|
|
@ -741,6 +741,22 @@ class CakeRequestTest extends CakeTestCase {
|
|||
$this->assertFalse($request->is(array('get', 'post')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test isAll()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsAll() {
|
||||
$request = new CakeRequest('some/path');
|
||||
|
||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
|
||||
$this->assertTrue($request->isAll(array('ajax', 'get')));
|
||||
$this->assertFalse($request->isAll(array('post', 'get')));
|
||||
$this->assertFalse($request->isAll(array('ajax', 'post')));
|
||||
}
|
||||
|
||||
/**
|
||||
* test the method() method.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue