validate color (#2072)

This commit is contained in:
Kevin Papst
2020-10-28 20:01:08 +01:00
committed by GitHub
parent 82e1d6b917
commit 1444593bbd
8 changed files with 189 additions and 14 deletions

View File

@@ -100,12 +100,17 @@ class ColorTest extends TestCase
$this->assertEquals('#000000', $sut->getFontContrastColor('#ffffff'));
}
public function testGetFontContrastColorThrowsExceptionOnNonHexadecimalColor()
public function testGetFontContrastColorReturnsContrastForDefaultColorOnInvalidColor()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid color code given, only #hexadecimal is supported.');
$sut = new Color();
$sut->getFontContrastColor('000000');
$this->assertEquals('#000000', $sut->getFontContrastColor(''));
$this->assertEquals('#000000', $sut->getFontContrastColor('000000'));
$this->assertEquals('#000000', $sut->getFontContrastColor(Constants::DEFAULT_COLOR));
$this->assertEquals('#000000', $sut->getFontContrastColor('#6'));
$this->assertEquals('#000000', $sut->getFontContrastColor('#66'));
$this->assertEquals('#000000', $sut->getFontContrastColor('#6666'));
$this->assertEquals('#000000', $sut->getFontContrastColor('#cccc'));
$this->assertEquals('#000000', $sut->getFontContrastColor('#ccccc'));
$this->assertEquals('#000000', $sut->getFontContrastColor('#ccccccc'));
}
}