1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
<?php
namespace Dompdf\Tests\Css;
use Dompdf\Css\Color;
use Dompdf\Tests\TestCase;
class ColorTest extends TestCase
{
public function validColorProvider(): array
{
return [
// Color names
["red", [1, 0, 0, 1.0]],
["lime", [0, 1, 0, 1.0]],
["blue", [0, 0, 1, 1.0]],
// Hex notation
["#f00", [1, 0, 0, 1.0]],
["#f003", [1, 0, 0, 0.2]],
["#ff0000", [1, 0, 0, 1.0]],
["#ff000033", [1, 0, 0, 0.2]],
["#FFFFFF00", [1, 1, 1, 0.0]],
// Functional rgb syntax (space-separated)
["rgb(255 0 0)", [1, 0, 0, 1.0]],
["rgb(255 0 0/0.2)", [1, 0, 0, 0.2]],
["rgb( 255 0 0 / 0.2 )", [1, 0, 0, 0.2]],
["rgb(100% 0% 0% / 20%)", [1, 0, 0, 0.2]],
["rgba(255 0 0)", [1, 0, 0, 1.0]],
["rgba(255 0 0/0.2)", [1, 0, 0, 0.2]],
// Functional rgb syntax (comma-separated)
["rgb(255, 0, 0)", [1, 0, 0, 1.0]],
["rgb(255, 0, 0, 0.2)", [1, 0, 0, 0.2]],
["rgb( 255,0,0,0.2 )", [1, 0, 0, 0.2]],
["rgb(100%, 0%, 0%, 20%)", [1, 0, 0, 0.2]],
["rgba(255, 0, 0)", [1, 0, 0, 1.0]],
["rgba(255, 0, 0, 0.2)", [1, 0, 0, 0.2]],
];
}
/**
* @dataProvider validColorProvider
*/
public function testParseColor(string $value, array $expected): void
{
$color = Color::parse($value);
if (!is_array($color)) {
$this->fail("Failed to parse valid color declaration");
}
[$r, $g, $b] = $color;
$alpha = $color["alpha"];
$this->assertEquals($expected, [$r, $g, $b, $alpha]);
}
}
|