allow to pre-define colors to choose from (#2481)
This commit is contained in:
@@ -58,7 +58,7 @@ class StatusControllerTest extends APIControllerBaseTest
|
||||
$this->assertEquals(Constants::VERSION . '-' . Constants::STATUS, $result['semver']);
|
||||
$this->assertEquals(Constants::NAME, $result['name']);
|
||||
$this->assertEquals(
|
||||
'Kimai 2 - ' . Constants::VERSION . ' ' . Constants::STATUS . ' (' . Constants::NAME . ') by Kevin Papst and contributors.',
|
||||
'Kimai - ' . Constants::VERSION . ' ' . Constants::STATUS . ' (' . Constants::NAME . ') by Kevin Papst and contributors.',
|
||||
$result['copyright']
|
||||
);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class UpdateCommandTest extends KernelTestCase
|
||||
self::assertStringContainsString('No migrations to execute.', $result);
|
||||
|
||||
self::assertStringContainsString(
|
||||
sprintf('[OK] Congratulations! Successfully updated Kimai 2 to version %s (%s)', Constants::VERSION, Constants::STATUS),
|
||||
sprintf('[OK] Congratulations! Successfully updated Kimai to version %s (%s)', Constants::VERSION, Constants::STATUS),
|
||||
$result
|
||||
);
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class VersionCommandTest extends KernelTestCase
|
||||
public function getTestData()
|
||||
{
|
||||
return [
|
||||
[[], 'Kimai 2 - ' . Constants::VERSION . ' ' . Constants::STATUS . ' (' . Constants::NAME . ') by Kevin Papst and contributors.'],
|
||||
[[], 'Kimai - ' . Constants::VERSION . ' ' . Constants::STATUS . ' (' . Constants::NAME . ') by Kevin Papst and contributors.'],
|
||||
[['--name' => true], Constants::NAME],
|
||||
[['--candidate' => true], Constants::STATUS],
|
||||
[['--short' => true], Constants::VERSION],
|
||||
|
||||
@@ -96,6 +96,10 @@ class SystemConfigurationTest extends TestCase
|
||||
'activate' => false,
|
||||
'title' => 'Fantastic OAuth login'
|
||||
],
|
||||
'theme' => [
|
||||
'color_choices' => 'Maroon|#800000,Brown|#a52a2a,Red|#ff0000,Orange|#ffa500,#ffffff,,|#000000',
|
||||
'colors_limited' => true
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -114,6 +118,7 @@ class SystemConfigurationTest extends TestCase
|
||||
(new Configuration())->setName('timesheet.default_begin')->setValue('07:00'),
|
||||
(new Configuration())->setName('timesheet.active_entries.hard_limit')->setValue('7'),
|
||||
(new Configuration())->setName('timesheet.active_entries.soft_limit')->setValue('3'),
|
||||
(new Configuration())->setName('theme.colors_limited')->setValue(false),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -130,6 +135,9 @@ 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' => '#ffffff', '#000000' => '#000000'], $sut->getThemeColorChoices());
|
||||
}
|
||||
|
||||
public function testDefaultWithLoader()
|
||||
@@ -140,6 +148,7 @@ 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'));
|
||||
}
|
||||
|
||||
public function testDefaultWithMixedConfigs()
|
||||
@@ -147,9 +156,11 @@ class SystemConfigurationTest extends TestCase
|
||||
$sut = $this->getSut($this->getDefaultSettings(), [
|
||||
(new Configuration())->setName('timesheet.rules.allow_future_times')->setValue(''),
|
||||
(new Configuration())->setName('saml.activate')->setValue(true),
|
||||
(new Configuration())->setName('theme.color_choices')->setValue(''),
|
||||
]);
|
||||
$this->assertFalse($sut->find('timesheet.rules.allow_future_times'));
|
||||
$this->assertTrue($sut->isSamlActive());
|
||||
$this->assertNull($sut->getThemeColorChoices());
|
||||
}
|
||||
|
||||
public function testUnknownConfigs()
|
||||
|
||||
@@ -28,7 +28,7 @@ class ConstantsTest extends TestCase
|
||||
$expectedId = $major * 10000 + $minor * 100 + $patch;
|
||||
|
||||
self::assertEquals('1.14', Constants::VERSION, 'Invalid release number');
|
||||
self::assertEquals('dev', Constants::STATUS, 'Invalid status');
|
||||
self::assertTrue(\in_array(Constants::STATUS, ['dev', 'stable']), 'Invalid status');
|
||||
self::assertEquals($expectedId, Constants::VERSION_ID, 'Invalid version ID');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,6 +174,8 @@ class AppExtensionTest extends TestCase
|
||||
'calendar' => [
|
||||
'background_color' => '#d2d6de',
|
||||
],
|
||||
'colors_limited' => true,
|
||||
'color_choices' => 'Kimai|#d2d6de,Silver|#c0c0c0,Gray|#808080,Black|#000000,Maroon|#800000,Brown|#a52a2a,Red|#ff0000,Orange|#ffa500,Gold|#ffd700,Yellow|#ffff00,Peach|#ffdab9,Khaki|#f0e68c,Olive|#808000,Lime|#00ff00,Jelly|#9acd32,Green|#008000,Teal|#008080,Aqua|#00ffff,LightBlue|#add8e6,DeepSky|#00bfff,Dodger|#1e90ff,Blue|#0000ff,Navy|#000080,Purple|#800080,Fuchsia|#ff00ff,Violet|#ee82ee,Rose|#ffe4e1,Lavender|#E6E6FA'
|
||||
],
|
||||
'kimai.theme.select_type' => 'selectpicker',
|
||||
'kimai.theme.show_about' => true,
|
||||
|
||||
@@ -361,7 +361,9 @@ class ConfigurationTest extends TestCase
|
||||
'tags_create' => true,
|
||||
'calendar' => [
|
||||
'background_color' => '#d2d6de'
|
||||
]
|
||||
],
|
||||
'colors_limited' => true,
|
||||
'color_choices' => 'Kimai|#d2d6de,Silver|#c0c0c0,Gray|#808080,Black|#000000,Maroon|#800000,Brown|#a52a2a,Red|#ff0000,Orange|#ffa500,Gold|#ffd700,Yellow|#ffff00,Peach|#ffdab9,Khaki|#f0e68c,Olive|#808000,Lime|#00ff00,Jelly|#9acd32,Green|#008000,Teal|#008080,Aqua|#00ffff,LightBlue|#add8e6,DeepSky|#00bfff,Dodger|#1e90ff,Blue|#0000ff,Navy|#000080,Purple|#800080,Fuchsia|#ff00ff,Violet|#ee82ee,Rose|#ffe4e1,Lavender|#E6E6FA'
|
||||
],
|
||||
'industry' => [
|
||||
'translation' => null,
|
||||
|
||||
@@ -20,7 +20,7 @@ class KernelTest extends TestCase
|
||||
public function testBuild()
|
||||
{
|
||||
$sut = new Kernel('test', false);
|
||||
$this->assertEquals($sut->getCacheDir(), realpath(__DIR__ . '/../var/cache/test'));
|
||||
$this->assertEquals($sut->getLogDir(), realpath(__DIR__ . '/../var/log'));
|
||||
self::assertStringEndsWith('var/cache/test', $sut->getCacheDir());
|
||||
self::assertStringEndsWith('var/log', $sut->getLogDir());
|
||||
}
|
||||
}
|
||||
|
||||
110
tests/Validator/Constraints/ColorChoicesValidatorTest.php
Normal file
110
tests/Validator/Constraints/ColorChoicesValidatorTest.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?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\ColorChoices;
|
||||
use App\Validator\Constraints\ColorChoicesValidator;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Validator\Constraints\ColorChoicesValidator
|
||||
*/
|
||||
class ColorChoicesValidatorTest extends ConstraintValidatorTestCase
|
||||
{
|
||||
protected function createValidator()
|
||||
{
|
||||
return new ColorChoicesValidator();
|
||||
}
|
||||
|
||||
public function getValidColors()
|
||||
{
|
||||
yield ['#000000'];
|
||||
yield ['#fff000'];
|
||||
yield ['#000aaa'];
|
||||
yield ['#fffaaa'];
|
||||
yield ['Foo|#fffaaa,|#fffaaa,#fffaaa,Bar|#fffaaa,'];
|
||||
yield [''];
|
||||
yield [null];
|
||||
}
|
||||
|
||||
public function testConstraintIsInvalid()
|
||||
{
|
||||
$this->expectException(UnexpectedTypeException::class);
|
||||
|
||||
$this->validator->validate('#000', new NotBlank());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidColors
|
||||
* @param string $color
|
||||
*/
|
||||
public function testConstraintWithValidColor($color)
|
||||
{
|
||||
$constraint = new ColorChoices();
|
||||
$this->validator->validate($color, $constraint);
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function getInvalidColors()
|
||||
{
|
||||
yield ['sdf sdf|#000000', null, 'sdf sdf', '#000000'];
|
||||
yield ['sdfghjklöß.|#aaabbb', null, 'sdfghjklöß.', '#aaabbb'];
|
||||
yield ['abcdefghijklmn|#aaabbb', null, 'abcdefghijklmn', '#aaabbb'];
|
||||
yield ['string', 'string', null];
|
||||
yield ['000', '000', null];
|
||||
yield ['aaa', 'aaa', null];
|
||||
yield ['000000', '000000', null];
|
||||
yield ['fff000', 'fff000', null];
|
||||
yield ['000aaa', '000aaa', null];
|
||||
yield ['fffaaa', 'fffaaa', null];
|
||||
yield ['#f', '#f', null];
|
||||
yield ['#ff', '#ff', null];
|
||||
yield ['#ffdd', '#ffdd', null];
|
||||
yield ['#ffddd', '#ffddd', null];
|
||||
yield ['#ffddddd', '#ffddddd', null];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidColors
|
||||
* @param string $color
|
||||
* @param string|null $invalidColor
|
||||
* @param string|null $invalidName
|
||||
* @param string|null $invalidNameCode
|
||||
*/
|
||||
public function testValidationError(string $color, $invalidColor = null, $invalidName = null, $invalidNameCode = null)
|
||||
{
|
||||
$constraint = new ColorChoices();
|
||||
|
||||
$this->validator->validate($color, $constraint);
|
||||
|
||||
if (null !== $invalidColor) {
|
||||
$this->buildViolation('The given value {{ value }} is not a valid hexadecimal color.')
|
||||
->setParameter('{{ value }}', '"' . $invalidColor . '"')
|
||||
->setCode(ColorChoices::COLOR_CHOICES_ERROR)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
if (null !== $invalidName) {
|
||||
$this->buildViolation('The given value {{ name }} is not a valid color name for {{ color }}. Allowed are {{ max }} characters, given {{ count }}.')
|
||||
->setParameter('{{ color }}', '"' . ($invalidNameCode ?? $color) . '"')
|
||||
->setParameter('{{ max }}', '10')
|
||||
->setParameter('{{ count }}', (string) \strlen($invalidName))
|
||||
->setParameter('{{ name }}', '"' . $invalidName . '"')
|
||||
->setCode(ColorChoices::COLOR_CHOICES_NAME_ERROR)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
if ($invalidColor === null && $invalidName === null) {
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user