4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Tests\Extension\Core\EventListener
;
14 use Symfony\Component\Form\FormEvent
;
15 use Symfony\Component\Form\Extension\Core\EventListener\TrimListener
;
17 class TrimListenerTest
extends \PHPUnit_Framework_TestCase
19 protected function setUp()
21 if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
22 $this->markTestSkipped('The "EventDispatcher" component is not available');
26 public function testTrim()
29 $form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
30 $event = new FormEvent($form, $data);
32 $filter = new TrimListener();
33 $filter->preSubmit($event);
35 $this->assertEquals('Foo!', $event->getData());
38 public function testTrimSkipNonStrings()
41 $form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
42 $event = new FormEvent($form, $data);
44 $filter = new TrimListener();
45 $filter->preSubmit($event);
47 $this->assertSame(1234, $event->getData());
51 * @dataProvider codePointProvider
53 public function testTrimUtf8($chars)
55 if (!function_exists('mb_check_encoding')) {
56 $this->markTestSkipped('The "mb_check_encoding" function is not available');
59 $data = mb_convert_encoding(pack('H*', implode('', $chars)), 'UTF-8', 'UCS-2BE');
60 $data = $data."ab\ncd".$data;
62 $form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
63 $event = new FormEvent($form, $data);
65 $filter = new TrimListener();
66 $filter->preSubmit($event);
68 $this->assertSame("ab\ncd", $event->getData(), 'TrimListener should trim character(s): '.implode(', ', $chars));
71 public function codePointProvider()
74 'General category: Separator' => array(array('0020', '00A0', '1680', '180E', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '200A', '2028', '2029', '202F', '205F', '3000')),
75 'General category: Other, control' => array(array('0009', '000A', '000B', '000C', '000D', '0085')),
76 //'General category: Other, format. ZERO WIDTH SPACE' => array(array('200B')),