bug #10872 [Form] Fixed TrimListenerTest as of PHP 5.5 (webmozart)

This PR was merged into the 2.3 branch.

Discussion
----------

[Form] Fixed TrimListenerTest as of PHP 5.5

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

b0bc83d [Form] Fixed TrimListenerTest as of PHP 5.5
This commit is contained in:
Fabien Potencier 2014-05-12 11:08:11 +02:00
commit 1a64fef828
1 changed files with 43 additions and 10 deletions

View File

@ -48,32 +48,65 @@ class TrimListenerTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @dataProvider codePointProvider * @dataProvider spaceProvider
*/ */
public function testTrimUtf8($chars) public function testTrimUtf8Separators($hex)
{ {
if (!function_exists('mb_check_encoding')) { if (!function_exists('mb_check_encoding')) {
$this->markTestSkipped('The "mb_check_encoding" function is not available'); $this->markTestSkipped('The "mb_check_encoding" function is not available');
} }
$data = mb_convert_encoding(pack('H*', implode('', $chars)), 'UTF-8', 'UCS-2BE'); // Convert hexadecimal representation into binary
$data = $data."ab\ncd".$data; // 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'); $form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
$event = new FormEvent($form, $data); $event = new FormEvent($form, $symbol);
$filter = new TrimListener(); $filter = new TrimListener();
$filter->preSubmit($event); $filter->preSubmit($event);
$this->assertSame("ab\ncd", $event->getData(), 'TrimListener should trim character(s): '.implode(', ', $chars)); $this->assertSame("ab\ncd", $event->getData());
} }
public function codePointProvider() public function spaceProvider()
{ {
return array( return array(
'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')), // separators
'General category: Other, control' => array(array('0009', '000A', '000B', '000C', '000D', '0085')), array('0020'),
//'General category: Other, format. ZERO WIDTH SPACE' => array(array('200B')), array('00A0'),
array('1680'),
// array('180E'),
array('2000'),
array('2001'),
array('2002'),
array('2003'),
array('2004'),
array('2005'),
array('2006'),
array('2007'),
array('2008'),
array('2009'),
array('200A'),
array('2028'),
array('2029'),
array('202F'),
array('205F'),
array('3000'),
// controls
array('0009'),
array('000A'),
array('000B'),
array('000C'),
array('000D'),
array('0085'),
// zero width space
// array('200B'),
); );
} }
} }