onlyAllow() public méthode

Alias of CakeRequest::allowMethod() for backwards compatibility.
See also: CakeRequest::allowMethod()
Deprecation: 3.0.0 Since 2.5, use CakeRequest::allowMethod() instead.
public onlyAllow ( string | array $methods ) : boolean
$methods string | array Allowed HTTP request methods.
Résultat boolean true
 /**
  * Test allowMethod method
  *
  * @return void
  */
 public function testAllowMethod()
 {
     $_SERVER['REQUEST_METHOD'] = 'PUT';
     $request = new CakeRequest('/posts/edit/1');
     $this->assertTrue($request->allowMethod(array('put')));
     // BC check
     $this->assertTrue($request->onlyAllow(array('put')));
     $_SERVER['REQUEST_METHOD'] = 'DELETE';
     $this->assertTrue($request->allowMethod('post', 'delete'));
     // BC check
     $this->assertTrue($request->onlyAllow('post', 'delete'));
 }
Exemple #2
0
 /**
  * TestOnlyAllow throwing exception
  *
  */
 public function testOnlyAllowException()
 {
     $_SERVER['REQUEST_METHOD'] = 'PUT';
     $request = new CakeRequest('/posts/edit/1');
     try {
         $request->onlyAllow('POST', 'DELETE');
         $this->fail('An expected exception has not been raised.');
     } catch (MethodNotAllowedException $e) {
         $this->assertEquals(array('Allow' => 'POST, DELETE'), $e->responseHeader());
     }
     $this->setExpectedException('MethodNotAllowedException');
     $request->onlyAllow('POST');
 }