Browse files

[HttpKernel] Added tests for non UTF-8 content types.

Tests to check that #1281 is fixed and to prevent regression in the
future.
  • Loading branch information...
1 parent 2e5ed78 commit 07d823caa8028a1bcf1fa5aa403aa977220809be @asm89 committed Jun 11, 2011
Showing with 42 additions and 0 deletions.
  1. +42 −0 tests/Symfony/Tests/Component/HttpKernel/EventListener/ResponseListenerTest.php
View
42 tests/Symfony/Tests/Component/HttpKernel/EventListener/ResponseListenerTest.php
@@ -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.