Skip to content

Commit

Permalink
Dont set the locale implicitly, just use the value provided by \Local…
Browse files Browse the repository at this point in the history
…e::getDefault() if none is set

Add tests

Signed-off-by: Matthias Kühne <[email protected]>
  • Loading branch information
MatthiasKuehneEllerhold committed Dec 19, 2023
1 parent cff848b commit c706c3f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/View/Helper/CurrencyFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function setLocale($locale)
public function getLocale()
{
if ($this->locale === null) {
$this->locale = Locale::getDefault();
return Locale::getDefault();
}

return $this->locale;
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/DateFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function setLocale($locale)
public function getLocale()
{
if ($this->locale === null) {
$this->locale = Locale::getDefault();
return Locale::getDefault();
}

return $this->locale;
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/NumberFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function setLocale($locale)
public function getLocale()
{
if ($this->locale === null) {
$this->locale = Locale::getDefault();
return Locale::getDefault();
}

return $this->locale;
Expand Down
12 changes: 12 additions & 0 deletions test/View/Helper/CurrencyFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,16 @@ public static function assertMbStringEquals(string $expected, string $test, stri
$test = str_replace(["\xC2\xA0", ' '], '', $test);
self::assertEquals($expected, $test, $message);
}

public function testNoImplicitLocale(): void
{
Locale::setDefault('de');
self::assertEquals(Locale::getDefault(), $this->helper->getLocale());

Locale::setDefault('en');
self::assertEquals(Locale::getDefault(), $this->helper->getLocale());

$this->helper->setLocale('es');
self::assertEquals('es', $this->helper->getLocale());
}
}
12 changes: 12 additions & 0 deletions test/View/Helper/DateFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,16 @@ public function testIntlCalendarIsHandledAsWell(): void
$helper->__invoke($calendar, IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'it_IT', 'dd-MM-Y')
);
}

public function testNoImplicitLocale(): void
{
Locale::setDefault('de');
self::assertEquals(Locale::getDefault(), $this->helper->getLocale());

Locale::setDefault('en');
self::assertEquals(Locale::getDefault(), $this->helper->getLocale());

$this->helper->setLocale('es');
self::assertEquals('es', $this->helper->getLocale());
}
}
12 changes: 12 additions & 0 deletions test/View/Helper/NumberFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,16 @@ public static function assertMbStringEquals(string $expected, string $test, stri
$test = str_replace(["\xC2\xA0", ' '], '', $test);
self::assertEquals($expected, $test, $message);
}

public function testNoImplicitLocale(): void
{
Locale::setDefault('de');
self::assertEquals(Locale::getDefault(), $this->helper->getLocale());

Locale::setDefault('en');
self::assertEquals(Locale::getDefault(), $this->helper->getLocale());

$this->helper->setLocale('es');
self::assertEquals('es', $this->helper->getLocale());
}
}

0 comments on commit c706c3f

Please sign in to comment.