public function testTrimSkipNonStrings() { $data = 1234; $form = $this->getMock('Symfony\\Tests\\Component\\Form\\FormInterface'); $event = new FilterDataEvent($form, $data); $filter = new TrimListener(); $filter->onBindClientData($event); $this->assertSame(1234, $event->getData()); }
public function testTrimSkipNonStrings() { $data = 1234; $form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock(); $event = new FormEvent($form, $data); $filter = new TrimListener(); $filter->preSubmit($event); $this->assertSame(1234, $event->getData()); }
/** * @dataProvider codePointProvider */ public function testTrimUtf8($chars) { if (!function_exists('mb_check_encoding')) { $this->markTestSkipped('The "mb_check_encoding" function is not available'); } $data = mb_convert_encoding(pack('H*', implode('', $chars)), 'UTF-8', 'UCS-2BE'); $data = $data . "ab\ncd" . $data; $form = $this->getMock('Symfony\\Component\\Form\\Test\\FormInterface'); $event = new FormEvent($form, $data); $filter = new TrimListener(); $filter->preBind($event); $this->assertSame("ab\ncd", $event->getData(), 'TrimListener should trim character(s): ' . implode(', ', $chars)); }
/** * @dataProvider spaceProvider * @requires extension mbstring */ public function testTrimUtf8Separators($hex) { // Convert hexadecimal representation into binary // H: hex string, high nibble first (UCS-2BE) // *: repeat until end of string $binary = pack('H*', $hex); // Convert UCS-2BE to UTF-8 $symbol = mb_convert_encoding($binary, 'UTF-8', 'UCS-2BE'); $symbol = $symbol . "ab\ncd" . $symbol; $form = $this->getMock('Symfony\\Component\\Form\\Test\\FormInterface'); $event = new FormEvent($form, $symbol); $filter = new TrimListener(); $filter->preSubmit($event); $this->assertSame("ab\ncd", $event->getData()); }