merged branch ManuelKiessling/ticket_3124 (PR #3188)
Commits -------6090dee
[FormType] Adopted MoneyTypeTest::testMoneyPatternWorksForYen to CSe814d27
[FormType] Fixed broken MoneyType regexp for JPY Discussion ---------- [Bugfix][Form] Fixed broken MoneyType regexp for JPY Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: ![Build Status](https://secure.travis-ci.org/ManuelKiessling/symfony.png?branch=ticket_3124) Fixes the following tickets: #3124 Todo: - The regexp in MoneyType doesn't work if currency format has no decimal (like JPY) and doesn't work either if the currency symbol is unicode This change fixes both issues and adds a unit test
This commit is contained in:
commit
048fc2f6b9
@ -100,7 +100,7 @@ class MoneyType extends AbstractType
|
|||||||
|
|
||||||
// the regex also considers non-break spaces (0xC2 or 0xA0 in UTF-8)
|
// the regex also considers non-break spaces (0xC2 or 0xA0 in UTF-8)
|
||||||
|
|
||||||
preg_match('/^([^\s\xc2\xa0]*)[\s\xc2\xa0]*123[,.]00[\s\xc2\xa0]*([^\s\xc2\xa0]*)$/', $pattern, $matches);
|
preg_match('/^([^\s\xc2\xa0]*)[\s\xc2\xa0]*123(?:[,.]0+)?[\s\xc2\xa0]*([^\s\xc2\xa0]*)$/u', $pattern, $matches);
|
||||||
|
|
||||||
if (!empty($matches[1])) {
|
if (!empty($matches[1])) {
|
||||||
self::$patterns[\Locale::getDefault()] = $matches[1].' {{ widget }}';
|
self::$patterns[\Locale::getDefault()] = $matches[1].' {{ widget }}';
|
||||||
|
@ -11,7 +11,10 @@
|
|||||||
|
|
||||||
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
|
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\FormFactory;
|
||||||
|
|
||||||
require_once __DIR__ . '/LocalizedTestCase.php';
|
require_once __DIR__ . '/LocalizedTestCase.php';
|
||||||
|
require_once __DIR__ . '/../../../../../../../../src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php';
|
||||||
|
|
||||||
class MoneyTypeTest extends LocalizedTestCase
|
class MoneyTypeTest extends LocalizedTestCase
|
||||||
{
|
{
|
||||||
@ -24,4 +27,13 @@ class MoneyTypeTest extends LocalizedTestCase
|
|||||||
|
|
||||||
$this->assertSame('{{ widget }} €', $view->get('money_pattern'));
|
$this->assertSame('{{ widget }} €', $view->get('money_pattern'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMoneyPatternWorksForYen()
|
||||||
|
{
|
||||||
|
\Locale::setDefault('en_US');
|
||||||
|
|
||||||
|
$form = $this->factory->create('money', null, array('currency' => 'JPY'));
|
||||||
|
$view = $form->createView();
|
||||||
|
$this->assertTrue((Boolean) strstr($view->get('money_pattern'), '¥'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user