added begin, end and export filter for API timesheets (#639)
This commit is contained in:
52
tests/API/ConfigurationControllerTest.php
Normal file
52
tests/API/ConfigurationControllerTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\API;
|
||||
|
||||
use App\Configuration\LanguageFormattings;
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\User;
|
||||
use App\Repository\Query\VisibilityQuery;
|
||||
use Symfony\Bundle\FrameworkBundle\Client;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \App\API\ConfigurationController
|
||||
* @group integration
|
||||
*/
|
||||
class ConfigurationControllerTest extends APIControllerBaseTest
|
||||
{
|
||||
public function testI18nIsSecure()
|
||||
{
|
||||
$this->assertUrlIsSecured('/api/config/i18n');
|
||||
}
|
||||
|
||||
public function testGetI18n()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/config/i18n', 'GET');
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals(7, count($result));
|
||||
$this->assertStructure($result, false);
|
||||
}
|
||||
|
||||
protected function assertStructure(array $result, $full = true)
|
||||
{
|
||||
$expectedKeys = ['date', 'date_time', 'duration', 'form_date', 'form_date_time', 'is24hours', 'time'];
|
||||
$actual = array_keys($result);
|
||||
sort($actual);
|
||||
sort($expectedKeys);
|
||||
|
||||
$this->assertEquals($expectedKeys, $actual, 'Activity structure does not match');
|
||||
}
|
||||
}
|
||||
52
tests/API/Model/I18nTest.php
Normal file
52
tests/API/Model/I18nTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\API;
|
||||
|
||||
use App\API\Model\I18n;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \App\API\Model\I18n
|
||||
*/
|
||||
class I18nTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = new I18n();
|
||||
$this->assertTrue($sut->isIs24hours());
|
||||
$this->assertEquals('', $sut->getDuration());
|
||||
$this->assertEquals('', $sut->getDate());
|
||||
$this->assertEquals('', $sut->getDateTime());
|
||||
$this->assertEquals('', $sut->getFormDate());
|
||||
$this->assertEquals('', $sut->getFormDateTime());
|
||||
$this->assertEquals('', $sut->getTime());
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new I18n();
|
||||
|
||||
$this->assertInstanceOf(I18n::class, $sut->setIs24hours(false));
|
||||
$this->assertInstanceOf(I18n::class, $sut->setDuration('foo'));
|
||||
$this->assertInstanceOf(I18n::class, $sut->setDate('bar'));
|
||||
$this->assertInstanceOf(I18n::class, $sut->setDateTime('hello'));
|
||||
$this->assertInstanceOf(I18n::class, $sut->setFormDate('world'));
|
||||
$this->assertInstanceOf(I18n::class, $sut->setFormDateTime('testing'));
|
||||
$this->assertInstanceOf(I18n::class, $sut->setTime('fun'));
|
||||
|
||||
$this->assertFalse($sut->isIs24hours());
|
||||
$this->assertEquals('foo', $sut->getDuration());
|
||||
$this->assertEquals('bar', $sut->getDate());
|
||||
$this->assertEquals('hello', $sut->getDateTime());
|
||||
$this->assertEquals('world', $sut->getFormDate());
|
||||
$this->assertEquals('testing', $sut->getFormDateTime());
|
||||
$this->assertEquals('fun', $sut->getTime());
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,23 @@ class TimesheetControllerTest extends APIControllerBaseTest
|
||||
|
||||
public function testGetCollectionWithQuery()
|
||||
{
|
||||
$query = ['customer' => 1, 'project' => 1, 'activity' => 1, 'page' => 2, 'size' => 5, 'order' => 'DESC', 'orderBy' => 'rate'];
|
||||
$begin = new \DateTime('-10 days');
|
||||
$begin->setTime(0, 0, 0);
|
||||
$end = new \DateTime();
|
||||
$end->setTime(23, 59, 59);
|
||||
|
||||
$query = [
|
||||
'customer' => 1,
|
||||
'project' => 1,
|
||||
'activity' => 1,
|
||||
'page' => 2,
|
||||
'size' => 5,
|
||||
'order' => 'DESC',
|
||||
'orderBy' => 'rate',
|
||||
'begin' => $begin->format('Y-m-d H:i:s'),
|
||||
'end' => $end->format('Y-m-d H:i:s'),
|
||||
'exported' => 0,
|
||||
];
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
@@ -130,6 +146,74 @@ class TimesheetControllerTest extends APIControllerBaseTest
|
||||
$this->assertDefaultStructure($result[0], false);
|
||||
}
|
||||
|
||||
public function testExportedFilter()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture
|
||||
->setExported(true)
|
||||
->setAmount(7)
|
||||
->setUser($this->getUserByRole($em, User::ROLE_USER))
|
||||
->setStartDate(new \DateTime('-10 days'))
|
||||
->setAllowEmptyDescriptions(false)
|
||||
;
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$begin = new \DateTime('-10 days');
|
||||
$begin->setTime(0, 0, 0);
|
||||
$end = new \DateTime();
|
||||
$end->setTime(23, 59, 59);
|
||||
|
||||
$query = [
|
||||
'page' => 1,
|
||||
'size' => 50,
|
||||
'begin' => $begin->format('Y-m-d H:i:s'),
|
||||
'end' => $end->format('Y-m-d H:i:s'),
|
||||
'exported' => 1,
|
||||
];
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals(7, count($result));
|
||||
$this->assertDefaultStructure($result[0], false);
|
||||
|
||||
$query = [
|
||||
'page' => 1,
|
||||
'size' => 50,
|
||||
'begin' => $begin->format('Y-m-d H:i:s'),
|
||||
'end' => $end->format('Y-m-d H:i:s'),
|
||||
'exported' => 0,
|
||||
];
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals(10, count($result));
|
||||
$this->assertDefaultStructure($result[0], false);
|
||||
|
||||
$query = [
|
||||
'page' => 1,
|
||||
'size' => 50,
|
||||
'begin' => $begin->format('Y-m-d H:i:s'),
|
||||
'end' => $end->format('Y-m-d H:i:s'),
|
||||
];
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals(17, count($result));
|
||||
$this->assertDefaultStructure($result[0], false);
|
||||
}
|
||||
|
||||
public function testGetEntity()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
|
||||
195
tests/Configuration/LanguageFormattingsTest.php
Normal file
195
tests/Configuration/LanguageFormattingsTest.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Configuration;
|
||||
|
||||
use App\Configuration\LanguageFormattings;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Configuration\LanguageFormattings
|
||||
*/
|
||||
class LanguageFormattingsTest extends TestCase
|
||||
{
|
||||
protected function getSut(array $settings)
|
||||
{
|
||||
return new LanguageFormattings($settings);
|
||||
}
|
||||
|
||||
protected function getDefaultSettings()
|
||||
{
|
||||
return [
|
||||
'de' => [
|
||||
'date_time_type' => 'dd.MM.yyyy HH:mm',
|
||||
'date_time_picker' => 'DD.MM.YYYY HH:mm',
|
||||
'date_type' => 'dd.MM.yyyy',
|
||||
'date_picker' => 'DD.MM.YYYY',
|
||||
'date' => 'd.m.Y',
|
||||
'date_time' => 'd.m. H:i',
|
||||
'duration' => '%h:%m h',
|
||||
'time' => 'H:i',
|
||||
'24_hours' => true,
|
||||
],
|
||||
'en' => [
|
||||
'date_time_type' => 'yyyy-MM-dd HH:mm',
|
||||
'date_time_picker' => 'YYYY-MM-DD HH:mm',
|
||||
'date_type' => 'yyyy-MM-dd',
|
||||
'date_picker' => 'YYYY-MM-DD',
|
||||
'date' => 'Y-m-d',
|
||||
'date_time' => 'm-d H:i',
|
||||
'duration' => '%h:%m h',
|
||||
'time' => 'H:i:s',
|
||||
'24_hours' => false,
|
||||
],
|
||||
'pt_BR' => [
|
||||
'date_time_type' => 'dd-MM-yyyy HH:mm',
|
||||
'date_time_picker' => 'DD-MM-YYYY HH:mm',
|
||||
'date_type' => 'dd-MM-yyyy',
|
||||
'date_picker' => 'DD-MM-YYYY',
|
||||
'date' => 'd-m-Y',
|
||||
'duration' => '%h:%m h',
|
||||
],
|
||||
'it' => [
|
||||
'date_time_type' => 'dd.MM.yyyy HH:mm',
|
||||
'date_time_picker' => 'DD.MM.YYYY HH:mm',
|
||||
'date_type' => 'dd.MM.yyyy',
|
||||
'date_picker' => 'DD.MM.YYYY',
|
||||
'date' => 'd.m.Y',
|
||||
'duration' => '%h:%m h',
|
||||
],
|
||||
'fr' => [
|
||||
'date_time_type' => 'dd/MM/yyyy HH:mm',
|
||||
'date_time_picker' => 'DD/MM/YYYY HH:mm',
|
||||
'date_type' => 'dd/MM/yyyy',
|
||||
'date_picker' => 'DD/MM/YYYY',
|
||||
'date' => 'd/m/Y',
|
||||
'duration' => '%h h %m',
|
||||
],
|
||||
'es' => [
|
||||
'date_time_type' => 'dd.MM.yyyy HH:mm',
|
||||
'date_time_picker' => 'DD.MM.YYYY HH:mm',
|
||||
'date_type' => 'dd.MM.yyyy',
|
||||
'date_picker' => 'DD.MM.YYYY',
|
||||
'date' => 'd.m.Y',
|
||||
'duration' => '%h:%m h',
|
||||
],
|
||||
'ru' => [
|
||||
'date_time_type' => 'dd.MM.yyyy HH:mm',
|
||||
'date_time_picker' => 'DD.MM.YYYY HH:mm',
|
||||
'date_type' => 'dd.MM.yyyy',
|
||||
'date_picker' => 'DD.MM.YYYY',
|
||||
'date' => 'd.m.Y',
|
||||
'duration' => '%h:%m h',
|
||||
],
|
||||
'ar' => [
|
||||
'date_time_type' => 'yyyy-MM-dd HH:mm',
|
||||
'date_time_picker' => 'YYYY-MM-DD HH:mm',
|
||||
'date_type' => 'yyyy-MM-dd',
|
||||
'date_picker' => 'YYYY-MM-DD',
|
||||
'date' => 'Y-m-d',
|
||||
'duration' => '%h:%m h',
|
||||
],
|
||||
'hu' => [
|
||||
'date_time_type' => 'yyyy.MM.dd HH:mm',
|
||||
'date_time_picker' => 'YYYY.MM.DD HH:mm',
|
||||
'date_type' => 'yyyy.MM.dd',
|
||||
'date_picker' => 'YYYY.MM.DD',
|
||||
'date' => 'Y.m.d.',
|
||||
'duration' => '%h:%m h',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetAvailableLanguages()
|
||||
{
|
||||
$sut = $this->getSut([]);
|
||||
$this->assertEquals([], $sut->getAvailableLanguages());
|
||||
|
||||
$sut = $this->getSut($this->getDefaultSettings());
|
||||
$this->assertEquals(['de', 'en', 'pt_BR', 'it', 'fr', 'es', 'ru', 'ar', 'hu'], $sut->getAvailableLanguages());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Unknown locale given: xx
|
||||
*/
|
||||
public function testInvalidLocaleWithGivenLocale()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings());
|
||||
$sut->getDateFormat('xx');
|
||||
}
|
||||
|
||||
public function testGetDurationFormat()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings());
|
||||
$this->assertEquals('%h:%m h', $sut->getDurationFormat('de'));
|
||||
}
|
||||
|
||||
public function testGetDateFormat()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings());
|
||||
$this->assertEquals('d.m.Y', $sut->getDateFormat('de'));
|
||||
}
|
||||
|
||||
public function testGetDateTimeFormat()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings());
|
||||
$this->assertEquals('d.m. H:i', $sut->getDateTimeFormat('de'));
|
||||
}
|
||||
|
||||
public function testGetDateTypeFormat()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings());
|
||||
$this->assertEquals('dd.MM.yyyy', $sut->getDateTypeFormat('de'));
|
||||
}
|
||||
|
||||
public function testGetDatePickerFormat()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings());
|
||||
$this->assertEquals('DD.MM.YYYY', $sut->getDatePickerFormat('de'));
|
||||
}
|
||||
|
||||
public function testGetDateTimeTypeFormat()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings());
|
||||
$this->assertEquals('dd.MM.yyyy HH:mm', $sut->getDateTimeTypeFormat('de'));
|
||||
}
|
||||
|
||||
public function testGetDateTimePickerFormat()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings());
|
||||
$this->assertEquals('DD.MM.YYYY HH:mm', $sut->getDateTimePickerFormat('de'));
|
||||
}
|
||||
|
||||
public function testIs24Hours()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings());
|
||||
$this->assertTrue($sut->isTwentyFourHours('de'));
|
||||
$this->assertFalse($sut->isTwentyFourHours('en'));
|
||||
}
|
||||
|
||||
public function testGetTimeFormat()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings());
|
||||
$this->assertEquals('H:i', $sut->getTimeFormat('de'));
|
||||
$this->assertEquals('H:i:s', $sut->getTimeFormat('en'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Unknown setting for locale en: date_time_picker
|
||||
*/
|
||||
public function testUnknownSetting()
|
||||
{
|
||||
$sut = $this->getSut(['en' => [
|
||||
'xxx' => 'dd.MM.yyyy HH:mm',
|
||||
]]);
|
||||
$sut->getDateTimePickerFormat('en');
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,10 @@ class TimesheetFixtures extends Fixture
|
||||
* @var bool
|
||||
*/
|
||||
protected $allowEmptyDescriptions = true;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $exported = false;
|
||||
|
||||
/**
|
||||
* @param bool $allowEmptyDescriptions
|
||||
@@ -68,6 +72,17 @@ class TimesheetFixtures extends Fixture
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exported
|
||||
* @return TimesheetFixtures
|
||||
*/
|
||||
public function setExported(bool $exported)
|
||||
{
|
||||
$this->exported = $exported;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $fixedRate
|
||||
* @return TimesheetFixtures
|
||||
@@ -292,6 +307,10 @@ class TimesheetFixtures extends Fixture
|
||||
$entry->setHourlyRate($hourlyRate);
|
||||
}
|
||||
|
||||
if (null !== $this->exported) {
|
||||
$entry->setExported($this->exported);
|
||||
}
|
||||
|
||||
if ($setEndDate) {
|
||||
$entry
|
||||
->setEnd($end)
|
||||
|
||||
@@ -107,4 +107,17 @@ class UserTest extends AbstractEntityTest
|
||||
$this->assertEquals('foo', (string) $user);
|
||||
$this->assertEquals('foo', $user->getAlias());
|
||||
}
|
||||
|
||||
public function testGetLocale()
|
||||
{
|
||||
$sut = new User();
|
||||
$this->assertEquals(User::DEFAULT_LANGUAGE, $sut->getLocale());
|
||||
|
||||
$language = new UserPreference();
|
||||
$language->setName(UserPreference::LOCALE);
|
||||
$language->setValue('fr');
|
||||
$sut->addPreference($language);
|
||||
|
||||
$this->assertEquals('fr', $sut->getLocale());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\Tests\Export\Renderer;
|
||||
|
||||
use App\Configuration\LanguageFormattings;
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
@@ -45,7 +46,7 @@ abstract class AbstractRendererTest extends KernelTestCase
|
||||
$request->setLocale('en');
|
||||
$requestStack->push($request);
|
||||
|
||||
$localeSettings = new LocaleSettings($requestStack, $languages);
|
||||
$localeSettings = new LocaleSettings($requestStack, new LanguageFormattings($languages));
|
||||
|
||||
$translator = $this->getMockBuilder(TranslatorInterface::class)->getMock();
|
||||
$dateExtension = new DateExtensions($localeSettings);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\Tests\Invoice\Renderer;
|
||||
|
||||
use App\Configuration\LanguageFormattings;
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\InvoiceDocument;
|
||||
@@ -69,7 +70,7 @@ abstract class AbstractRendererTest extends KernelTestCase
|
||||
$request->setLocale('en');
|
||||
$requestStack->push($request);
|
||||
|
||||
$localeSettings = new LocaleSettings($requestStack, $languages);
|
||||
$localeSettings = new LocaleSettings($requestStack, new LanguageFormattings($languages));
|
||||
|
||||
$translator = $this->getMockBuilder(TranslatorInterface::class)->getMock();
|
||||
$dateExtension = new DateExtensions($localeSettings);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\Tests\Twig;
|
||||
|
||||
use App\Configuration\LanguageFormattings;
|
||||
use App\Twig\DateExtensions;
|
||||
use App\Utils\LocaleSettings;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -33,7 +34,7 @@ class DateExtensionsTest extends TestCase
|
||||
$requestStack = new RequestStack();
|
||||
$requestStack->push($request);
|
||||
|
||||
$localeSettings = new LocaleSettings($requestStack, $dateSettings);
|
||||
$localeSettings = new LocaleSettings($requestStack, new LanguageFormattings($dateSettings));
|
||||
|
||||
return new DateExtensions($localeSettings);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\Tests\Twig;
|
||||
|
||||
use App\Configuration\LanguageFormattings;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Twig\Extensions;
|
||||
@@ -41,7 +42,7 @@ class ExtensionsTest extends TestCase
|
||||
$requestStack = new RequestStack();
|
||||
$requestStack->push($request);
|
||||
|
||||
$localeSettings = new LocaleSettings($requestStack, $locales);
|
||||
$localeSettings = new LocaleSettings($requestStack, new LanguageFormattings($locales));
|
||||
|
||||
return new Extensions($requestStack, $localeSettings);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\Tests\Utils;
|
||||
|
||||
use App\Configuration\LanguageFormattings;
|
||||
use App\Utils\LocaleSettings;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -16,6 +17,7 @@ use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
* @covers \App\Utils\LocaleSettings
|
||||
* @covers \App\Configuration\LanguageFormattings
|
||||
*/
|
||||
class LocaleSettingsTest extends TestCase
|
||||
{
|
||||
@@ -31,7 +33,7 @@ class LocaleSettingsTest extends TestCase
|
||||
|
||||
protected function getSut(string $locale, array $settings)
|
||||
{
|
||||
return new LocaleSettings($this->getRequestStack($locale), $settings);
|
||||
return new LocaleSettings($this->getRequestStack($locale), new LanguageFormattings($settings));
|
||||
}
|
||||
|
||||
protected function getDefaultSettings()
|
||||
@@ -45,6 +47,8 @@ class LocaleSettingsTest extends TestCase
|
||||
'date' => 'd.m.Y',
|
||||
'date_time' => 'd.m. H:i',
|
||||
'duration' => '%h:%m h',
|
||||
'time' => 'H:i',
|
||||
'24_hours' => true,
|
||||
],
|
||||
'en' => [
|
||||
'date_time_type' => 'yyyy-MM-dd HH:mm',
|
||||
@@ -54,6 +58,8 @@ class LocaleSettingsTest extends TestCase
|
||||
'date' => 'Y-m-d',
|
||||
'date_time' => 'm-d H:i',
|
||||
'duration' => '%h:%m h',
|
||||
'time' => 'H:i:s',
|
||||
'24_hours' => false,
|
||||
],
|
||||
'pt_BR' => [
|
||||
'date_time_type' => 'dd-MM-yyyy HH:mm',
|
||||
@@ -146,57 +152,62 @@ class LocaleSettingsTest extends TestCase
|
||||
*/
|
||||
public function testInvalidLocaleWithGivenLocale()
|
||||
{
|
||||
$sut = $this->getSut('en', $this->getDefaultSettings());
|
||||
$sut->getDateFormat('xx');
|
||||
$sut = $this->getSut('xx', $this->getDefaultSettings());
|
||||
$sut->getDateFormat();
|
||||
}
|
||||
|
||||
public function testGetDurationFormat()
|
||||
{
|
||||
$sut = $this->getSut('en', $this->getDefaultSettings());
|
||||
$this->assertEquals('%h:%m h', $sut->getDurationFormat());
|
||||
$this->assertEquals('%h:%m h', $sut->getDurationFormat('de'));
|
||||
}
|
||||
|
||||
public function testGetDateFormat()
|
||||
{
|
||||
$sut = $this->getSut('en', $this->getDefaultSettings());
|
||||
$this->assertEquals('Y-m-d', $sut->getDateFormat());
|
||||
$this->assertEquals('d.m.Y', $sut->getDateFormat('de'));
|
||||
$sut = $this->getSut('de', $this->getDefaultSettings());
|
||||
$this->assertEquals('d.m.Y', $sut->getDateFormat());
|
||||
}
|
||||
|
||||
public function testGetDateTimeFormat()
|
||||
{
|
||||
$sut = $this->getSut('en', $this->getDefaultSettings());
|
||||
$this->assertEquals('m-d H:i', $sut->getDateTimeFormat());
|
||||
$this->assertEquals('d.m. H:i', $sut->getDateTimeFormat('de'));
|
||||
}
|
||||
|
||||
public function testGetDateTypeFormat()
|
||||
{
|
||||
$sut = $this->getSut('en', $this->getDefaultSettings());
|
||||
$this->assertEquals('yyyy-MM-dd', $sut->getDateTypeFormat());
|
||||
$this->assertEquals('dd.MM.yyyy', $sut->getDateTypeFormat('de'));
|
||||
$sut = $this->getSut('de', $this->getDefaultSettings());
|
||||
$this->assertEquals('dd.MM.yyyy', $sut->getDateTypeFormat());
|
||||
}
|
||||
|
||||
public function testGetDatePickerFormat()
|
||||
{
|
||||
$sut = $this->getSut('en', $this->getDefaultSettings());
|
||||
$this->assertEquals('YYYY-MM-DD', $sut->getDatePickerFormat());
|
||||
$this->assertEquals('DD.MM.YYYY', $sut->getDatePickerFormat('de'));
|
||||
}
|
||||
|
||||
public function testGetDateTimeTypeFormat()
|
||||
{
|
||||
$sut = $this->getSut('en', $this->getDefaultSettings());
|
||||
$this->assertEquals('yyyy-MM-dd HH:mm', $sut->getDateTimeTypeFormat());
|
||||
$this->assertEquals('dd.MM.yyyy HH:mm', $sut->getDateTimeTypeFormat('de'));
|
||||
}
|
||||
|
||||
public function testGetDateTimePickerFormat()
|
||||
{
|
||||
$sut = $this->getSut('en', $this->getDefaultSettings());
|
||||
$this->assertEquals('YYYY-MM-DD HH:mm', $sut->getDateTimePickerFormat());
|
||||
$this->assertEquals('DD.MM.YYYY HH:mm', $sut->getDateTimePickerFormat('de'));
|
||||
}
|
||||
|
||||
public function testIs24Hours()
|
||||
{
|
||||
$sut = $this->getSut('en', $this->getDefaultSettings());
|
||||
$this->assertFalse($sut->isTwentyFourHours());
|
||||
}
|
||||
|
||||
public function testGetTimeFormat()
|
||||
{
|
||||
$sut = $this->getSut('en', $this->getDefaultSettings());
|
||||
$this->assertEquals('H:i:s', $sut->getTimeFormat());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,6 +219,6 @@ class LocaleSettingsTest extends TestCase
|
||||
$sut = $this->getSut('en', ['en' => [
|
||||
'xxx' => 'dd.MM.yyyy HH:mm',
|
||||
]]);
|
||||
$sut->getDateTimePickerFormat('en');
|
||||
$sut->getDateTimePickerFormat();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user