Skip to content

Commit

Permalink
merged branch ManuelKiessling/ticket_3124 (PR #3188)
Browse files Browse the repository at this point in the history
Commits
-------

6090dee [FormType] Adopted MoneyTypeTest::testMoneyPatternWorksForYen to CS
e814d27 [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
  • Loading branch information
fabpot committed Feb 2, 2012
2 parents 47598c6 + 6090dee commit 048fc2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Expand Up @@ -100,7 +100,7 @@ static private function getPattern($currency)

// 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])) {
self::$patterns[\Locale::getDefault()] = $matches[1].' {{ widget }}';
Expand Down
Expand Up @@ -11,7 +11,10 @@

namespace Symfony\Tests\Component\Form\Extension\Core\Type;

use Symfony\Component\Form\FormFactory;

require_once __DIR__ . '/LocalizedTestCase.php';
require_once __DIR__ . '/../../../../../../../../src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php';

class MoneyTypeTest extends LocalizedTestCase
{
Expand All @@ -24,4 +27,13 @@ public function testPassMoneyPatternToView()

$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'), '¥'));
}
}

0 comments on commit 048fc2f

Please sign in to comment.