diff options
Diffstat (limited to 'vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php')
-rw-r--r-- | vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php new file mode 100644 index 00000000..4e368933 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php | |||
@@ -0,0 +1,79 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Tests\Extension\Core\EventListener; | ||
13 | |||
14 | use Symfony\Component\Form\FormEvent; | ||
15 | use Symfony\Component\Form\Extension\Core\EventListener\TrimListener; | ||
16 | |||
17 | class TrimListenerTest extends \PHPUnit_Framework_TestCase | ||
18 | { | ||
19 | protected function setUp() | ||
20 | { | ||
21 | if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) { | ||
22 | $this->markTestSkipped('The "EventDispatcher" component is not available'); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | public function testTrim() | ||
27 | { | ||
28 | $data = " Foo! "; | ||
29 | $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); | ||
30 | $event = new FormEvent($form, $data); | ||
31 | |||
32 | $filter = new TrimListener(); | ||
33 | $filter->preSubmit($event); | ||
34 | |||
35 | $this->assertEquals('Foo!', $event->getData()); | ||
36 | } | ||
37 | |||
38 | public function testTrimSkipNonStrings() | ||
39 | { | ||
40 | $data = 1234; | ||
41 | $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); | ||
42 | $event = new FormEvent($form, $data); | ||
43 | |||
44 | $filter = new TrimListener(); | ||
45 | $filter->preSubmit($event); | ||
46 | |||
47 | $this->assertSame(1234, $event->getData()); | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * @dataProvider codePointProvider | ||
52 | */ | ||
53 | public function testTrimUtf8($chars) | ||
54 | { | ||
55 | if (!function_exists('mb_check_encoding')) { | ||
56 | $this->markTestSkipped('The "mb_check_encoding" function is not available'); | ||
57 | } | ||
58 | |||
59 | $data = mb_convert_encoding(pack('H*', implode('', $chars)), 'UTF-8', 'UCS-2BE'); | ||
60 | $data = $data."ab\ncd".$data; | ||
61 | |||
62 | $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); | ||
63 | $event = new FormEvent($form, $data); | ||
64 | |||
65 | $filter = new TrimListener(); | ||
66 | $filter->preSubmit($event); | ||
67 | |||
68 | $this->assertSame("ab\ncd", $event->getData(), 'TrimListener should trim character(s): '.implode(', ', $chars)); | ||
69 | } | ||
70 | |||
71 | public function codePointProvider() | ||
72 | { | ||
73 | return array( | ||
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')), | ||
77 | ); | ||
78 | } | ||
79 | } | ||