Commit 9edf938b by Carsten Brandt

Added tests for empty values

use "just now" for empty time difference in Formatter. fixed wrong language name definition
parent be655d4f
...@@ -624,7 +624,9 @@ class Formatter extends Component ...@@ -624,7 +624,9 @@ class Formatter extends Component
if ($interval->i >= 1) { if ($interval->i >= 1) {
return Yii::t('yii', 'in {delta, plural, =1{a minute} other{# minutes}}', ['delta' => $interval->i], $this->locale); return Yii::t('yii', 'in {delta, plural, =1{a minute} other{# minutes}}', ['delta' => $interval->i], $this->locale);
} }
if ($interval->s == 0) {
return Yii::t('yii', 'just now', [], $this->locale);
}
return Yii::t('yii', 'in {delta, plural, =1{a second} other{# seconds}}', ['delta' => $interval->s], $this->locale); return Yii::t('yii', 'in {delta, plural, =1{a second} other{# seconds}}', ['delta' => $interval->s], $this->locale);
} else { } else {
if ($interval->y >= 1) { if ($interval->y >= 1) {
...@@ -642,7 +644,9 @@ class Formatter extends Component ...@@ -642,7 +644,9 @@ class Formatter extends Component
if ($interval->i >= 1) { if ($interval->i >= 1) {
return Yii::t('yii', '{delta, plural, =1{a minute} other{# minutes}} ago', ['delta' => $interval->i], $this->locale); return Yii::t('yii', '{delta, plural, =1{a minute} other{# minutes}} ago', ['delta' => $interval->i], $this->locale);
} }
if ($interval->s == 0) {
return Yii::t('yii', 'just now', [], $this->locale);
}
return Yii::t('yii', '{delta, plural, =1{a second} other{# seconds}} ago', ['delta' => $interval->s], $this->locale); return Yii::t('yii', '{delta, plural, =1{a second} other{# seconds}} ago', ['delta' => $interval->s], $this->locale);
} }
} }
......
...@@ -7,7 +7,7 @@ return [ ...@@ -7,7 +7,7 @@ return [
'messagePath' => __DIR__, 'messagePath' => __DIR__,
// array, required, list of language codes that the extracted messages // array, required, list of language codes that the extracted messages
// should be translated to. For example, ['zh-CN', 'de']. // should be translated to. For example, ['zh-CN', 'de'].
'languages' => ['ar', 'bg', 'ca', 'da', 'de', 'el', 'es', 'et', 'fa-IR', 'fi', 'fr', 'hu', 'id', 'it', 'ja', 'kk', 'ko', 'lt', 'lv', 'nl', 'pl', 'pt-BR', 'pt-PT', 'ro', 'ru', 'sk', 'sr', 'sr-Latn', 'th', 'uk', 'vi', 'zh-CN','zh-TW'], 'languages' => ['ar', 'bg', 'ca', 'da', 'de', 'el', 'es', 'et', 'fa-IR', 'fi', 'fr', 'hu', 'id', 'it', 'ja', 'kk', 'ko', 'lt', 'lv', 'nl', 'pl', 'pt', 'pt-BR', 'ro', 'ru', 'sk', 'sr', 'sr-Latn', 'th', 'uk', 'vi', 'zh-CN','zh-TW'],
// string, the name of the function for translating messages. // string, the name of the function for translating messages.
// Defaults to 'Yii::t'. This is used as a mark to find the messages to be // Defaults to 'Yii::t'. This is used as a mark to find the messages to be
// translated. You may use a string for single function name or an array for // translated. You may use a string for single function name or an array for
......
...@@ -17,41 +17,7 @@ ...@@ -17,41 +17,7 @@
* NOTE: this file must be saved in UTF-8 encoding. * NOTE: this file must be saved in UTF-8 encoding.
*/ */
return [ return [
'The requested view "{name}" was not found.' => 'Die View-Datei "{name}" konnte nicht gefunden werden.', 'just now' => 'gerade jetzt',
'in {delta, plural, =1{a day} other{# days}}' => 'in {delta, plural, =1{einem Tag} other{# Tagen}}',
'in {delta, plural, =1{a minute} other{# minutes}}' => 'in {delta, plural, =1{einer Minute} other{# Minuten}}',
'in {delta, plural, =1{a month} other{# months}}' => 'in {delta, plural, =1{einem Monat} other{# Monaten}}',
'in {delta, plural, =1{a second} other{# seconds}}' => 'in {delta, plural, =1{einer Sekunde} other{# Sekunden}}',
'in {delta, plural, =1{a year} other{# years}}' => 'in {delta, plural, =1{einem Jahr} other{# Jahren}}',
'in {delta, plural, =1{an hour} other{# hours}}' => 'in {delta, plural, =1{einer Stunde} other{# Stunden}}',
'{delta, plural, =1{a day} other{# days}} ago' => 'vor {delta, plural, =1{einem Tag} other{# Tagen}}',
'{delta, plural, =1{a minute} other{# minutes}} ago' => 'vor {delta, plural, =1{einer Minute} other{# Minuten}}',
'{delta, plural, =1{a month} other{# months}} ago' => 'vor {delta, plural, =1{einem Monat} other{# Monaten}}',
'{delta, plural, =1{a second} other{# seconds}} ago' => 'vor {delta, plural, =1{einer Sekunde} other{# Sekunden}}',
'{delta, plural, =1{a year} other{# years}} ago' => 'vor {delta, plural, =1{einem Jahr} other{# Jahren}}',
'{delta, plural, =1{an hour} other{# hours}} ago' => 'vor {delta, plural, =1{einer Stunde} other{# Stunden}}',
'{nFormatted} B' => '{nFormatted} B',
'{nFormatted} GB' => '{nFormatted} GB',
'{nFormatted} GiB' => '{nFormatted} GiB',
'{nFormatted} KB' => '{nFormatted} KB',
'{nFormatted} KiB' => '{nFormatted} KiB',
'{nFormatted} MB' => '{nFormatted} MB',
'{nFormatted} MiB' => '{nFormatted} MiB',
'{nFormatted} PB' => '{nFormatted} PB',
'{nFormatted} PiB' => '{nFormatted} PiB',
'{nFormatted} TB' => '{nFormatted} TB',
'{nFormatted} TiB' => '{nFormatted} TiB',
'{nFormatted} {n, plural, =1{byte} other{bytes}}' => '{nFormatted} Byte',
'{nFormatted} {n, plural, =1{gibibyte} other{gibibytes}}' => '{nFormatted} GibiByte',
'{nFormatted} {n, plural, =1{gigabyte} other{gigabytes}}' => '{nFormatted} Gigabyte',
'{nFormatted} {n, plural, =1{kibibyte} other{kibibytes}}' => '{nFormatted} KibiByte',
'{nFormatted} {n, plural, =1{kilobyte} other{kilobytes}}' => '{nFormatted} Kilobyte',
'{nFormatted} {n, plural, =1{mebibyte} other{mebibytes}}' => '{nFormatted} MebiByte',
'{nFormatted} {n, plural, =1{megabyte} other{megabytes}}' => '{nFormatted} Megabyte',
'{nFormatted} {n, plural, =1{pebibyte} other{pebibytes}}' => '{nFormatted} PebiByte',
'{nFormatted} {n, plural, =1{petabyte} other{petabytes}}' => '{nFormatted} Petabyte',
'{nFormatted} {n, plural, =1{tebibyte} other{tebibytes}}' => '{nFormatted} TebiByte',
'{nFormatted} {n, plural, =1{terabyte} other{terabytes}}' => '{nFormatted} Terabyte',
'(not set)' => '(nicht gesetzt)', '(not set)' => '(nicht gesetzt)',
'An internal server error occurred.' => 'Es ist ein interner Serverfehler aufgetreten.', 'An internal server error occurred.' => 'Es ist ein interner Serverfehler aufgetreten.',
'Are you sure you want to delete this item?' => 'Wollen Sie diesen Eintrag wirklich löschen?', 'Are you sure you want to delete this item?' => 'Wollen Sie diesen Eintrag wirklich löschen?',
...@@ -81,6 +47,7 @@ return [ ...@@ -81,6 +47,7 @@ return [
'The image "{file}" is too large. The width cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.' => 'Das Bild "{file}" ist zu groß. Es darf maximal {limit, number} Pixel breit sein.', 'The image "{file}" is too large. The width cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.' => 'Das Bild "{file}" ist zu groß. Es darf maximal {limit, number} Pixel breit sein.',
'The image "{file}" is too small. The height cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.' => 'Das Bild "{file}" ist zu klein. Es muss mindestens {limit, number} Pixel hoch sein.', 'The image "{file}" is too small. The height cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.' => 'Das Bild "{file}" ist zu klein. Es muss mindestens {limit, number} Pixel hoch sein.',
'The image "{file}" is too small. The width cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.' => 'Das Bild "{file}" ist zu klein. Es muss mindestens {limit, number} Pixel breit sein.', 'The image "{file}" is too small. The width cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.' => 'Das Bild "{file}" ist zu klein. Es muss mindestens {limit, number} Pixel breit sein.',
'The requested view "{name}" was not found.' => 'Die View-Datei "{name}" konnte nicht gefunden werden.',
'The verification code is incorrect.' => 'Der Prüfcode ist falsch.', 'The verification code is incorrect.' => 'Der Prüfcode ist falsch.',
'Total <b>{count, number}</b> {count, plural, one{item} other{items}}.' => 'Insgesamt <b>{count, number}</b> {count, plural, one{Eintrag} other{Einträge}}.', 'Total <b>{count, number}</b> {count, plural, one{item} other{items}}.' => 'Insgesamt <b>{count, number}</b> {count, plural, one{Eintrag} other{Einträge}}.',
'Unable to verify your data submission.' => 'Es ist nicht möglich, Ihre Dateneingabe zu prüfen.', 'Unable to verify your data submission.' => 'Es ist nicht möglich, Ihre Dateneingabe zu prüfen.',
...@@ -91,6 +58,12 @@ return [ ...@@ -91,6 +58,12 @@ return [
'Yes' => 'Ja', 'Yes' => 'Ja',
'You are not allowed to perform this action.' => 'Sie dürfen diese Aktion nicht durchführen.', 'You are not allowed to perform this action.' => 'Sie dürfen diese Aktion nicht durchführen.',
'You can upload at most {limit, number} {limit, plural, one{file} other{files}}.' => 'Sie können maximal {limit, number} {limit, plural, one{eine Datei} other{# Dateien}} hochladen.', 'You can upload at most {limit, number} {limit, plural, one{file} other{files}}.' => 'Sie können maximal {limit, number} {limit, plural, one{eine Datei} other{# Dateien}} hochladen.',
'in {delta, plural, =1{a day} other{# days}}' => 'in {delta, plural, =1{einem Tag} other{# Tagen}}',
'in {delta, plural, =1{a minute} other{# minutes}}' => 'in {delta, plural, =1{einer Minute} other{# Minuten}}',
'in {delta, plural, =1{a month} other{# months}}' => 'in {delta, plural, =1{einem Monat} other{# Monaten}}',
'in {delta, plural, =1{a second} other{# seconds}}' => 'in {delta, plural, =1{einer Sekunde} other{# Sekunden}}',
'in {delta, plural, =1{a year} other{# years}}' => 'in {delta, plural, =1{einem Jahr} other{# Jahren}}',
'in {delta, plural, =1{an hour} other{# hours}}' => 'in {delta, plural, =1{einer Stunde} other{# Stunden}}',
'the input value' => 'der eingegebene Wert', 'the input value' => 'der eingegebene Wert',
'{attribute} "{value}" has already been taken.' => '{attribute} "{value}" wird bereits verwendet.', '{attribute} "{value}" has already been taken.' => '{attribute} "{value}" wird bereits verwendet.',
'{attribute} cannot be blank.' => '{attribute} darf nicht leer sein.', '{attribute} cannot be blank.' => '{attribute} darf nicht leer sein.',
...@@ -113,4 +86,32 @@ return [ ...@@ -113,4 +86,32 @@ return [
'{attribute} should contain at least {min, number} {min, plural, one{character} other{characters}}.' => '{attribute} muss mindestens {min, number} Zeichen enthalten.', '{attribute} should contain at least {min, number} {min, plural, one{character} other{characters}}.' => '{attribute} muss mindestens {min, number} Zeichen enthalten.',
'{attribute} should contain at most {max, number} {max, plural, one{character} other{characters}}.' => '{attribute} darf maximal {max, number} Zeichen enthalten.', '{attribute} should contain at most {max, number} {max, plural, one{character} other{characters}}.' => '{attribute} darf maximal {max, number} Zeichen enthalten.',
'{attribute} should contain {length, number} {length, plural, one{character} other{characters}}.' => '{attribute} muss aus genau {length, number} Zeichen bestehen.', '{attribute} should contain {length, number} {length, plural, one{character} other{characters}}.' => '{attribute} muss aus genau {length, number} Zeichen bestehen.',
'{delta, plural, =1{a day} other{# days}} ago' => 'vor {delta, plural, =1{einem Tag} other{# Tagen}}',
'{delta, plural, =1{a minute} other{# minutes}} ago' => 'vor {delta, plural, =1{einer Minute} other{# Minuten}}',
'{delta, plural, =1{a month} other{# months}} ago' => 'vor {delta, plural, =1{einem Monat} other{# Monaten}}',
'{delta, plural, =1{a second} other{# seconds}} ago' => 'vor {delta, plural, =1{einer Sekunde} other{# Sekunden}}',
'{delta, plural, =1{a year} other{# years}} ago' => 'vor {delta, plural, =1{einem Jahr} other{# Jahren}}',
'{delta, plural, =1{an hour} other{# hours}} ago' => 'vor {delta, plural, =1{einer Stunde} other{# Stunden}}',
'{nFormatted} B' => '{nFormatted} B',
'{nFormatted} GB' => '{nFormatted} GB',
'{nFormatted} GiB' => '{nFormatted} GiB',
'{nFormatted} KB' => '{nFormatted} KB',
'{nFormatted} KiB' => '{nFormatted} KiB',
'{nFormatted} MB' => '{nFormatted} MB',
'{nFormatted} MiB' => '{nFormatted} MiB',
'{nFormatted} PB' => '{nFormatted} PB',
'{nFormatted} PiB' => '{nFormatted} PiB',
'{nFormatted} TB' => '{nFormatted} TB',
'{nFormatted} TiB' => '{nFormatted} TiB',
'{nFormatted} {n, plural, =1{byte} other{bytes}}' => '{nFormatted} Byte',
'{nFormatted} {n, plural, =1{gibibyte} other{gibibytes}}' => '{nFormatted} GibiByte',
'{nFormatted} {n, plural, =1{gigabyte} other{gigabytes}}' => '{nFormatted} Gigabyte',
'{nFormatted} {n, plural, =1{kibibyte} other{kibibytes}}' => '{nFormatted} KibiByte',
'{nFormatted} {n, plural, =1{kilobyte} other{kilobytes}}' => '{nFormatted} Kilobyte',
'{nFormatted} {n, plural, =1{mebibyte} other{mebibytes}}' => '{nFormatted} MebiByte',
'{nFormatted} {n, plural, =1{megabyte} other{megabytes}}' => '{nFormatted} Megabyte',
'{nFormatted} {n, plural, =1{pebibyte} other{pebibytes}}' => '{nFormatted} PebiByte',
'{nFormatted} {n, plural, =1{petabyte} other{petabytes}}' => '{nFormatted} Petabyte',
'{nFormatted} {n, plural, =1{tebibyte} other{tebibytes}}' => '{nFormatted} TebiByte',
'{nFormatted} {n, plural, =1{terabyte} other{terabytes}}' => '{nFormatted} Terabyte',
]; ];
...@@ -18,8 +18,8 @@ namespace yiiunit\framework\helpers { ...@@ -18,8 +18,8 @@ namespace yiiunit\framework\helpers {
use Yii; use Yii;
use yii\helpers\FormatConverter; use yii\helpers\FormatConverter;
use yii\i18n\Formatter; use yii\i18n\Formatter;
use yiiunit\framework\i18n\FormatterTest; use yiiunit\framework\i18n\FormatterTest;
use yiiunit\TestCase; use yiiunit\TestCase;
/** /**
...@@ -57,7 +57,7 @@ class FormatConverterTest extends TestCase ...@@ -57,7 +57,7 @@ class FormatConverterTest extends TestCase
public function testIntlIcuToPhpShortForm() public function testIntlIcuToPhpShortForm()
{ {
$this->assertEquals('m/j/y', FormatConverter::convertDateIcuToPhp('short', 'date', 'en-US')); $this->assertEquals('n/j/y', FormatConverter::convertDateIcuToPhp('short', 'date', 'en-US'));
$this->assertEquals('d.m.y', FormatConverter::convertDateIcuToPhp('short', 'date', 'de-DE')); $this->assertEquals('d.m.y', FormatConverter::convertDateIcuToPhp('short', 'date', 'de-DE'));
} }
......
...@@ -212,14 +212,11 @@ class FormatterTest extends TestCase ...@@ -212,14 +212,11 @@ class FormatterTest extends TestCase
public function testAsBoolean() public function testAsBoolean()
{ {
$value = true; $this->assertSame('Yes', $this->formatter->asBoolean(true));
$this->assertSame('Yes', $this->formatter->asBoolean($value)); $this->assertSame('No', $this->formatter->asBoolean(false));
$value = false; $this->assertSame('Yes', $this->formatter->asBoolean("111"));
$this->assertSame('No', $this->formatter->asBoolean($value)); $this->assertSame('No', $this->formatter->asBoolean(""));
$value = "111"; $this->assertSame('No', $this->formatter->asBoolean(0));
$this->assertSame('Yes', $this->formatter->asBoolean($value));
$value = "";
$this->assertSame('No', $this->formatter->asBoolean($value));
// null display // null display
$this->assertSame($this->formatter->nullDisplay, $this->formatter->asBoolean(null)); $this->assertSame($this->formatter->nullDisplay, $this->formatter->asBoolean(null));
...@@ -243,6 +240,10 @@ class FormatterTest extends TestCase ...@@ -243,6 +240,10 @@ class FormatterTest extends TestCase
$this->assertSame(date('n/j/y', $value), $this->formatter->asDate($value, 'short')); $this->assertSame(date('n/j/y', $value), $this->formatter->asDate($value, 'short'));
$this->assertSame(date('F j, Y', $value), $this->formatter->asDate($value, 'long')); $this->assertSame(date('F j, Y', $value), $this->formatter->asDate($value, 'long'));
// empty input
$this->assertSame('Jan 1, 1970', $this->formatter->asDate(''));
$this->assertSame('Jan 1, 1970', $this->formatter->asDate(0));
$this->assertSame('Jan 1, 1970', $this->formatter->asDate(false));
// null display // null display
$this->assertSame($this->formatter->nullDisplay, $this->formatter->asDate(null)); $this->assertSame($this->formatter->nullDisplay, $this->formatter->asDate(null));
} }
...@@ -250,6 +251,12 @@ class FormatterTest extends TestCase ...@@ -250,6 +251,12 @@ class FormatterTest extends TestCase
public function testIntlAsTime() public function testIntlAsTime()
{ {
$this->testAsTime(); $this->testAsTime();
// empty input
$this->formatter->locale = 'de-DE';
$this->assertSame('00:00:00', $this->formatter->asTime(''));
$this->assertSame('00:00:00', $this->formatter->asTime(0));
$this->assertSame('00:00:00', $this->formatter->asTime(false));
} }
public function testAsTime() public function testAsTime()
...@@ -258,6 +265,10 @@ class FormatterTest extends TestCase ...@@ -258,6 +265,10 @@ class FormatterTest extends TestCase
$this->assertSame(date('g:i:s A', $value), $this->formatter->asTime($value)); $this->assertSame(date('g:i:s A', $value), $this->formatter->asTime($value));
$this->assertSame(date('h:i:s A', $value), $this->formatter->asTime($value, 'php:h:i:s A')); $this->assertSame(date('h:i:s A', $value), $this->formatter->asTime($value, 'php:h:i:s A'));
// empty input
$this->assertSame('12:00:00 AM', $this->formatter->asTime(''));
$this->assertSame('12:00:00 AM', $this->formatter->asTime(0));
$this->assertSame('12:00:00 AM', $this->formatter->asTime(false));
// null display // null display
$this->assertSame($this->formatter->nullDisplay, $this->formatter->asTime(null)); $this->assertSame($this->formatter->nullDisplay, $this->formatter->asTime(null));
} }
...@@ -265,6 +276,12 @@ class FormatterTest extends TestCase ...@@ -265,6 +276,12 @@ class FormatterTest extends TestCase
public function testIntlAsDatetime() public function testIntlAsDatetime()
{ {
$this->testAsDatetime(); $this->testAsDatetime();
// empty input
$this->formatter->locale = 'de-DE';
$this->assertSame('01.01.1970 00:00:00', $this->formatter->asDatetime(''));
$this->assertSame('01.01.1970 00:00:00', $this->formatter->asDatetime(0));
$this->assertSame('01.01.1970 00:00:00', $this->formatter->asDatetime(false));
} }
public function testAsDatetime() public function testAsDatetime()
...@@ -273,6 +290,10 @@ class FormatterTest extends TestCase ...@@ -273,6 +290,10 @@ class FormatterTest extends TestCase
$this->assertSame(date('M j, Y g:i:s A', $value), $this->formatter->asDatetime($value)); $this->assertSame(date('M j, Y g:i:s A', $value), $this->formatter->asDatetime($value));
$this->assertSame(date('Y/m/d h:i:s A', $value), $this->formatter->asDatetime($value, 'php:Y/m/d h:i:s A')); $this->assertSame(date('Y/m/d h:i:s A', $value), $this->formatter->asDatetime($value, 'php:Y/m/d h:i:s A'));
// empty input
$this->assertSame('Jan 1, 1970 12:00:00 AM', $this->formatter->asDatetime(''));
$this->assertSame('Jan 1, 1970 12:00:00 AM', $this->formatter->asDatetime(0));
$this->assertSame('Jan 1, 1970 12:00:00 AM', $this->formatter->asDatetime(false));
// null display // null display
$this->assertSame($this->formatter->nullDisplay, $this->formatter->asDatetime(null)); $this->assertSame($this->formatter->nullDisplay, $this->formatter->asDatetime(null));
} }
...@@ -285,13 +306,15 @@ class FormatterTest extends TestCase ...@@ -285,13 +306,15 @@ class FormatterTest extends TestCase
$this->assertSame("$value", $this->formatter->asTimestamp(date('Y-m-d H:i:s', $value))); $this->assertSame("$value", $this->formatter->asTimestamp(date('Y-m-d H:i:s', $value)));
// empty input
$this->assertSame("0", $this->formatter->asTimestamp(0));
$this->assertSame("0", $this->formatter->asTimestamp(false));
$this->assertSame("0", $this->formatter->asTimestamp(""));
// null display // null display
$this->assertSame($this->formatter->nullDisplay, $this->formatter->asTimestamp(null)); $this->assertSame($this->formatter->nullDisplay, $this->formatter->asTimestamp(null));
} }
// TODO test format conversion ICU/PHP
/** /**
* Test for dates before 1970 * Test for dates before 1970
* https://github.com/yiisoft/yii2/issues/3126 * https://github.com/yiisoft/yii2/issues/3126
...@@ -435,6 +458,14 @@ class FormatterTest extends TestCase ...@@ -435,6 +458,14 @@ class FormatterTest extends TestCase
$this->assertSame('in a month', $this->formatter->asRelativeTime($this->buildDateSubIntervals('2014-03-03', [$interval_1_month]), $dateNow)); $this->assertSame('in a month', $this->formatter->asRelativeTime($this->buildDateSubIntervals('2014-03-03', [$interval_1_month]), $dateNow));
$this->assertSame('in 28 days', $this->formatter->asRelativeTime($dateThen, $dateNow)); $this->assertSame('in 28 days', $this->formatter->asRelativeTime($dateThen, $dateNow));
// just now
$this->assertSame("just now", $this->formatter->asRelativeTime($t = time(), $t));
$this->assertSame("just now", $this->formatter->asRelativeTime(0, 0));
// empty input
$this->assertSame("just now", $this->formatter->asRelativeTime(false, 0));
$this->assertSame("just now", $this->formatter->asRelativeTime("", 0));
// null display // null display
$this->assertSame($this->formatter->nullDisplay, $this->formatter->asRelativeTime(null)); $this->assertSame($this->formatter->nullDisplay, $this->formatter->asRelativeTime(null));
$this->assertSame($this->formatter->nullDisplay, $this->formatter->asRelativeTime(null, time())); $this->assertSame($this->formatter->nullDisplay, $this->formatter->asRelativeTime(null, time()));
...@@ -470,7 +501,7 @@ class FormatterTest extends TestCase ...@@ -470,7 +501,7 @@ class FormatterTest extends TestCase
*/ */
public function testAsIntegerException() public function testAsIntegerException()
{ {
$this->assertSame("0", $this->formatter->asInteger('a')); $this->formatter->asInteger('a');
} }
/** /**
...@@ -478,7 +509,23 @@ class FormatterTest extends TestCase ...@@ -478,7 +509,23 @@ class FormatterTest extends TestCase
*/ */
public function testAsIntegerException2() public function testAsIntegerException2()
{ {
$this->assertSame("0", $this->formatter->asInteger('-123abc')); $this->formatter->asInteger('-123abc');
}
/**
* @expectedException \yii\base\InvalidParamException
*/
public function testAsIntegerException3()
{
$this->formatter->asInteger('');
}
/**
* @expectedException \yii\base\InvalidParamException
*/
public function testAsIntegerException4()
{
$this->formatter->asInteger(false);
} }
public function testIntlAsDecimal() public function testIntlAsDecimal()
...@@ -706,6 +753,9 @@ class FormatterTest extends TestCase ...@@ -706,6 +753,9 @@ class FormatterTest extends TestCase
$this->formatter->numberFormatterOptions = []; $this->formatter->numberFormatterOptions = [];
$this->assertSame("1,001 KiB", $this->formatter->asShortSize(1025, 3)); $this->assertSame("1,001 KiB", $this->formatter->asShortSize(1025, 3));
// empty values
$this->assertSame('0 B', $this->formatter->asShortSize(0));
// null display // null display
$this->assertSame($this->formatter->nullDisplay, $this->formatter->asSize(null)); $this->assertSame($this->formatter->nullDisplay, $this->formatter->asSize(null));
} }
...@@ -733,6 +783,9 @@ class FormatterTest extends TestCase ...@@ -733,6 +783,9 @@ class FormatterTest extends TestCase
$this->formatter->decimalSeparator = ','; $this->formatter->decimalSeparator = ',';
$this->assertSame("1,001 KiB", $this->formatter->asShortSize(1025, 3)); $this->assertSame("1,001 KiB", $this->formatter->asShortSize(1025, 3));
// empty values
$this->assertSame('0 bytes', $this->formatter->asSize(0));
// null display // null display
$this->assertSame($this->formatter->nullDisplay, $this->formatter->asSize(null)); $this->assertSame($this->formatter->nullDisplay, $this->formatter->asSize(null));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment