Merge pull request #17557 from ngo360/master
[civicrm-core.git] / tests / phpunit / CRM / Utils / ColorTest.php
1 <?php
2
3 /**
4 * Class CRM_Utils_ColorTest
5 * @group headless
6 */
7 class CRM_Utils_ColorTest extends CiviUnitTestCase {
8
9 /**
10 * @dataProvider contrastExamples
11 */
12 public function testGetContrast($background, $text) {
13 $this->assertEquals($text, CRM_Utils_Color::getContrast($background));
14 }
15
16 public function contrastExamples() {
17 return [
18 ['ef4444', 'white'],
19 ['FAA31B', 'black'],
20 ['FFF000', 'black'],
21 [' 82c341', 'black'],
22 ['#009F75', 'white'],
23 ['#88C6eD', 'black'],
24 ['# 394ba0', 'white'],
25 [' #D54799', 'white'],
26 ];
27 }
28
29 /**
30 * @dataProvider rgbExamples
31 */
32 public function testGetRgb($color, $expectedRGB, $expectedHex) {
33 $rgb = CRM_Utils_Color::getRgb($color);
34 $this->assertEquals($expectedRGB, $rgb);
35 $this->assertEquals($expectedHex, CRM_Utils_Color::rgbToHex($rgb));
36 }
37
38 public function rgbExamples() {
39 return [
40 ['#fff', [255, 255, 255], '#ffffff'],
41 ['white', [255, 255, 255], '#ffffff'],
42 ['#000000', [0, 0, 0], '#000000'],
43 [' black', [0, 0, 0], '#000000'],
44 [' #111 ', [17, 17, 17], '#111111'],
45 [' fffc99 ', [255, 252, 153], '#fffc99'],
46 ['blue', [0, 0, 255], '#0000ff'],
47 ['Green', [0, 128, 0], '#008000'],
48 ['rgb(12, 0, 123)', [12, 0, 123], '#0c007b'],
49 [' rgb ( 123, 0, 12 ) !important', [123, 0, 12], '#7b000c'],
50 ];
51 }
52
53 }