Skip to content

Commit f975ef0

Browse files
committed
bug #25233 [TwigBridge][Form] Fix hidden currency element with Bootstrap 3 theme (julienfalque)
This PR was merged into the 2.7 branch. Discussion ---------- [TwigBridge][Form] Fix hidden currency element with Bootstrap 3 theme | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - When using a `MoneyType` field, one can pass `currency=false` option to hide the currency symbol. This does not work well when using the Bootstrap 3 theme: the symbol is not displayed but HTML elements that are supposed to contain it are still rendered. Commits ------- c5af7fd938 Fix hidden currency element with Bootstrap 3 theme
2 parents 58f29cc + c7f28d6 commit f975ef0

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Tests/AbstractBootstrap3LayoutTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,25 @@ public function testMoney()
18991899
);
19001900
}
19011901

1902+
public function testMoneyWithoutCurrency()
1903+
{
1904+
$form = $this->factory->createNamed('name', 'money', 1234.56, array(
1905+
'currency' => false,
1906+
));
1907+
1908+
$this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')),
1909+
'/input
1910+
[@id="my&id"]
1911+
[@type="text"]
1912+
[@name="name"]
1913+
[@class="my&class form-control"]
1914+
[@value="1234.56"]
1915+
[not(preceding-sibling::*)]
1916+
[not(following-sibling::*)]
1917+
'
1918+
);
1919+
}
1920+
19021921
public function testNumber()
19031922
{
19041923
$form = $this->factory->createNamed('name', 'number', 1234.56);

Tests/Extension/Core/Type/MoneyTypeTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testMoneyPatternWorksForYen()
4343
$view = $this->factory->create(static::TESTED_TYPE, null, array('currency' => 'JPY'))
4444
->createView();
4545

46-
$this->assertTrue((bool) strstr($view->vars['money_pattern'], '¥'));
46+
$this->assertSame('¥ {{ widget }}', $view->vars['money_pattern']);
4747
}
4848

4949
// https://github.com/symfony/symfony/issues/5458
@@ -62,4 +62,12 @@ public function testSubmitNull($expected = null, $norm = null, $view = null)
6262
{
6363
parent::testSubmitNull($expected, $norm, '');
6464
}
65+
66+
public function testMoneyPatternWithoutCurrency()
67+
{
68+
$view = $this->factory->create(static::TESTED_TYPE, null, array('currency' => false))
69+
->createView();
70+
71+
$this->assertSame('{{ widget }}', $view->vars['money_pattern']);
72+
}
6573
}

0 commit comments

Comments
 (0)