Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)
This commit is contained in:
@@ -1,100 +0,0 @@
|
||||
<?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\CalendarConfiguration;
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Configuration\CalendarConfiguration
|
||||
* @group legacy
|
||||
*/
|
||||
class CalendarConfigurationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param array $settings
|
||||
* @param array $loaderSettings
|
||||
* @return CalendarConfiguration
|
||||
*/
|
||||
protected function getSut(array $settings, array $loaderSettings = [])
|
||||
{
|
||||
$loader = new TestConfigLoader($loaderSettings);
|
||||
|
||||
return new CalendarConfiguration(new SystemConfiguration($loader, ['calendar' => $settings]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getDefaultSettings()
|
||||
{
|
||||
return [
|
||||
'businessHours' => [
|
||||
'days' => [2, 4, 6],
|
||||
'begin' => '07:49',
|
||||
'end' => '19:27'
|
||||
],
|
||||
'visibleHours' => [
|
||||
'begin' => '09:00',
|
||||
'end' => '21:34',
|
||||
],
|
||||
'day_limit' => 20,
|
||||
'slot_duration' => '01:11:00',
|
||||
'week_numbers' => false,
|
||||
'google' => [
|
||||
'api_key' => 'wertwertwegsdfbdf243w567fg8ihuon',
|
||||
'sources' => [
|
||||
'holidays' => [
|
||||
'id' => 'de.german#holiday@group.v.calendar.google.com',
|
||||
'color' => '#ccc',
|
||||
],
|
||||
'holidays_en' => [
|
||||
'id' => 'en.german#holiday@group.v.calendar.google.com',
|
||||
'color' => '#fff',
|
||||
],
|
||||
]
|
||||
],
|
||||
'weekends' => true,
|
||||
];
|
||||
}
|
||||
|
||||
public function testPrefix()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
$this->assertEquals('calendar', $sut->getPrefix());
|
||||
}
|
||||
|
||||
public function testConfigs()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
$this->assertEquals([2, 4, 6], $sut->getBusinessDays());
|
||||
$this->assertEquals('07:49', $sut->getBusinessTimeBegin());
|
||||
$this->assertEquals('19:27', $sut->getBusinessTimeEnd());
|
||||
$this->assertEquals('01:11:00', $sut->getSlotDuration());
|
||||
$this->assertEquals(20, $sut->getDayLimit());
|
||||
$this->assertFalse($sut->isShowWeekNumbers());
|
||||
|
||||
$this->assertEquals('wertwertwegsdfbdf243w567fg8ihuon', $sut->getGoogleApiKey());
|
||||
$sources = $sut->getGoogleSources();
|
||||
$this->assertEquals(2, \count($sources));
|
||||
|
||||
self::assertTrue($sut->isShowWeekends());
|
||||
self::assertEquals('09:00', $sut->getTimeframeBegin());
|
||||
self::assertEquals('21:34', $sut->getTimeframeEnd());
|
||||
}
|
||||
|
||||
public function testFindByKey()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
$this->assertFalse($sut->find('week_numbers'));
|
||||
$this->assertFalse($sut->find('calendar.week_numbers'));
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
<?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\FormConfiguration;
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Entity\Configuration;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Configuration\FormConfiguration
|
||||
* @group legacy
|
||||
*/
|
||||
class FormConfigurationTest extends TestCase
|
||||
{
|
||||
protected function getSut(array $settings, array $loaderSettings = [])
|
||||
{
|
||||
$loader = new TestConfigLoader($loaderSettings);
|
||||
|
||||
return new FormConfiguration(new SystemConfiguration($loader, ['defaults' => $settings]));
|
||||
}
|
||||
|
||||
protected function getDefaultSettings()
|
||||
{
|
||||
return [
|
||||
'customer' => [
|
||||
'timezone' => 'Europe/London',
|
||||
'currency' => 'GBP',
|
||||
'country' => 'FR',
|
||||
],
|
||||
'user' => [
|
||||
'timezone' => 'Europe/London',
|
||||
'currency' => 'GBP',
|
||||
'country' => 'FR',
|
||||
'language' => 'it',
|
||||
'theme' => 'blue',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getDefaultLoaderSettings()
|
||||
{
|
||||
return [
|
||||
(new Configuration())->setName('defaults.customer.timezone')->setValue('Russia/Moscov'),
|
||||
(new Configuration())->setName('defaults.customer.currency')->setValue('USD'),
|
||||
(new Configuration())->setName('defaults.customer.country')->setValue('RU'),
|
||||
(new Configuration())->setName('defaults.user.timezone')->setValue('Russia/Moscov'),
|
||||
(new Configuration())->setName('defaults.user.currency')->setValue('USD'),
|
||||
(new Configuration())->setName('defaults.user.language')->setValue('RU'),
|
||||
(new Configuration())->setName('defaults.user.country')->setValue('RU'),
|
||||
(new Configuration())->setName('defaults.user.theme')->setValue('black'),
|
||||
];
|
||||
}
|
||||
|
||||
public function testPrefix()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
$this->assertEquals('defaults', $sut->getPrefix());
|
||||
}
|
||||
|
||||
public function testDefaultWithoutLoader()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
$this->assertEquals('Europe/London', $sut->getCustomerDefaultTimezone());
|
||||
$this->assertEquals('GBP', $sut->getCustomerDefaultCurrency());
|
||||
$this->assertEquals('FR', $sut->getCustomerDefaultCountry());
|
||||
}
|
||||
|
||||
public function testDefaultWithLoader()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), $this->getDefaultLoaderSettings());
|
||||
$this->assertEquals('Russia/Moscov', $sut->getCustomerDefaultTimezone());
|
||||
$this->assertEquals('USD', $sut->getCustomerDefaultCurrency());
|
||||
$this->assertEquals('RU', $sut->getCustomerDefaultCountry());
|
||||
$this->assertEquals('USD', $sut->getUserDefaultCurrency());
|
||||
$this->assertEquals('RU', $sut->getUserDefaultLanguage());
|
||||
$this->assertEquals('black', $sut->getUserDefaultTheme());
|
||||
$this->assertEquals('Russia/Moscov', $sut->getUserDefaultTimezone());
|
||||
$this->assertEquals('Russia/Moscov', $sut->find('defaults.user.timezone'));
|
||||
}
|
||||
|
||||
public function testDefaultWithMixedConfigs()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), [
|
||||
(new Configuration())->setName('defaults.customer.country')->setValue('RU'),
|
||||
(new Configuration())->setName('defaults.customer.foobar')->setValue('hello'),
|
||||
]);
|
||||
$this->assertEquals('Europe/London', $sut->getCustomerDefaultTimezone());
|
||||
$this->assertEquals('GBP', $sut->getCustomerDefaultCurrency());
|
||||
$this->assertEquals('RU', $sut->getCustomerDefaultCountry());
|
||||
}
|
||||
|
||||
public function testFindByKey()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
$this->assertEquals('FR', $sut->find('customer.country'));
|
||||
$this->assertEquals('FR', $sut->find('defaults.customer.country'));
|
||||
}
|
||||
|
||||
public function testUnknownConfigAreImported()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), [
|
||||
(new Configuration())->setName('defaults.customer.foobar')->setValue('hello'),
|
||||
]);
|
||||
$this->assertEquals('hello', $sut->find('customer.foobar'));
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
namespace App\Tests\Configuration;
|
||||
|
||||
use App\Configuration\LdapConfiguration;
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Tests\Mocks\SystemConfigurationFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -21,7 +21,7 @@ class LdapConfigurationTest extends TestCase
|
||||
{
|
||||
protected function getSut(array $settings)
|
||||
{
|
||||
$systemConfig = new SystemConfiguration(new TestConfigLoader([]), ['ldap' => $settings]);
|
||||
$systemConfig = SystemConfigurationFactory::create(new TestConfigLoader([]), ['ldap' => $settings]);
|
||||
|
||||
return new LdapConfiguration($systemConfig);
|
||||
}
|
||||
|
||||
@@ -9,81 +9,70 @@
|
||||
|
||||
namespace App\Tests\Configuration;
|
||||
|
||||
use App\Configuration\LanguageFormattings;
|
||||
use App\Configuration\LocaleService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Configuration\LanguageFormattings
|
||||
* @covers \App\Configuration\LocaleService
|
||||
*/
|
||||
class LanguageFormattingsTest extends TestCase
|
||||
class LocaleServiceTest extends TestCase
|
||||
{
|
||||
protected function getSut(array $settings)
|
||||
{
|
||||
return new LanguageFormattings($settings);
|
||||
return new LocaleService($settings);
|
||||
}
|
||||
|
||||
protected function getDefaultSettings()
|
||||
{
|
||||
return [
|
||||
'de' => [
|
||||
'date_type' => 'dd.MM.yyyy',
|
||||
'date' => 'd.m.Y',
|
||||
'date_time' => 'd.m. H:i',
|
||||
'duration' => '%h:%m h',
|
||||
'duration' => '%h:%m',
|
||||
'time' => 'H:i',
|
||||
],
|
||||
'en' => [
|
||||
'date_type' => 'yyyy-MM-dd',
|
||||
'date' => 'Y-m-d',
|
||||
'date_time' => 'm-d H:i',
|
||||
'duration' => '%h:%m h',
|
||||
'duration' => '%h:%m',
|
||||
'time' => 'H:i:s',
|
||||
],
|
||||
'pt_BR' => [
|
||||
'date_type' => 'dd-MM-yyyy',
|
||||
'date' => 'd-m-Y',
|
||||
'duration' => '%h:%m h',
|
||||
'duration' => '%h:%m',
|
||||
],
|
||||
'it' => [
|
||||
'date_type' => 'dd.MM.yyyy',
|
||||
'date' => 'd.m.Y',
|
||||
'duration' => '%h:%m h',
|
||||
'duration' => '%h:%m',
|
||||
],
|
||||
'fr' => [
|
||||
'date_type' => 'dd/MM/yyyy',
|
||||
'date' => 'd/m/Y',
|
||||
'duration' => '%h h %m',
|
||||
],
|
||||
'es' => [
|
||||
'date_type' => 'dd.MM.yyyy',
|
||||
'date' => 'd.m.Y',
|
||||
'duration' => '%h:%m h',
|
||||
'duration' => '%h:%m',
|
||||
],
|
||||
'ru' => [
|
||||
'date_type' => 'dd.MM.yyyy',
|
||||
'date' => 'd.m.Y',
|
||||
'duration' => '%h:%m h',
|
||||
'duration' => '%h:%m',
|
||||
],
|
||||
'ar' => [
|
||||
'date_type' => 'yyyy-MM-dd',
|
||||
'date' => 'Y-m-d',
|
||||
'duration' => '%h:%m h',
|
||||
'duration' => '%h:%m',
|
||||
],
|
||||
'hu' => [
|
||||
'date_type' => 'yyyy.MM.dd',
|
||||
'date' => 'Y.m.d.',
|
||||
'duration' => '%h:%m h',
|
||||
'duration' => '%h:%m',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetAvailableLanguages()
|
||||
public function testGetAllLocales()
|
||||
{
|
||||
$sut = $this->getSut([]);
|
||||
$this->assertEquals([], $sut->getAvailableLanguages());
|
||||
$this->assertEquals([], $sut->getAllLocales());
|
||||
|
||||
$sut = $this->getSut($this->getDefaultSettings());
|
||||
$this->assertEquals(['de', 'en', 'pt_BR', 'it', 'fr', 'es', 'ru', 'ar', 'hu'], $sut->getAvailableLanguages());
|
||||
$this->assertEquals(['de', 'en', 'pt_BR', 'it', 'fr', 'es', 'ru', 'ar', 'hu'], $sut->getAllLocales());
|
||||
}
|
||||
|
||||
public function testInvalidLocaleWithGivenLocale()
|
||||
@@ -98,7 +87,7 @@ class LanguageFormattingsTest extends TestCase
|
||||
public function testGetDurationFormat()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings());
|
||||
$this->assertEquals('%h:%m h', $sut->getDurationFormat('de'));
|
||||
$this->assertEquals('%h:%m', $sut->getDurationFormat('de'));
|
||||
}
|
||||
|
||||
public function testGetDateFormat()
|
||||
@@ -110,19 +99,7 @@ class LanguageFormattingsTest extends TestCase
|
||||
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'));
|
||||
$this->assertEquals('d.m.Y H:i', $sut->getDateTimeFormat('de'));
|
||||
}
|
||||
|
||||
public function testGetTimeFormat()
|
||||
@@ -10,7 +10,7 @@
|
||||
namespace App\Tests\Configuration;
|
||||
|
||||
use App\Configuration\SamlConfiguration;
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Tests\Mocks\SystemConfigurationFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -21,7 +21,7 @@ class SamlConfigurationTest extends TestCase
|
||||
{
|
||||
protected function getSut(array $settings)
|
||||
{
|
||||
$systemConfig = new SystemConfiguration(new TestConfigLoader([]), ['saml' => $settings]);
|
||||
$systemConfig = SystemConfigurationFactory::create(new TestConfigLoader([]), ['saml' => $settings]);
|
||||
|
||||
return new SamlConfiguration($systemConfig);
|
||||
}
|
||||
@@ -31,6 +31,7 @@ class SamlConfigurationTest extends TestCase
|
||||
return [
|
||||
'activate' => true,
|
||||
'title' => 'SAML title',
|
||||
'provider' => 'google',
|
||||
'connection' => [
|
||||
'host' => '1.2.3.4',
|
||||
],
|
||||
@@ -40,6 +41,7 @@ class SamlConfigurationTest extends TestCase
|
||||
],
|
||||
'roles' => [
|
||||
'attribute' => 'Roles',
|
||||
'resetOnLogin' => true,
|
||||
'mapping' => [
|
||||
['saml' => 'Kimai - Admin', 'kimai' => 'ROLE_SUPER_ADMIN'],
|
||||
['saml' => 'Management', 'kimai' => 'ROLE_TEAMLEAD'],
|
||||
@@ -57,13 +59,16 @@ class SamlConfigurationTest extends TestCase
|
||||
$this->assertEquals([], $sut->getRolesMapping());
|
||||
$this->assertEquals('', $sut->getRolesAttribute());
|
||||
$this->assertEquals([], $sut->getAttributeMapping());
|
||||
$this->assertFalse($sut->isRolesResetOnLogin());
|
||||
}
|
||||
|
||||
public function testDefaultSettings()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings());
|
||||
$this->assertTrue($sut->isActivated());
|
||||
$this->assertTrue($sut->isRolesResetOnLogin());
|
||||
$this->assertEquals('SAML title', $sut->getTitle());
|
||||
$this->assertEquals('google', $sut->getProvider());
|
||||
$this->assertEquals([
|
||||
'host' => '1.2.3.4',
|
||||
], $sut->getConnection());
|
||||
|
||||
@@ -11,11 +11,11 @@ namespace App\Tests\Configuration;
|
||||
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Entity\Configuration;
|
||||
use App\Tests\Mocks\SystemConfigurationFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Configuration\SystemConfiguration
|
||||
* @covers \App\Configuration\StringAccessibleConfigTrait
|
||||
*/
|
||||
class SystemConfigurationTest extends TestCase
|
||||
{
|
||||
@@ -28,7 +28,7 @@ class SystemConfigurationTest extends TestCase
|
||||
{
|
||||
$loader = new TestConfigLoader($loaderSettings);
|
||||
|
||||
return new SystemConfiguration($loader, $settings);
|
||||
return SystemConfigurationFactory::create($loader, $settings);
|
||||
}
|
||||
|
||||
protected function getDefaultSettings()
|
||||
@@ -42,11 +42,10 @@ class SystemConfigurationTest extends TestCase
|
||||
'lockdown_period_end' => null,
|
||||
'lockdown_grace_period' => null,
|
||||
],
|
||||
'mode' => 'duration_only',
|
||||
'mode' => 'punch',
|
||||
'markdown_content' => false,
|
||||
'active_entries' => [
|
||||
'hard_limit' => 99,
|
||||
'soft_limit' => 15,
|
||||
],
|
||||
'default_begin' => 'now',
|
||||
'duration_increment' => 10,
|
||||
@@ -67,7 +66,6 @@ class SystemConfigurationTest extends TestCase
|
||||
],
|
||||
'calendar' => [
|
||||
'businessHours' => [
|
||||
'days' => [2, 4, 6],
|
||||
'begin' => '07:49',
|
||||
'end' => '19:27'
|
||||
],
|
||||
@@ -100,13 +98,9 @@ class SystemConfigurationTest extends TestCase
|
||||
'theme' => [
|
||||
'color_choices' => 'Maroon|#800000,Brown|#a52a2a,Red|#ff0000,Orange|#ffa500,#ffffff,,|#000000',
|
||||
'colors_limited' => true,
|
||||
'tags_create' => true,
|
||||
'branding' => [
|
||||
'logo' => null,
|
||||
'mini' => null,
|
||||
'company' => 'Acme Corp.',
|
||||
'title' => 'Fantastic Time-Tracking',
|
||||
'translation' => null,
|
||||
],
|
||||
],
|
||||
];
|
||||
@@ -126,16 +120,9 @@ class SystemConfigurationTest extends TestCase
|
||||
(new Configuration())->setName('timesheet.markdown_content')->setValue('1'),
|
||||
(new Configuration())->setName('timesheet.default_begin')->setValue('07:00'),
|
||||
(new Configuration())->setName('timesheet.active_entries.hard_limit')->setValue('7'),
|
||||
(new Configuration())->setName('theme.colors_limited')->setValue(false),
|
||||
];
|
||||
}
|
||||
|
||||
public function testPrefix()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
$this->assertEquals('kimai', $sut->getPrefix());
|
||||
}
|
||||
|
||||
public function testDefaultWithoutLoader()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
@@ -143,11 +130,7 @@ class SystemConfigurationTest extends TestCase
|
||||
$this->assertEquals('GBP', $sut->find('defaults.customer.currency'));
|
||||
$this->assertFalse($sut->find('timesheet.rules.allow_future_times'));
|
||||
$this->assertEquals(99, $sut->find('timesheet.active_entries.hard_limit'));
|
||||
$this->assertTrue($sut->find('theme.colors_limited'));
|
||||
$this->assertTrue($sut->isThemeColorsLimited());
|
||||
$this->assertEquals('Maroon|#800000,Brown|#a52a2a,Red|#ff0000,Orange|#ffa500,#ffffff,,|#000000', $sut->getThemeColorChoices());
|
||||
$this->assertEquals('Fantastic Time-Tracking', $sut->getBrandingTitle());
|
||||
$this->assertTrue($sut->isAllowTagCreation());
|
||||
}
|
||||
|
||||
public function testDefaultWithLoader()
|
||||
@@ -158,8 +141,6 @@ class SystemConfigurationTest extends TestCase
|
||||
$this->assertTrue($sut->find('timesheet.rules.allow_future_times'));
|
||||
$this->assertEquals(7, $sut->find('timesheet.active_entries.hard_limit'));
|
||||
$this->assertFalse($sut->isSamlActive());
|
||||
$this->assertFalse($sut->find('theme.colors_limited'));
|
||||
$this->assertEquals('Europe/London', $sut->default('defaults.customer.timezone'));
|
||||
}
|
||||
|
||||
public function testDefaultWithMixedConfigs()
|
||||
@@ -172,24 +153,45 @@ class SystemConfigurationTest extends TestCase
|
||||
]);
|
||||
$this->assertFalse($sut->find('timesheet.rules.allow_future_times'));
|
||||
$this->assertTrue($sut->isSamlActive());
|
||||
$this->assertEquals('Maroon|#800000,Brown|#a52a2a,Red|#ff0000,Orange|#ffa500,#ffffff,,|#000000', $sut->getThemeColorChoices());
|
||||
$this->assertEquals('Silver|#c0c0c0', $sut->getThemeColorChoices());
|
||||
$this->assertEquals('2020-03-27', $sut->getFinancialYearStart());
|
||||
}
|
||||
|
||||
public function testOffsetUnsetThrowsException()
|
||||
{
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
$this->expectExceptionMessage('SystemBundleConfiguration does not support offsetUnset()');
|
||||
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
$sut->offsetUnset('dfsdf');
|
||||
}
|
||||
|
||||
public function testUnknownConfigs()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), [
|
||||
(new Configuration())->setName('timesheet.foo')->setValue('hello'),
|
||||
]);
|
||||
$this->assertEquals('hello', $sut->find('timesheet.foo'));
|
||||
$this->assertEquals('hello', $sut->offsetGet('timesheet.foo'));
|
||||
$this->assertTrue($sut->has('timesheet.foo'));
|
||||
$this->assertTrue($sut->offsetExists('timesheet.foo'));
|
||||
$this->assertFalse($sut->has('timesheet.yyyyyyyyy'));
|
||||
$this->assertFalse($sut->offsetExists('timesheet.yyyyyyyyy'));
|
||||
$this->assertFalse($sut->has('xxxxxxxx.yyyyyyyyy'));
|
||||
$this->assertFalse($sut->offsetExists('xxxxxxxx.yyyyyyyyy'));
|
||||
$this->assertNull($sut->find('xxxxxxxx.yyyyyyyyy'));
|
||||
$this->assertNull($sut->offsetGet('xxxxxxxx.yyyyyyyyy'));
|
||||
|
||||
$sut->offsetSet('xxxxxxxx.yyyyyyyyy', 'foooo-bar!');
|
||||
$this->assertTrue($sut->has('xxxxxxxx.yyyyyyyyy'));
|
||||
$this->assertTrue($sut->offsetExists('xxxxxxxx.yyyyyyyyy'));
|
||||
$this->assertEquals('foooo-bar!', $sut->find('xxxxxxxx.yyyyyyyyy'));
|
||||
$this->assertEquals('foooo-bar!', $sut->offsetGet('xxxxxxxx.yyyyyyyyy'));
|
||||
}
|
||||
|
||||
public function testCalendarWithoutLoader()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
$this->assertEquals([2, 4, 6], $sut->getCalendarBusinessDays());
|
||||
$this->assertEquals('07:49', $sut->getCalendarBusinessTimeBegin());
|
||||
$this->assertEquals('19:27', $sut->getCalendarBusinessTimeEnd());
|
||||
$this->assertEquals('06:00:00', $sut->getCalendarTimeframeBegin());
|
||||
@@ -243,12 +245,8 @@ class SystemConfigurationTest extends TestCase
|
||||
$this->assertEquals(99, $sut->getTimesheetActiveEntriesHardLimit());
|
||||
$this->assertFalse($sut->isTimesheetAllowFutureTimes());
|
||||
$this->assertFalse($sut->isTimesheetMarkdownEnabled());
|
||||
$this->assertEquals('duration_only', $sut->getTimesheetTrackingMode());
|
||||
$this->assertEquals('punch', $sut->getTimesheetTrackingMode());
|
||||
$this->assertEquals('now', $sut->getTimesheetDefaultBeginTime());
|
||||
$this->assertFalse($sut->isTimesheetLockdownActive());
|
||||
$this->assertEquals('', $sut->getTimesheetLockdownPeriodStart());
|
||||
$this->assertEquals('', $sut->getTimesheetLockdownPeriodEnd());
|
||||
$this->assertEquals('', $sut->getTimesheetLockdownGracePeriod());
|
||||
$this->assertEquals('', $sut->isTimesheetAllowOverlappingRecords());
|
||||
$this->assertEquals('', $sut->getTimesheetDefaultRoundingDays());
|
||||
$this->assertEquals('', $sut->getTimesheetDefaultRoundingMode());
|
||||
@@ -256,17 +254,7 @@ class SystemConfigurationTest extends TestCase
|
||||
$this->assertEquals(0, $sut->getTimesheetDefaultRoundingEnd());
|
||||
$this->assertEquals(0, $sut->getTimesheetDefaultRoundingBegin());
|
||||
$this->assertEquals(10, $sut->getTimesheetIncrementDuration());
|
||||
$this->assertEquals(5, $sut->getTimesheetIncrementBegin());
|
||||
$this->assertEquals(5, $sut->getTimesheetIncrementEnd());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testDeprecatedSettingsWithoutLoader()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
$this->assertEquals(99, $sut->getTimesheetActiveEntriesSoftLimit());
|
||||
$this->assertEquals(5, $sut->getTimesheetIncrementMinutes());
|
||||
}
|
||||
|
||||
public function testTimesheetWithLoader()
|
||||
@@ -277,10 +265,6 @@ class SystemConfigurationTest extends TestCase
|
||||
$this->assertTrue($sut->isTimesheetMarkdownEnabled());
|
||||
$this->assertEquals('default', $sut->getTimesheetTrackingMode());
|
||||
$this->assertEquals('07:00', $sut->getTimesheetDefaultBeginTime());
|
||||
$this->assertTrue($sut->isTimesheetLockdownActive());
|
||||
$this->assertEquals('first day of last month', $sut->getTimesheetLockdownPeriodStart());
|
||||
$this->assertEquals('last day of last month', $sut->getTimesheetLockdownPeriodEnd());
|
||||
$this->assertEquals('+5 days', $sut->getTimesheetLockdownGracePeriod());
|
||||
$this->assertEquals('', $sut->isTimesheetAllowOverlappingRecords());
|
||||
$this->assertEquals('', $sut->getTimesheetDefaultRoundingDays());
|
||||
$this->assertEquals('', $sut->getTimesheetDefaultRoundingMode());
|
||||
@@ -288,7 +272,6 @@ class SystemConfigurationTest extends TestCase
|
||||
$this->assertEquals(0, $sut->getTimesheetDefaultRoundingEnd());
|
||||
$this->assertEquals(0, $sut->getTimesheetDefaultRoundingBegin());
|
||||
$this->assertEquals(10, $sut->getTimesheetIncrementDuration());
|
||||
$this->assertEquals(5, $sut->getTimesheetIncrementBegin());
|
||||
$this->assertEquals(5, $sut->getTimesheetIncrementEnd());
|
||||
$this->assertEquals(5, $sut->getTimesheetIncrementMinutes());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,10 @@ use App\Entity\Configuration;
|
||||
*/
|
||||
class TestConfigLoader implements ConfigLoaderInterface
|
||||
{
|
||||
private $configs = [];
|
||||
/**
|
||||
* @var Configuration[]
|
||||
*/
|
||||
private array $configs;
|
||||
|
||||
/**
|
||||
* @param Configuration[] $configs
|
||||
@@ -27,11 +30,19 @@ class TestConfigLoader implements ConfigLoaderInterface
|
||||
$this->configs = $configs;
|
||||
}
|
||||
|
||||
public function getConfiguration(string $name): ?Configuration
|
||||
{
|
||||
if (!\array_key_exists($name, $this->configs)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->configs[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|string $prefix
|
||||
* @return Configuration[]
|
||||
*/
|
||||
public function getConfiguration(?string $prefix = null): array
|
||||
public function getConfigurations(): array
|
||||
{
|
||||
return $this->configs;
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
<?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\SystemConfiguration;
|
||||
use App\Configuration\ThemeConfiguration;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Configuration\ThemeConfiguration
|
||||
* @covers \App\Configuration\SystemConfiguration
|
||||
*/
|
||||
class ThemeConfigurationTest extends TestCase
|
||||
{
|
||||
protected function getSut(array $settings, array $loaderSettings = []): ThemeConfiguration
|
||||
{
|
||||
$loader = new TestConfigLoader($loaderSettings);
|
||||
$config = new SystemConfiguration($loader, ['theme' => $settings]);
|
||||
|
||||
return new ThemeConfiguration($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getDefaultSettings()
|
||||
{
|
||||
return [
|
||||
'active_warning' => 3,
|
||||
'box_color' => 'green',
|
||||
'select_type' => null,
|
||||
'show_about' => true,
|
||||
'chart' => [
|
||||
'background_color' => 'rgba(0,115,183,0.7)',
|
||||
'border_color' => '#3b8bba',
|
||||
'grid_color' => 'rgba(0,0,0,.05)',
|
||||
'height' => '200'
|
||||
],
|
||||
'branding' => [
|
||||
'logo' => null,
|
||||
'mini' => null,
|
||||
'company' => null,
|
||||
'title' => null,
|
||||
],
|
||||
'tags_create' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testDeprecations()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
$this->assertTrue($sut->isAllowTagCreation());
|
||||
$this->assertNull($sut->getTitle());
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
<?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\SystemConfiguration;
|
||||
use App\Configuration\TimesheetConfiguration;
|
||||
use App\Entity\Configuration;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Configuration\TimesheetConfiguration
|
||||
* @group legacy
|
||||
*/
|
||||
class TimesheetConfigurationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param array $settings
|
||||
* @param array $loaderSettings
|
||||
* @return TimesheetConfiguration
|
||||
*/
|
||||
protected function getSut(array $settings, array $loaderSettings = [])
|
||||
{
|
||||
$loader = new TestConfigLoader($loaderSettings);
|
||||
|
||||
$config = new SystemConfiguration($loader, ['timesheet' => $settings]);
|
||||
|
||||
return new TimesheetConfiguration($config);
|
||||
}
|
||||
|
||||
protected function getDefaultSettings()
|
||||
{
|
||||
return [
|
||||
'rules' => [
|
||||
'allow_future_times' => false,
|
||||
'lockdown_period_start' => null,
|
||||
'lockdown_period_end' => null,
|
||||
'lockdown_grace_period' => null,
|
||||
],
|
||||
'mode' => 'duration_only',
|
||||
'markdown_content' => false,
|
||||
'active_entries' => [
|
||||
'hard_limit' => 99,
|
||||
],
|
||||
'default_begin' => 'now',
|
||||
];
|
||||
}
|
||||
|
||||
protected function getDefaultLoaderSettings()
|
||||
{
|
||||
return [
|
||||
(new Configuration())->setName('timesheet.rules.allow_future_times')->setValue('1'),
|
||||
(new Configuration())->setName('timesheet.rules.lockdown_period_start')->setValue('first day of last month'),
|
||||
(new Configuration())->setName('timesheet.rules.lockdown_period_end')->setValue('last day of last month'),
|
||||
(new Configuration())->setName('timesheet.rules.lockdown_grace_period')->setValue('+5 days'),
|
||||
(new Configuration())->setName('timesheet.mode')->setValue('default'),
|
||||
(new Configuration())->setName('timesheet.markdown_content')->setValue('1'),
|
||||
(new Configuration())->setName('timesheet.default_begin')->setValue('07:00'),
|
||||
(new Configuration())->setName('timesheet.active_entries.hard_limit')->setValue('7'),
|
||||
];
|
||||
}
|
||||
|
||||
public function testPrefix()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
$this->assertEquals('timesheet', $sut->getPrefix());
|
||||
}
|
||||
|
||||
public function testDefaultWithoutLoader()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
|
||||
$this->assertEquals(99, $sut->getActiveEntriesHardLimit());
|
||||
$this->assertEquals(99, $sut->getActiveEntriesSoftLimit());
|
||||
$this->assertFalse($sut->isAllowFutureTimes());
|
||||
$this->assertFalse($sut->isMarkdownEnabled());
|
||||
$this->assertEquals('duration_only', $sut->getTrackingMode());
|
||||
$this->assertEquals('now', $sut->getDefaultBeginTime());
|
||||
$this->assertFalse($sut->isLockdownActive());
|
||||
$this->assertEquals('', $sut->getLockdownPeriodStart());
|
||||
$this->assertEquals('', $sut->getLockdownPeriodEnd());
|
||||
$this->assertEquals('', $sut->getLockdownGracePeriod());
|
||||
$this->assertEquals('', $sut->isAllowOverlappingRecords());
|
||||
$this->assertEquals('', $sut->getDefaultRoundingDays());
|
||||
$this->assertEquals('', $sut->getDefaultRoundingMode());
|
||||
$this->assertEquals(0, $sut->getDefaultRoundingBegin());
|
||||
$this->assertEquals(0, $sut->getDefaultRoundingEnd());
|
||||
$this->assertEquals(0, $sut->getDefaultRoundingDuration());
|
||||
}
|
||||
|
||||
public function testDefaultWithLoader()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), $this->getDefaultLoaderSettings());
|
||||
$this->assertEquals(7, $sut->getActiveEntriesHardLimit());
|
||||
$this->assertEquals(7, $sut->getActiveEntriesSoftLimit());
|
||||
$this->assertTrue($sut->isAllowFutureTimes());
|
||||
$this->assertTrue($sut->isMarkdownEnabled());
|
||||
$this->assertEquals('default', $sut->getTrackingMode());
|
||||
$this->assertEquals('07:00', $sut->getDefaultBeginTime());
|
||||
$this->assertTrue($sut->isLockdownActive());
|
||||
$this->assertEquals('first day of last month', $sut->getLockdownPeriodStart());
|
||||
$this->assertEquals('last day of last month', $sut->getLockdownPeriodEnd());
|
||||
$this->assertEquals('+5 days', $sut->getLockdownGracePeriod());
|
||||
}
|
||||
|
||||
public function testDefaultWithMixedConfigs()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), [
|
||||
(new Configuration())->setName('timesheet.mode')->setValue('sdf'),
|
||||
]);
|
||||
$this->assertEquals('sdf', $sut->getTrackingMode());
|
||||
}
|
||||
|
||||
public function testFindByKey()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
$this->assertFalse($sut->find('rules.allow_future_times'));
|
||||
$this->assertFalse($sut->find('timesheet.rules.allow_future_times'));
|
||||
}
|
||||
|
||||
public function testUnknownConfigAreImported()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), [
|
||||
(new Configuration())->setName('timesheet.foo')->setValue('hello'),
|
||||
]);
|
||||
$this->assertEquals('hello', $sut->find('foo'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user