improve color chooser and name validation (#2622)

This commit is contained in:
Kevin Papst
2021-06-25 16:35:16 +02:00
committed by GitHub
parent 0d5e0b3e80
commit 3d1fba650b
11 changed files with 77 additions and 40 deletions

View File

@@ -136,7 +136,7 @@ class SystemConfigurationTest extends TestCase
$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());
$this->assertEquals('Maroon|#800000,Brown|#a52a2a,Red|#ff0000,Orange|#ffa500,#ffffff,,|#000000', $sut->getThemeColorChoices());
}
public function testDefaultWithLoader()
@@ -148,6 +148,7 @@ class SystemConfigurationTest extends TestCase
$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()
@@ -160,7 +161,7 @@ class SystemConfigurationTest extends TestCase
]);
$this->assertFalse($sut->find('timesheet.rules.allow_future_times'));
$this->assertTrue($sut->isSamlActive());
$this->assertNull($sut->getThemeColorChoices());
$this->assertEquals('Maroon|#800000,Brown|#a52a2a,Red|#ff0000,Orange|#ffa500,#ffffff,,|#000000', $sut->getThemeColorChoices());
$this->assertEquals('2020-03-27', $sut->getFinancialYearStart());
}

View File

@@ -175,7 +175,7 @@ class AppExtensionTest extends TestCase
'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'
'color_choices' => '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,

View File

@@ -371,7 +371,7 @@ class ConfigurationTest extends TestCase
'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'
'color_choices' => '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,

View File

@@ -32,6 +32,8 @@ class ColorChoicesValidatorTest extends ConstraintValidatorTestCase
yield ['#000aaa'];
yield ['#fffaaa'];
yield ['Foo|#fffaaa,|#fffaaa,#fffaaa,Bar|#fffaaa,'];
yield ['Fo o - sdsd|#fffaaa'];
yield ['abcdefghijklmnopqrst|#fffaaa'];
yield [''];
yield [null];
}
@@ -56,9 +58,9 @@ class ColorChoicesValidatorTest extends ConstraintValidatorTestCase
public function getInvalidColors()
{
yield ['sdf sdf|#000000', null, 'sdf sdf', '#000000'];
yield ['sdf_sdf|#000000', null, 'sdf_sdf', '#000000'];
yield ['sdfghjklöß.|#aaabbb', null, 'sdfghjklöß.', '#aaabbb'];
yield ['abcdefghijklmn|#aaabbb', null, 'abcdefghijklmn', '#aaabbb'];
yield ['abcdefghijklmnopqrstu|#aaabbb', null, 'abcdefghijklmnopqrstu', '#aaabbb'];
yield ['string', 'string', null];
yield ['000', '000', null];
yield ['aaa', 'aaa', null];
@@ -94,10 +96,10 @@ class ColorChoicesValidatorTest extends ConstraintValidatorTestCase
}
if (null !== $invalidName) {
$this->buildViolation('The given value {{ name }} is not a valid color name for {{ color }}. Allowed are {{ max }} characters, given {{ count }}.')
$this->buildViolation('The given value {{ name }} is not a valid color name for {{ color }}. Allowed are {{ max }} alpha-numerical characters, including minus and space.')
->setParameter('{{ color }}', '"' . ($invalidNameCode ?? $color) . '"')
->setParameter('{{ max }}', '10')
->setParameter('{{ count }}', (string) \strlen($invalidName))
->setParameter('{{ max }}', (string) $constraint->maxLength)
->setParameter('{{ count }}', (string) mb_strlen($invalidName))
->setParameter('{{ name }}', '"' . $invalidName . '"')
->setCode(ColorChoices::COLOR_CHOICES_NAME_ERROR)
->assertRaised();