added UI configuration for default start-time (#1506)

This commit is contained in:
Kevin Papst
2020-02-28 16:06:00 +01:00
committed by GitHub
parent bf11de82fc
commit ec31d206e2
8 changed files with 199 additions and 2 deletions

View File

@@ -93,6 +93,7 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
'system_configuration_form_timesheet' => [
'configuration' => [
['name' => 'timesheet.mode', 'value' => 'duration_only'],
['name' => 'timesheet.active_entries.default_begin', 'value' => '23:59'],
['name' => 'timesheet.rules.allow_future_times', 'value' => false],
['name' => 'timesheet.active_entries.hard_limit', 'value' => 99],
['name' => 'timesheet.active_entries.soft_limit', 'value' => 77],
@@ -122,6 +123,7 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
'system_configuration_form_timesheet' => [
'configuration' => [
['name' => 'timesheet.mode', 'value' => 'foo'],
['name' => 'timesheet.active_entries.default_begin', 'value' => '23:59'],
['name' => 'timesheet.rules.allow_future_times', 'value' => 1],
['name' => 'timesheet.active_entries.hard_limit', 'value' => -1],
['name' => 'timesheet.active_entries.soft_limit', 'value' => -1],
@@ -130,8 +132,8 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
],
[
'#system_configuration_form_timesheet_configuration_0_value', // mode
'#system_configuration_form_timesheet_configuration_2_value', // hard_limit
'#system_configuration_form_timesheet_configuration_3_value', // soft_limit
'#system_configuration_form_timesheet_configuration_3_value', // hard_limit
'#system_configuration_form_timesheet_configuration_4_value', // soft_limit
],
true
);

View File

@@ -0,0 +1,85 @@
<?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\Validator\Constraints;
use App\Validator\Constraints\DateTimeFormat;
use App\Validator\Constraints\DateTimeFormatValidator;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
/**
* @covers \App\Validator\Constraints\DateTimeFormatValidator
*/
class DateTimeFormatValidatorTest extends ConstraintValidatorTestCase
{
protected function createValidator()
{
return new DateTimeFormatValidator();
}
public function getValidData()
{
return [
['10:00'],
['now'],
['2020-12-31 13:31:29'],
['monday this week 12:44'],
[''], // empty is now
[null], // null is now
];
}
public function testConstraintIsInvalid()
{
$this->expectException(UnexpectedTypeException::class);
$this->validator->validate('foo', new NotBlank());
}
/**
* @dataProvider getValidData
* @param string $input
*/
public function testConstraintWithValidData($input)
{
$constraint = new DateTimeFormat();
$this->validator->validate($input, $constraint);
$this->assertNoViolation();
}
public function getInvalidData()
{
return [
['13-13'],
['3127::00'],
['3127:00:'],
[':3127:00'],
['::3127'],
];
}
/**
* @dataProvider getInvalidData
* @param mixed $input
*/
public function testValidationError($input)
{
$constraint = new DateTimeFormat();
$this->validator->validate($input, $constraint);
$expectedFormat = is_string($input) ? '"' . $input . '"' : $input;
$this->buildViolation('The given value is not a valid datetime format.')
->setCode(DateTimeFormat::INVALID_FORMAT)
->assertRaised();
}
}