ILIAS  release_8 Revision v8.24
ilSystemStyleIconColorTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once('libs/composer/vendor/autoload.php');
22
23use PHPUnit\Framework\TestCase;
24
25class ilSystemStyleIconColorTest extends TestCase
26{
27 public function testConstruct(): void
28 {
29 $color = new ilSystemStyleIconColor('id', 'name', 'FF0000', 'description');
30
31 $this->assertEquals('id', $color->getId());
32 $this->assertEquals('name', $color->getName());
33 $this->assertEquals('FF0000', $color->getColor());
34 $this->assertEquals('description', $color->getDescription());
35 }
36
37 public function testSetMethods(): void
38 {
39 $color = new ilSystemStyleIconColor('id', 'name', 'FF0000', 'description');
40
41 $color->setId('idnew');
42 $color->setName('namenew');
43 $color->setColor('EE0000');
44 $color->setDescription('descriptionnew');
45
46 $this->assertEquals('idnew', $color->getId());
47 $this->assertEquals('namenew', $color->getName());
48 $this->assertEquals('EE0000', $color->getColor());
49 $this->assertEquals('descriptionnew', $color->getDescription());
50 }
51
52 public function testLowerCaseColor(): void
53 {
54 $color = new ilSystemStyleIconColor('id', 'name', 'abcdef', 'description');
55
56 $this->assertEquals('ABCDEF', $color->getColor());
57 }
58
59 public function testInvalidColor1(): void
60 {
61 try {
62 new ilSystemStyleIconColor('id', 'name', '#FF0000', 'description');
63 $this->fail();
65 $this->assertEquals(ilSystemStyleColorException::INVALID_COLOR_EXCEPTION, $e->getCode());
66 }
67 }
68 public function testInvalidColor2(): void
69 {
70 try {
71 new ilSystemStyleIconColor('id', 'name', 'ZZ0000', 'description');
72 $this->fail();
74 $this->assertEquals(ilSystemStyleColorException::INVALID_COLOR_EXCEPTION, $e->getCode());
75 }
76 }
77 public function testValidColor3(): void
78 {
79 try {
80 new ilSystemStyleIconColor('id', 'name', 'F00', 'description');
81 $this->assertTrue(true);
83 $this->fail();
84 }
85 }
86
87 public function testGetDominantAspect(): void
88 {
89 $white = new ilSystemStyleIconColor('id', 'name', 'FFFFFF', 'description');
90 $black = new ilSystemStyleIconColor('id', 'name', '000000', 'description');
91
92 $grey = new ilSystemStyleIconColor('id', 'name', 'AAAAAA', 'description');
93 $red = new ilSystemStyleIconColor('id', 'name', 'FF0000', 'description');
94 $green = new ilSystemStyleIconColor('id', 'name', '00FF00', 'description');
95 $blue = new ilSystemStyleIconColor('id', 'name', '0000FF', 'description');
96
97 $this->assertEquals(ilSystemStyleIconColor::GREY, $white->getDominatAspect());
98 $this->assertEquals(ilSystemStyleIconColor::GREY, $black->getDominatAspect());
99 $this->assertEquals(ilSystemStyleIconColor::GREY, $grey->getDominatAspect());
100 $this->assertEquals(ilSystemStyleIconColor::RED, $red->getDominatAspect());
101 $this->assertEquals(ilSystemStyleIconColor::GREEN, $green->getDominatAspect());
102 $this->assertEquals(ilSystemStyleIconColor::BLUE, $blue->getDominatAspect());
103 }
104
105 public function testGetPerceivedBrightness(): void
106 {
107 $white = new ilSystemStyleIconColor('id', 'name', 'FFFFFF', 'description');
108 $black = new ilSystemStyleIconColor('id', 'name', '000000', 'description');
109
110 $grey = new ilSystemStyleIconColor('id', 'name', 'AAAAAA', 'description');
111 $red = new ilSystemStyleIconColor('id', 'name', 'FF0000', 'description');
112 $green = new ilSystemStyleIconColor('id', 'name', '00FF00', 'description');
113 $blue = new ilSystemStyleIconColor('id', 'name', '0000FF', 'description');
114
115 $this->assertEquals(255, ceil($white->getPerceivedBrightness()));
116 $this->assertEquals(0, ceil($black->getPerceivedBrightness()));
117 $this->assertEquals(170, ceil($grey->getPerceivedBrightness()));
118 $this->assertEquals(140, ceil($red->getPerceivedBrightness()));
119 $this->assertEquals(196, ceil($green->getPerceivedBrightness()));
120 $this->assertEquals(87, ceil($blue->getPerceivedBrightness()));
121 }
122
123 public function testCompareColors(): void
124 {
125 $white = new ilSystemStyleIconColor('id', 'name', 'FFFFFF', 'description');
126 $black = new ilSystemStyleIconColor('id', 'name', '000000', 'description');
127
128 $grey = new ilSystemStyleIconColor('id', 'name', 'AAAAAA', 'description');
129 $red = new ilSystemStyleIconColor('id', 'name', 'FF0000', 'description');
130 $green = new ilSystemStyleIconColor('id', 'name', '00FF00', 'description');
131 $blue = new ilSystemStyleIconColor('id', 'name', '0000FF', 'description');
132
133 $this->assertEquals(1, ilSystemStyleIconColor::compareColors($white, $black));
134 $this->assertEquals(-1, ilSystemStyleIconColor::compareColors($black, $white));
135 $this->assertEquals(0, ilSystemStyleIconColor::compareColors($grey, $grey));
136
137 $this->assertEquals(-1, ilSystemStyleIconColor::compareColors($red, $green));
138 $this->assertEquals(1, ilSystemStyleIconColor::compareColors($red, $blue));
139 $this->assertEquals(-1, ilSystemStyleIconColor::compareColors($blue, $green));
140 }
141}
Class for advanced editing exception handling in ILIAS.
static compareColors(ilSystemStyleIconColor $color1, ilSystemStyleIconColor $color2)
Used to sort colors according to their brightness.