You are here

public function RequestTest::testGetSetMethod in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/Tests/RequestTest.php \Symfony\Component\HttpFoundation\Tests\RequestTest::testGetSetMethod()

@covers Symfony\Component\HttpFoundation\Request::setMethod @covers Symfony\Component\HttpFoundation\Request::getMethod

File

vendor/symfony/http-foundation/Tests/RequestTest.php, line 801

Class

RequestTest

Namespace

Symfony\Component\HttpFoundation\Tests

Code

public function testGetSetMethod() {
  $request = new Request();
  $this
    ->assertEquals('GET', $request
    ->getMethod(), '->getMethod() returns GET if no method is defined');
  $request
    ->setMethod('get');
  $this
    ->assertEquals('GET', $request
    ->getMethod(), '->getMethod() returns an uppercased string');
  $request
    ->setMethod('PURGE');
  $this
    ->assertEquals('PURGE', $request
    ->getMethod(), '->getMethod() returns the method even if it is not a standard one');
  $request
    ->setMethod('POST');
  $this
    ->assertEquals('POST', $request
    ->getMethod(), '->getMethod() returns the method POST if no _method is defined');
  $request
    ->setMethod('POST');
  $request->request
    ->set('_method', 'purge');
  $this
    ->assertEquals('POST', $request
    ->getMethod(), '->getMethod() does not return the method from _method if defined and POST but support not enabled');
  $request = new Request();
  $request
    ->setMethod('POST');
  $request->request
    ->set('_method', 'purge');
  $this
    ->assertFalse(Request::getHttpMethodParameterOverride(), 'httpMethodParameterOverride should be disabled by default');
  Request::enableHttpMethodParameterOverride();
  $this
    ->assertTrue(Request::getHttpMethodParameterOverride(), 'httpMethodParameterOverride should be enabled now but it is not');
  $this
    ->assertEquals('PURGE', $request
    ->getMethod(), '->getMethod() returns the method from _method if defined and POST');
  $this
    ->disableHttpMethodParameterOverride();
  $request = new Request();
  $request
    ->setMethod('POST');
  $request->query
    ->set('_method', 'purge');
  $this
    ->assertEquals('POST', $request
    ->getMethod(), '->getMethod() does not return the method from _method if defined and POST but support not enabled');
  $request = new Request();
  $request
    ->setMethod('POST');
  $request->query
    ->set('_method', 'purge');
  Request::enableHttpMethodParameterOverride();
  $this
    ->assertEquals('PURGE', $request
    ->getMethod(), '->getMethod() returns the method from _method if defined and POST');
  $this
    ->disableHttpMethodParameterOverride();
  $request = new Request();
  $request
    ->setMethod('POST');
  $request->headers
    ->set('X-HTTP-METHOD-OVERRIDE', 'delete');
  $this
    ->assertEquals('DELETE', $request
    ->getMethod(), '->getMethod() returns the method from X-HTTP-Method-Override even though _method is set if defined and POST');
  $request = new Request();
  $request
    ->setMethod('POST');
  $request->headers
    ->set('X-HTTP-METHOD-OVERRIDE', 'delete');
  $this
    ->assertEquals('DELETE', $request
    ->getMethod(), '->getMethod() returns the method from X-HTTP-Method-Override if defined and POST');
}