Skip to content

Commit 6e1eb64

Browse files
joshua-salsadigitalJoshua FernandesAlexSkrypnyk
authored
Issue #3415662 by joshua1234511, alex.skrypnyk: Error when trying to mix CT 1.7 colours (#1239)
Co-authored-by: Joshua Fernandes <“[email protected]”> Co-authored-by: Alex Skrypnyk <[email protected]>
1 parent 4b317c4 commit 6e1eb64

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

web/themes/contrib/civictheme/src/Color/CivicthemeColorUtility.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function keywordToHex($value) {
5555
* The origin color.
5656
* @param string|array $mixer
5757
* The color to mix with.
58-
* @param int $range
58+
* @param string|int $range
5959
* Range to apply the mixer color with. From 0 to 100.
6060
*
6161
* @return string
@@ -66,7 +66,13 @@ public static function keywordToHex($value) {
6666
*
6767
* @SuppressWarnings(MissingImport)
6868
*/
69-
public static function mix(string|array $color, string|array $mixer, int $range): string {
69+
public static function mix(string|array $color, string|array $mixer, string|int $range): string {
70+
if (!is_numeric($range)) {
71+
throw new \Exception(sprintf('Numeric value is expected for range, but %s provided.', $range));
72+
}
73+
74+
$range = (int) $range;
75+
7076
$color = static::hexToRgb($color);
7177
$mixer = static::hexToRgb($mixer);
7278
$range = max(0, min($range, 100));

web/themes/contrib/civictheme/tests/src/Unit/CivicthemeColorUtilityUnitTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ public function dataProviderNormalizeHex(): array {
4646
* @dataProvider dataProviderMix
4747
* @SuppressWarnings(PHPMD.StaticAccess)
4848
*/
49-
public function testMix(string $color, string $mixer, int $range, string $expected): void {
49+
public function testMix(string $color, string $mixer, string|int $range, string $expected, string|null $expected_exception_message = NULL): void {
50+
if ($expected_exception_message) {
51+
$this->expectException(\Exception::class);
52+
$this->expectExceptionMessage($expected_exception_message);
53+
}
54+
5055
$actual = CivicthemeColorUtility::mix($color, $mixer, $range);
5156
$this->assertEquals($expected, $actual);
5257
}
@@ -59,6 +64,8 @@ public function dataProviderMix(): array {
5964
['#00698f', '#000', 10, '#005e80'],
6065
['#00698f', '#000', 0, '#00698f'],
6166
['#e6e9eb', '#fff', 80, '#fafafb'],
67+
['#e6e9eb', '#fff', '80', '#fafafb'],
68+
['#00698f', '#000', 'alpha', '#005e80', 'Numeric value is expected for range, but alpha provided.'],
6269
];
6370
}
6471

0 commit comments

Comments
 (0)