configs: overwrite via prepend, mode instead of duration_only (#715)

This commit is contained in:
Kevin Papst
2019-04-26 16:14:28 +02:00
committed by GitHub
parent f0f757cf75
commit 32f0d80729
24 changed files with 253 additions and 45 deletions

View File

@@ -38,7 +38,7 @@ class SystemConfigurationTest extends TestCase
'rules' => [
'allow_future_times' => false,
],
'duration_only' => true,
'mode' => 'duration_only',
'markdown_content' => false,
'active_entries' => [
'hard_limit' => 99,
@@ -61,7 +61,7 @@ class SystemConfigurationTest extends TestCase
(new Configuration())->setName('defaults.customer.timezone')->setValue('Russia/Moscov'),
(new Configuration())->setName('defaults.customer.currency')->setValue('RUB'),
(new Configuration())->setName('timesheet.rules.allow_future_times')->setValue('1'),
(new Configuration())->setName('timesheet.duration_only')->setValue('0'),
(new Configuration())->setName('timesheet.mode')->setValue('default'),
(new Configuration())->setName('timesheet.markdown_content')->setValue('1'),
(new Configuration())->setName('timesheet.active_entries.hard_limit')->setValue('7'),
(new Configuration())->setName('timesheet.active_entries.soft_limit')->setValue('3'),
@@ -95,9 +95,9 @@ class SystemConfigurationTest extends TestCase
public function testDefaultWithMixedConfigs()
{
$sut = $this->getSut($this->getDefaultSettings(), [
(new Configuration())->setName('timesheet.duration_only')->setValue(''),
(new Configuration())->setName('timesheet.rules.allow_future_times')->setValue(''),
]);
$this->assertEquals(false, $sut->find('timesheet.duration_only'));
$this->assertEquals(false, $sut->find('timesheet.rules.allow_future_times'));
}
/**

View File

@@ -37,7 +37,7 @@ class TimesheetConfigurationTest extends TestCase
'rules' => [
'allow_future_times' => false,
],
'duration_only' => true,
'mode' => 'duration_only',
'markdown_content' => false,
'active_entries' => [
'hard_limit' => 99,
@@ -50,7 +50,7 @@ class TimesheetConfigurationTest extends TestCase
{
return [
(new Configuration())->setName('timesheet.rules.allow_future_times')->setValue('1'),
(new Configuration())->setName('timesheet.duration_only')->setValue('0'),
(new Configuration())->setName('timesheet.mode')->setValue('default'),
(new Configuration())->setName('timesheet.markdown_content')->setValue('1'),
(new Configuration())->setName('timesheet.active_entries.hard_limit')->setValue('7'),
(new Configuration())->setName('timesheet.active_entries.soft_limit')->setValue('3'),
@@ -86,7 +86,7 @@ class TimesheetConfigurationTest extends TestCase
public function testDefaultWithMixedConfigs()
{
$sut = $this->getSut($this->getDefaultSettings(), [
(new Configuration())->setName('timesheet.duration_only')->setValue(''),
(new Configuration())->setName('timesheet.mode')->setValue('sdf'),
]);
$this->assertEquals(false, $sut->isDurationOnly());
}

View File

@@ -61,7 +61,7 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
$configService = $client->getContainer()->get(SystemConfiguration::class);
$this->assertEquals(false, $configService->find('timesheet.markdown_content'));
$this->assertEquals(false, $configService->find('timesheet.duration_only'));
$this->assertEquals('default', $configService->find('timesheet.mode'));
$this->assertEquals(true, $configService->find('timesheet.rules.allow_future_times'));
$this->assertEquals(3, $configService->find('timesheet.active_entries.hard_limit'));
$this->assertEquals(1, $configService->find('timesheet.active_entries.soft_limit'));
@@ -70,8 +70,8 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
$client->submit($form, [
'system_configuration_form' => [
'configuration' => [
['name' => 'timesheet.mode', 'value' => 'duration_only'],
['name' => 'timesheet.markdown_content', 'value' => 1],
['name' => 'timesheet.duration_only', 'value' => 1],
['name' => 'timesheet.rules.allow_future_times', 'value' => false],
['name' => 'timesheet.active_entries.hard_limit', 'value' => 99],
['name' => 'timesheet.active_entries.soft_limit', 'value' => 77],
@@ -86,7 +86,7 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
$configService = $client->getContainer()->get(SystemConfiguration::class);
$this->assertEquals(true, $configService->find('timesheet.markdown_content'));
$this->assertEquals(true, $configService->find('timesheet.duration_only'));
$this->assertEquals('duration_only', $configService->find('timesheet.mode'));
$this->assertEquals(false, $configService->find('timesheet.rules.allow_future_times'));
$this->assertEquals(99, $configService->find('timesheet.active_entries.hard_limit'));
$this->assertEquals(77, $configService->find('timesheet.active_entries.soft_limit'));
@@ -101,8 +101,8 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
[
'system_configuration_form' => [
'configuration' => [
['name' => 'timesheet.mode', 'value' => 'foo'],
['name' => 'timesheet.markdown_content', 'value' => 1],
['name' => 'timesheet.duration_only', 'value' => 1],
['name' => 'timesheet.rules.allow_future_times', 'value' => 1],
['name' => 'timesheet.active_entries.hard_limit', 'value' => -1],
['name' => 'timesheet.active_entries.soft_limit', 'value' => -1],
@@ -110,10 +110,11 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
]
],
[
'#system_configuration_form_configuration_3_value',
'#system_configuration_form_configuration_4_value',
'#system_configuration_form_configuration_0_value', // mode
'#system_configuration_form_configuration_3_value', // hard_limit
'#system_configuration_form_configuration_4_value', // soft_limit
],
false
true
);
}

View File

@@ -0,0 +1,47 @@
<?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\Twig;
use App\Configuration\ConfigLoaderInterface;
use App\Configuration\TimesheetConfiguration;
use App\Twig\TimesheetConfigExtension;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Twig\TimesheetConfigExtension
*/
class TimesheetConfigExtensionTest extends TestCase
{
public function testGetFunctions()
{
$loader = $this->getMockBuilder(ConfigLoaderInterface::class)->getMock();
$config = new TimesheetConfiguration($loader, ['mode' => 'duration_only']);
$sut = new TimesheetConfigExtension($config);
$filters = $sut->getFunctions();
$this->assertCount(1, $filters);
$this->assertEquals('is_duration_only', $filters[0]->getName());
}
public function testIsDurationOnly()
{
$loader = $this->getMockBuilder(ConfigLoaderInterface::class)->getMock();
$config = new TimesheetConfiguration($loader, ['mode' => 'duration_only']);
$sut = new TimesheetConfigExtension($config);
$this->assertTrue($sut->isDurationOnly());
}
public function testIsNotDurationOnly()
{
$loader = $this->getMockBuilder(ConfigLoaderInterface::class)->getMock();
$config = new TimesheetConfiguration($loader, ['mode' => 'default']);
$sut = new TimesheetConfigExtension($config);
$this->assertFalse($sut->isDurationOnly());
}
}

View File

@@ -36,7 +36,7 @@ class TimesheetValidatorTest extends ConstraintValidatorTestCase
'rules' => [
'allow_future_times' => false,
],
'duration_only' => false,
'mode' => 'default',
]);
return new TimesheetValidator($authMock, $config);