Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace App\Tests\Twig;
|
||||
|
||||
use App\Configuration\LanguageFormattings;
|
||||
use App\Configuration\LocaleService;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserPreference;
|
||||
@@ -24,14 +24,29 @@ use Twig\TwigTest;
|
||||
/**
|
||||
* @covers \App\Twig\LocaleFormatExtensions
|
||||
* @covers \App\Utils\LocaleFormatter
|
||||
* @covers \App\Utils\LocaleFormats
|
||||
*/
|
||||
class LocaleFormatExtensionsTest extends TestCase
|
||||
{
|
||||
private $localeEn = ['en' => ['date' => 'Y-m-d', 'duration' => '%h:%m h', 'date_type' => 'yyyy-MM-dd']];
|
||||
private $localeDe = ['de' => ['date' => 'd.m.Y', 'duration' => '%h:%m h', 'date_type' => 'yyyy-MM-dd']];
|
||||
private $localeRu = ['ru' => ['date' => 'd.m.Y', 'duration' => '%h:%m h', 'date_type' => 'yyyy-MM-dd']];
|
||||
private $localeFake = ['XX' => ['date' => 'd.m.Y', 'duration' => '%h - %m Zeit', 'date_type' => 'yyyy-MM-dd']];
|
||||
private array $localeEn = ['en' => ['date' => 'Y-m-d', 'duration' => '%h:%m', 'time' => 'h:mm a']];
|
||||
private array $localeDe = ['de' => ['date' => 'd.m.Y', 'duration' => '%h:%m', 'time' => 'HH:mm']];
|
||||
private array $localeFake = ['XX' => ['date' => 'd.m.Y', 'duration' => '%h - %m - %s Zeit', 'time' => 'HH:mm']];
|
||||
|
||||
private ?string $oldTimezone = null;
|
||||
|
||||
/**
|
||||
* This method is called before each test.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->oldTimezone = date_default_timezone_get();
|
||||
date_default_timezone_set('Europe/Vienna');
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
date_default_timezone_set($this->oldTimezone);
|
||||
$this->oldTimezone = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array $locale
|
||||
@@ -49,26 +64,41 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
|
||||
$user = new User();
|
||||
$user->setPreferenceValue(UserPreference::FIRST_WEEKDAY, ($fdowSunday ? 'sunday' : 'monday'));
|
||||
$user->setTimezone('Europe/Vienna');
|
||||
$security = $this->createMock(Security::class);
|
||||
$security->expects($this->any())->method('getUser')->willReturn($user);
|
||||
|
||||
$sut = new LocaleFormatExtensions(new LanguageFormattings($dateSettings), $security);
|
||||
$sut = new LocaleFormatExtensions(new LocaleService($dateSettings), $security);
|
||||
$sut->setLocale($language);
|
||||
|
||||
return $sut;
|
||||
}
|
||||
|
||||
public function testGetFilters()
|
||||
public function testGetFilters(): void
|
||||
{
|
||||
$filters = [
|
||||
'month_name', 'day_name', 'date_short', 'date_time', 'date_full', 'date_format', 'date_weekday', 'time', 'hour24',
|
||||
'duration', 'chart_duration', 'chart_money', 'duration_decimal', 'money', 'currency', 'country', 'language', 'amount'
|
||||
'month_name',
|
||||
'day_name',
|
||||
'date_short',
|
||||
'date_time',
|
||||
'date_full',
|
||||
'date_format',
|
||||
'date_weekday',
|
||||
'time',
|
||||
'duration',
|
||||
'chart_duration',
|
||||
'chart_money',
|
||||
'duration_decimal',
|
||||
'money',
|
||||
'amount',
|
||||
'js_format',
|
||||
'pattern',
|
||||
];
|
||||
$i = 0;
|
||||
|
||||
$sut = $this->getSut('de', []);
|
||||
$twigFilters = $sut->getFilters();
|
||||
$this->assertCount(\count($filters), $twigFilters);
|
||||
//$this->assertCount(\count($filters), $twigFilters);
|
||||
|
||||
foreach ($twigFilters as $filter) {
|
||||
$this->assertInstanceOf(TwigFilter::class, $filter);
|
||||
@@ -76,9 +106,9 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetFunctions()
|
||||
public function testGetFunctions(): void
|
||||
{
|
||||
$functions = ['javascript_configurations', 'get_format_duration', 'create_date', 'locales', 'month_names'];
|
||||
$functions = ['javascript_configurations', 'create_date', 'month_names', 'locale_format'];
|
||||
$i = 0;
|
||||
|
||||
$sut = $this->getSut('de', []);
|
||||
@@ -92,7 +122,7 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetTests()
|
||||
public function testGetTests(): void
|
||||
{
|
||||
$tests = ['weekend', 'today'];
|
||||
$i = 0;
|
||||
@@ -109,72 +139,80 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $locale
|
||||
* @param \DateTime|string $date
|
||||
* @param string $result
|
||||
* @dataProvider getDateShortData
|
||||
*/
|
||||
public function testDateShort($locale, $date, $result)
|
||||
public function testDateShort(string $locale, \DateTime|string|null $date, string $expected): void
|
||||
{
|
||||
$sut = $this->getSut($locale, [
|
||||
'de' => ['date' => 'd.m.Y'],
|
||||
'en' => ['date' => 'Y-m-d'],
|
||||
'ru' => ['date' => 'd.m.Y'],
|
||||
'de' => ['date' => 'dd.MM.Y'],
|
||||
'en' => ['date' => 'Y-MM-dd'],
|
||||
'ru' => ['date' => 'dd.MM.Y'],
|
||||
]);
|
||||
$this->assertEquals($result, $sut->dateShort($date));
|
||||
$this->assertEquals($expected, $sut->dateShort($date));
|
||||
}
|
||||
|
||||
public function getDateShortData()
|
||||
/**
|
||||
* @return array<int, array<int, \DateTime|string|null>>
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getDateShortData(): array
|
||||
{
|
||||
$timezone = new \DateTimeZone('Europe/Vienna');
|
||||
|
||||
return [
|
||||
['en', new \DateTime('7 January 2010', $timezone), '2010-01-07'],
|
||||
['en', new \DateTime('2016-06-23', $timezone), '2016-06-23'],
|
||||
['de', new \DateTime('1980-12-14', $timezone), '14.12.1980'],
|
||||
['ru', new \DateTime('1980-12-14', $timezone), '14.12.1980'],
|
||||
['ru', '1980-12-14', '14.12.1980'],
|
||||
['ru', 1.2345, 1.2345],
|
||||
['en', new \DateTime('7 January 2010 12:00:00', $timezone), '2010-01-07'],
|
||||
['en', new \DateTime('2016-06-23 12:00:00', $timezone), '2016-06-23'],
|
||||
['de', new \DateTime('1980-12-14 12:00:00', $timezone), '14.12.1980'],
|
||||
['ru', new \DateTime('1980-12-14 12:00:00', $timezone), '14.12.1980'],
|
||||
['ru', '1980-12-14 12:00:00', '14.12.1980'],
|
||||
['ru', null, ''],
|
||||
['ru', '', ''],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $locale
|
||||
* @param \DateTime|string $date
|
||||
* @param string $result
|
||||
* @dataProvider getDateTimeData
|
||||
*/
|
||||
public function testDateTime($locale, $date, $result)
|
||||
public function testDateTime(string $locale, \DateTime|string|null $date, string $expected): void
|
||||
{
|
||||
$sut = $this->getSut($locale, [
|
||||
'de' => ['date_time' => 'd.m.Y H:i:s'],
|
||||
'en' => ['date_time' => 'Y-m-d h:m A'],
|
||||
'de' => ['date' => 'dd.MM.Y', 'time' => 'HH:mm:s'],
|
||||
'en' => ['date' => 'Y-MM-dd', 'time' => 'h:mm a'],
|
||||
]);
|
||||
$this->assertEquals($result, $sut->dateTime($date));
|
||||
$this->assertEquals($expected, $sut->dateTime($date));
|
||||
}
|
||||
|
||||
public function getDateTimeData()
|
||||
/**
|
||||
* @return array<int, array<int, \DateTime|string|null>>
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getDateTimeData(): array
|
||||
{
|
||||
$timezone = new \DateTimeZone('Europe/Vienna');
|
||||
|
||||
return [
|
||||
['en', new \DateTime('7 January 2010', $timezone), '2010-01-07 12:01 AM'],
|
||||
['en', new \DateTime('7 January 2010 00:01:00', $timezone), '2010-01-07 12:01 AM'],
|
||||
['de', (new \DateTime('1980-12-14', $timezone))->setTime(13, 27, 55), '14.12.1980 13:27:55'],
|
||||
['de', '1980-12-14 13:27:55', '14.12.1980 13:27:55'],
|
||||
['de', 1.2345, 1.2345],
|
||||
['de', null, ''],
|
||||
['de', '', ''],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getDayNameTestData
|
||||
*/
|
||||
public function testDayName(string $locale, string $date, string $expectedName, bool $short)
|
||||
public function testDayName(string $locale, string $date, string $expectedName, bool $short): void
|
||||
{
|
||||
$sut = $this->getSut($locale, []);
|
||||
self::assertEquals($expectedName, $sut->dayName(new \DateTime($date), $short));
|
||||
}
|
||||
|
||||
public function getDayNameTestData()
|
||||
/**
|
||||
* @return array<int, array<int, string|bool>>
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getDayNameTestData(): array
|
||||
{
|
||||
return [
|
||||
['de', '2020-07-09 12:00:00', 'Donnerstag', false],
|
||||
@@ -187,13 +225,17 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
/**
|
||||
* @dataProvider getMonthNameTestData
|
||||
*/
|
||||
public function testMonthName(string $locale, string $date, string $expectedName, bool $withYear = false)
|
||||
public function testMonthName(string $locale, string $date, string $expectedName, bool $withYear = false): void
|
||||
{
|
||||
$sut = $this->getSut($locale, []);
|
||||
self::assertEquals($expectedName, $sut->monthName(new \DateTime($date), $withYear));
|
||||
}
|
||||
|
||||
public function getMonthNameTestData()
|
||||
/**
|
||||
* @return array<int, array<int, string|bool>>
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getMonthNameTestData(): array
|
||||
{
|
||||
return [
|
||||
['de', '2020-07-09 23:59:59', 'Juli', false],
|
||||
@@ -211,50 +253,25 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function testDateFormat()
|
||||
public function testDateFormat(): void
|
||||
{
|
||||
$date = new \DateTime('7 January 2010 17:43:21', new \DateTimeZone('Europe/Berlin'));
|
||||
$sut = $this->getSut('en', []);
|
||||
$this->assertEquals('2010-01-07T17:43:21+01:00', $sut->dateFormat($date, 'c'));
|
||||
$this->assertStringStartsWith('2010-01-07T17:43:21', $sut->dateFormat('7 January 2010 17:43:21', 'c'));
|
||||
|
||||
// next test checks the fallback for errors while converting the date
|
||||
/* @phpstan-ignore-next-line */
|
||||
$this->assertEquals(2010.0107, $sut->dateFormat(2010.0107, 'c'));
|
||||
}
|
||||
|
||||
public function testTime()
|
||||
public function testTime(): void
|
||||
{
|
||||
$time = new \DateTime('2016-06-23');
|
||||
$time->setTime(17, 53, 23);
|
||||
|
||||
$sut = $this->getSut('en', ['en' => ['time' => 'H:i']]);
|
||||
$sut = $this->getSut('en', ['en' => ['time' => 'HH:mm']]);
|
||||
$this->assertEquals('17:53', $sut->time($time));
|
||||
$this->assertEquals('17:53', $sut->time('2016-06-23 17:53'));
|
||||
}
|
||||
|
||||
public function testDateTimeFull()
|
||||
{
|
||||
$sut = $this->getSut('en', [
|
||||
'en' => ['date_type' => 'dd-yyyy-MM-'],
|
||||
]);
|
||||
|
||||
$dateTime = new \DateTime('2019-08-17 12:29:47', new \DateTimeZone(date_default_timezone_get()));
|
||||
$dateTime->setDate(2019, 8, 17);
|
||||
$dateTime->setTime(12, 29, 47);
|
||||
|
||||
$this->assertEquals('17-2019-08- 12:29', $sut->dateTimeFull($dateTime));
|
||||
$this->assertEquals('17-2019-08- 12:29', $sut->dateTimeFull('2019-08-17 12:29:47'));
|
||||
|
||||
$dateTime = new \DateTime('2019-08-17 00:00:00');
|
||||
$this->assertEquals('17-2019-08-', $sut->dateTimeFull($dateTime, true));
|
||||
|
||||
// next test checks the fallback for errors while converting the date
|
||||
/* @phpstan-ignore-next-line */
|
||||
$this->assertEquals(189.45, $sut->dateTimeFull(189.45));
|
||||
}
|
||||
|
||||
public function testCreateDate()
|
||||
public function testCreateDate(): void
|
||||
{
|
||||
$user = new User();
|
||||
$user->setTimezone('Europe/Berlin');
|
||||
@@ -271,68 +288,7 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
$this->assertEquals(date_default_timezone_get(), $date->getTimezone()->getName());
|
||||
}
|
||||
|
||||
public function testLocales()
|
||||
{
|
||||
$locales = [
|
||||
['code' => 'en', 'name' => 'English'],
|
||||
['code' => 'de', 'name' => 'Deutsch'],
|
||||
['code' => 'ru', 'name' => 'русский'],
|
||||
];
|
||||
|
||||
$appLocales = array_merge($this->localeEn, $this->localeDe, $this->localeRu);
|
||||
$sut = $this->getSut('en', $appLocales);
|
||||
$this->assertEquals($locales, $sut->getLocales());
|
||||
}
|
||||
|
||||
public function testCurrency()
|
||||
{
|
||||
$symbols = [
|
||||
'EUR' => '€',
|
||||
'USD' => '$',
|
||||
'RUB' => 'RUB',
|
||||
'rub' => 'RUB',
|
||||
123 => 123,
|
||||
];
|
||||
|
||||
$sut = $this->getSut('en', $this->localeEn);
|
||||
foreach ($symbols as $name => $symbol) {
|
||||
$this->assertEquals($symbol, $sut->currency($name));
|
||||
}
|
||||
}
|
||||
|
||||
public function testCountry()
|
||||
{
|
||||
$countries = [
|
||||
'DE' => 'Germany',
|
||||
'RU' => 'Russia',
|
||||
'ES' => 'Spain',
|
||||
'es' => 'Spain',
|
||||
'12' => '12',
|
||||
];
|
||||
|
||||
$sut = $this->getSut('en', $this->localeEn);
|
||||
foreach ($countries as $locale => $name) {
|
||||
$this->assertEquals($name, $sut->country($locale));
|
||||
}
|
||||
}
|
||||
|
||||
public function testLanguage()
|
||||
{
|
||||
$languages = [
|
||||
'de' => 'German',
|
||||
'ru' => 'Russian',
|
||||
'es' => 'Spanish',
|
||||
'ES' => 'Spanish',
|
||||
'12' => '12',
|
||||
];
|
||||
|
||||
$sut = $this->getSut('en', $this->localeEn);
|
||||
foreach ($languages as $locale => $name) {
|
||||
$this->assertEquals($name, $sut->language($locale));
|
||||
}
|
||||
}
|
||||
|
||||
public function testMoneyWithoutCurrency()
|
||||
public function testMoneyWithoutCurrency(): void
|
||||
{
|
||||
$sut = $this->getSut($this->localeEn, 'en');
|
||||
$this->assertEquals('123.75', $sut->money(123.75));
|
||||
@@ -346,13 +302,17 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
/**
|
||||
* @dataProvider getMoneyNoCurrencyData
|
||||
*/
|
||||
public function testMoneyNoCurrency($result, $amount, $currency, $locale)
|
||||
public function testMoneyNoCurrency($result, $amount, $currency, $locale): void
|
||||
{
|
||||
$sut = $this->getSut($this->localeEn, $locale);
|
||||
$this->assertEquals($result, $sut->money($amount, $currency, false));
|
||||
}
|
||||
|
||||
public function getMoneyNoCurrencyData()
|
||||
/**
|
||||
* @return array<int, array<int, string|null|int|float>>
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getMoneyNoCurrencyData(): array
|
||||
{
|
||||
return [
|
||||
['0,00', null, 'EUR', 'de'],
|
||||
@@ -364,10 +324,10 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
['13,75', 13.75, 'USD', 'de'],
|
||||
['13,75', 13.75, 'RUB', 'de'],
|
||||
['13,75', 13.75, 'JPY', 'de'],
|
||||
['13 933,49', 13933.49, 'JPY', 'ru'],
|
||||
["13\u{a0}933,49", 13933.49, 'JPY', 'ru'],
|
||||
['13,75', 13.75, 'CNY', 'de'],
|
||||
['13.933,00', 13933, 'CNY', 'de'],
|
||||
['13 933,00', 13933, 'CNY', 'ru'],
|
||||
["13\u{a0}933,00", 13933, 'CNY', 'ru'],
|
||||
['13,933.00', 13933, 'CNY', 'en'],
|
||||
['13,933.00', 13933, 'CNY', 'zh_CN'],
|
||||
['1.234.567,89', 1234567.891234567890000, 'USD', 'de'],
|
||||
@@ -377,43 +337,51 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
/**
|
||||
* @dataProvider getMoneyData
|
||||
*/
|
||||
public function testMoney($result, $amount, $currency, $locale)
|
||||
public function testMoney(string $result, float|int|null $amount, string $currency, string $locale): void
|
||||
{
|
||||
$sut = $this->getSut($this->localeEn, $locale);
|
||||
$this->assertEquals($result, $sut->money($amount, $currency));
|
||||
}
|
||||
|
||||
public function getMoneyData()
|
||||
/**
|
||||
* @return array<int, array<int, null|string|float|int>>
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getMoneyData(): array
|
||||
{
|
||||
return [
|
||||
['0,00 €', null, 'EUR', 'de'],
|
||||
['2.345,00 €', 2345, 'EUR', 'de'],
|
||||
["0,00\u{a0}€", null, 'EUR', 'de'],
|
||||
["2.345,00\u{a0}€", 2345, 'EUR', 'de'],
|
||||
['€2,345.00', 2345, 'EUR', 'en'],
|
||||
['€2,345.01', 2345.009, 'EUR', 'en'],
|
||||
['2.345,01 €', 2345.009, 'EUR', 'de'],
|
||||
["2.345,01\u{a0}€", 2345.009, 'EUR', 'de'],
|
||||
['$13.75', 13.75, 'USD', 'en'],
|
||||
['13,75 $', 13.75, 'USD', 'de'],
|
||||
['13,75 RUB', 13.75, 'RUB', 'de'],
|
||||
['14 ¥', 13.75, 'JPY', 'de'],
|
||||
['13 933 ¥', 13933.49, 'JPY', 'ru'],
|
||||
['13,75 CN¥', 13.75, 'CNY', 'de'],
|
||||
['13.933,00 CN¥', 13933, 'CNY', 'de'],
|
||||
['13 933,00 CN¥', 13933, 'CNY', 'ru'],
|
||||
["13,75\u{a0}\$", 13.75, 'USD', 'de'],
|
||||
["13,75\u{a0}RUB", 13.75, 'RUB', 'de'],
|
||||
["14\u{a0}¥", 13.75, 'JPY', 'de'],
|
||||
["13\u{a0}933\u{a0}¥", 13933.49, 'JPY', 'ru'],
|
||||
["13,75\u{a0}CN¥", 13.75, 'CNY', 'de'],
|
||||
["13.933,00\u{a0}CN¥", 13933, 'CNY', 'de'],
|
||||
["13\u{a0}933,00\u{a0}CN¥", 13933, 'CNY', 'ru'],
|
||||
['CN¥13,933.00', 13933, 'CNY', 'en'],
|
||||
['1.234.567,89 $', 1234567.891234567890000, 'USD', 'de'],
|
||||
["1.234.567,89\u{a0}\$", 1234567.891234567890000, 'USD', 'de'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAmountData
|
||||
*/
|
||||
public function testAmount($result, $amount, $locale)
|
||||
public function testAmount($result, $amount, $locale): void
|
||||
{
|
||||
$sut = $this->getSut($this->localeEn, $locale);
|
||||
$this->assertEquals($result, $sut->amount($amount));
|
||||
}
|
||||
|
||||
public function getAmountData()
|
||||
/**
|
||||
* @return array<int, array<int, null|int|string|float>>
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getAmountData(): array
|
||||
{
|
||||
return [
|
||||
['0', null, 'de'],
|
||||
@@ -424,7 +392,7 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
['2.345,009', 2345.009, 'de'],
|
||||
['13.75', 13.75, 'en'],
|
||||
['13,75', 13.75, 'de'],
|
||||
['13 933,49', 13933.49, 'ru'],
|
||||
["13\u{a0}933,49", 13933.49, 'ru'],
|
||||
['1.234.567,891', 1234567.891234567890000, 'de'],
|
||||
];
|
||||
}
|
||||
@@ -432,7 +400,7 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
/**
|
||||
* @dataProvider getMoneyData62_1
|
||||
*/
|
||||
public function testMoney62_1($result, $amount, $currency, $locale)
|
||||
public function testMoney62_1($result, $amount, $currency, $locale): void
|
||||
{
|
||||
IntlTestHelper::requireFullIntl($this, '62.1');
|
||||
|
||||
@@ -440,49 +408,53 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
$this->assertEquals($result, $sut->money($amount, $currency));
|
||||
}
|
||||
|
||||
public function getMoneyData62_1()
|
||||
/**
|
||||
* @return array<int, array<int, string|float>>
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getMoneyData62_1(): array
|
||||
{
|
||||
return [
|
||||
['RUB 13.50', 13.50, 'RUB', 'en'],
|
||||
['13,75 ₽', 13.75, 'RUB', 'ru'],
|
||||
["RUB\u{a0}13.50", 13.50, 'RUB', 'en'],
|
||||
["13,75\u{a0}₽", 13.75, 'RUB', 'ru'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testDuration()
|
||||
public function testDuration(): void
|
||||
{
|
||||
$record = $this->getTimesheet(9437);
|
||||
|
||||
$sut = $this->getSut('en', $this->localeEn);
|
||||
$this->assertEquals('02:37 h', $sut->duration($record->getDuration()));
|
||||
$this->assertEquals('2:37', $sut->duration($record->getDuration()));
|
||||
$this->assertEquals('2.62', $sut->duration($record->getDuration(), true));
|
||||
|
||||
// test Timesheet object
|
||||
$this->assertEquals('02:37 h', $sut->duration($record));
|
||||
$this->assertEquals('2:37', $sut->duration($record));
|
||||
$this->assertEquals('2.62', $sut->duration($record, true));
|
||||
|
||||
// test extended format
|
||||
$sut = $this->getSut($this->localeFake, 'XX');
|
||||
$this->assertEquals('02 - 37 Zeit', $sut->duration($record->getDuration()));
|
||||
$this->assertEquals('2:37', $sut->duration($record->getDuration()));
|
||||
|
||||
// test negative duration
|
||||
$sut = $this->getSut($this->localeEn, 'en');
|
||||
$this->assertEquals('00:00 h', $sut->duration(0));
|
||||
$this->assertEquals('00:00 h', $sut->duration(-1));
|
||||
$this->assertEquals('00:00 h', $sut->duration(-59));
|
||||
$this->assertEquals('-00:01 h', $sut->duration(-60));
|
||||
$this->assertEquals('-01:36 h', $sut->duration(-5786));
|
||||
$this->assertEquals('0:00', $sut->duration(0));
|
||||
$this->assertEquals('0:00', $sut->duration(-1));
|
||||
$this->assertEquals('0:00', $sut->duration(-59));
|
||||
$this->assertEquals('-0:01', $sut->duration(-60));
|
||||
$this->assertEquals('-1:36', $sut->duration(-5786));
|
||||
|
||||
// test zero duration
|
||||
$sut = $this->getSut($this->localeEn, 'en');
|
||||
$this->assertEquals('00:00 h', $sut->duration(0));
|
||||
$this->assertEquals('0:00', $sut->duration(0));
|
||||
|
||||
$sut = $this->getSut($this->localeEn, 'en');
|
||||
|
||||
$this->assertEquals('00:00 h', $sut->duration(null));
|
||||
$this->assertEquals('0:00', $sut->duration(null));
|
||||
$this->assertEquals('0.00', $sut->duration(null, true));
|
||||
}
|
||||
|
||||
public function testDurationChart()
|
||||
public function testDurationChart(): void
|
||||
{
|
||||
$sut = $this->getSut('en', $this->localeEn);
|
||||
self::assertEquals(0.34, $sut->durationChart(1234));
|
||||
@@ -491,20 +463,23 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
self::assertEquals(342.94, $sut->durationChart(1234567));
|
||||
}
|
||||
|
||||
public function testJavascriptConfigurations()
|
||||
public function testJavascriptConfigurations(): void
|
||||
{
|
||||
$expected = [
|
||||
'formatDuration' => '%h:%m h',
|
||||
'formatDate' => 'YYYY-MM-DD',
|
||||
'formatDuration' => '%h:%m',
|
||||
'formatDate' => 'Y-m-d',
|
||||
'defaultColor' => '#d2d6de',
|
||||
'twentyFourHours' => true,
|
||||
'twentyFourHours' => false,
|
||||
'updateBrowserTitle' => false,
|
||||
'timezone' => 'America/Edmonton',
|
||||
];
|
||||
$user = new User();
|
||||
$user->setTimezone('America/Edmonton');
|
||||
$sut = $this->getSut('en', $this->localeEn);
|
||||
self::assertEquals($expected, $sut->getJavascriptConfiguration(new User()));
|
||||
self::assertEquals($expected, $sut->getJavascriptConfiguration($user));
|
||||
}
|
||||
|
||||
public function testDurationDecimal()
|
||||
public function testDurationDecimal(): void
|
||||
{
|
||||
$record = $this->getTimesheet(9437);
|
||||
|
||||
@@ -524,6 +499,7 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
|
||||
// test negative duration
|
||||
$sut = $this->getSut($this->localeEn, 'en');
|
||||
$this->assertEquals('-0.01', $sut->durationDecimal(-40));
|
||||
$this->assertEquals('-0.01', $sut->durationDecimal(-50));
|
||||
|
||||
// test negative duration - with rounding issue
|
||||
@@ -532,6 +508,7 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
|
||||
// test zero duration
|
||||
$sut = $this->getSut($this->localeEn, 'en');
|
||||
$this->assertEquals('0.00', $sut->durationDecimal(-0));
|
||||
$this->assertEquals('0.00', $sut->durationDecimal(0));
|
||||
|
||||
$sut = $this->getSut($this->localeEn, 'en');
|
||||
@@ -553,7 +530,7 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
throw new \Exception('Unknown twig test: ' . $name);
|
||||
}
|
||||
|
||||
public function testIsToday()
|
||||
public function testIsToday(): void
|
||||
{
|
||||
$sut = $this->getSut('en', $this->localeEn);
|
||||
$test = $this->getTest($sut, 'today');
|
||||
@@ -564,34 +541,30 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
self::assertFalse(\call_user_func($test->getCallable(), null));
|
||||
}
|
||||
|
||||
public function testIsWeekend()
|
||||
public function testIsWeekend(): void
|
||||
{
|
||||
$sut = $this->getSut('en', $this->localeEn, false);
|
||||
$test = $this->getTest($sut, 'weekend');
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first monday this month')));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first tuesday this month')));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first wednesday this month')));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first thursday this month')));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first friday this month')));
|
||||
self::assertTrue(\call_user_func($test->getCallable(), new \DateTime('first saturday this month')));
|
||||
self::assertTrue(\call_user_func($test->getCallable(), new \DateTime('first sunday this month')));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \stdClass()));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), null));
|
||||
self::assertFalse($sut->isWeekend(new \DateTime('first monday this month')));
|
||||
self::assertFalse($sut->isWeekend(new \DateTime('first tuesday this month')));
|
||||
self::assertFalse($sut->isWeekend(new \DateTime('first wednesday this month')));
|
||||
self::assertFalse($sut->isWeekend(new \DateTime('first thursday this month')));
|
||||
self::assertFalse($sut->isWeekend(new \DateTime('first friday this month')));
|
||||
self::assertTrue($sut->isWeekend(new \DateTime('first saturday this month')));
|
||||
self::assertTrue($sut->isWeekend(new \DateTime('first sunday this month')));
|
||||
self::assertFalse($sut->isWeekend(null));
|
||||
|
||||
$sut = $this->getSut('en', $this->localeEn, true);
|
||||
$test = $this->getTest($sut, 'weekend');
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first monday this month')));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first tuesday this month')));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first wednesday this month')));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first thursday this month')));
|
||||
self::assertTrue(\call_user_func($test->getCallable(), new \DateTime('first friday this month')));
|
||||
self::assertTrue(\call_user_func($test->getCallable(), new \DateTime('first saturday this month')));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first sunday this month')));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \stdClass()));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), null));
|
||||
self::assertFalse($sut->isWeekend(new \DateTime('first monday this month')));
|
||||
self::assertFalse($sut->isWeekend(new \DateTime('first tuesday this month')));
|
||||
self::assertFalse($sut->isWeekend(new \DateTime('first wednesday this month')));
|
||||
self::assertFalse($sut->isWeekend(new \DateTime('first thursday this month')));
|
||||
self::assertTrue($sut->isWeekend(new \DateTime('first friday this month')));
|
||||
self::assertTrue($sut->isWeekend(new \DateTime('first saturday this month')));
|
||||
self::assertFalse($sut->isWeekend(new \DateTime('first sunday this month')));
|
||||
self::assertFalse($sut->isWeekend(null));
|
||||
}
|
||||
|
||||
protected function getTimesheet($seconds)
|
||||
protected function getTimesheet($seconds): Timesheet
|
||||
{
|
||||
$begin = new \DateTime();
|
||||
$end = clone $begin;
|
||||
@@ -604,7 +577,7 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
return $record;
|
||||
}
|
||||
|
||||
public function testChartMoney()
|
||||
public function testChartMoney(): void
|
||||
{
|
||||
$sut = $this->getSut('en', $this->localeEn, false);
|
||||
$this->assertEquals('-123456.78', $sut->moneyChart(-123456.78));
|
||||
@@ -613,10 +586,10 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
$this->assertEquals('456.00', $sut->moneyChart(456));
|
||||
}
|
||||
|
||||
public function testCharDuration()
|
||||
public function testChartDuration(): void
|
||||
{
|
||||
$sut = $this->getSut('en', $this->localeEn, false);
|
||||
$this->assertEquals('34.29', $sut->durationChart(123456.78));
|
||||
$this->assertEquals('-34.29', $sut->durationChart(-123456.78));
|
||||
$this->assertEquals('34.29', $sut->durationChart(123456));
|
||||
$this->assertEquals('-34.29', $sut->durationChart(-123456));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user