Skip to content

Commit

Permalink
[HttpKernel] Added tests for non UTF-8 content types.
Browse files Browse the repository at this point in the history
Tests to check that #1281 is fixed and to prevent regression in the
future.
  • Loading branch information
asm89 committed Jun 11, 2011
1 parent 2e5ed78 commit 07d823c
Showing 1 changed file with 42 additions and 0 deletions.
Expand Up @@ -87,4 +87,46 @@ public function testFilterRemovesContentForHeadRequests()

$this->assertEquals('', $response->getContent());
}

public function testFilterSetsNonDefaultCharsetIfNotOverridden()
{
$listener = new ResponseListener('ISO-8859-15');
$this->dispatcher->addListener(CoreEvents::RESPONSE, array($listener, 'onCoreResponse'), 1);

$response = new Response('foo');

$event = new FilterResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response);
$this->dispatcher->dispatch(CoreEvents::RESPONSE, $event);

$this->assertEquals('ISO-8859-15', $response->getCharset());
}

public function testFilterDoesNothingIfCharsetIsOverridden()
{
$listener = new ResponseListener('ISO-8859-15');
$this->dispatcher->addListener(CoreEvents::RESPONSE, array($listener, 'onCoreResponse'), 1);

$response = new Response('foo');
$response->setCharset('ISO-8859-1');

$event = new FilterResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response);
$this->dispatcher->dispatch(CoreEvents::RESPONSE, $event);

$this->assertEquals('ISO-8859-1', $response->getCharset());
}

public function testFiltersSetsNonDefaultCharsetIfNotOverriddenOnNonTextContentType()
{
$listener = new ResponseListener('ISO-8859-15');
$this->dispatcher->addListener(CoreEvents::RESPONSE, array($listener, 'onCoreResponse'), 1);

$response = new Response('foo');
$request = Request::create('/');
$request->setRequestFormat('application/json');

$event = new FilterResponseEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
$this->dispatcher->dispatch(CoreEvents::RESPONSE, $event);

$this->assertEquals('ISO-8859-15', $response->getCharset());
}
}

0 comments on commit 07d823c

Please sign in to comment.