ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilSystemStyleIconColorTest.php
Go to the documentation of this file.
1<?php
2
3include_once("Services/Style/System/classes/Icons/class.ilSystemStyleIconColor.php");
4include_once("Services/Style/System/classes/Exceptions/class.ilSystemStyleColorException.php");
5
6use PHPUnit\Framework\TestCase;
7
13class ilSystemStyleIconColorTest extends TestCase
14{
15 public function testConstruct()
16 {
17 $color = new ilSystemStyleIconColor("id", "name", "FF0000", "description");
18
19 $this->assertEquals("id", $color->getId());
20 $this->assertEquals("name", $color->getName());
21 $this->assertEquals("FF0000", $color->getColor());
22 $this->assertEquals("description", $color->getDescription());
23 }
24
25 public function testSetMethods()
26 {
27 $color = new ilSystemStyleIconColor("id", "name", "FF0000", "description");
28
29 $color->setId("idnew");
30 $color->setName("namenew");
31 $color->setColor("EE0000");
32 $color->setDescription("descriptionnew");
33
34 $this->assertEquals("idnew", $color->getId());
35 $this->assertEquals("namenew", $color->getName());
36 $this->assertEquals("EE0000", $color->getColor());
37 $this->assertEquals("descriptionnew", $color->getDescription());
38 }
39
40 public function testLowerCaseColor()
41 {
42 $color = new ilSystemStyleIconColor("id", "name", "abcdef", "description");
43
44 $this->assertEquals("ABCDEF", $color->getColor());
45 }
46
47 public function testInvalidColor1()
48 {
49 try {
50 new ilSystemStyleIconColor("id", "name", "#FF0000", "description");
51 $this->assertTrue(false);
53 $this->assertEquals(ilSystemStyleColorException::INVALID_COLOR_EXCEPTION, $e->getCode());
54 }
55 }
56 public function testInvalidColor2()
57 {
58 try {
59 new ilSystemStyleIconColor("id", "name", "ZZ0000", "description");
60 $this->assertTrue(false);
62 $this->assertEquals(ilSystemStyleColorException::INVALID_COLOR_EXCEPTION, $e->getCode());
63 }
64 }
65 public function testValidColor3()
66 {
67 try {
68 new ilSystemStyleIconColor("id", "name", "F00", "description");
69 $this->assertTrue(true);
71 $this->assertTrue(false);
72 }
73 }
74
75 public function testGetDominantAspect()
76 {
77 $white = new ilSystemStyleIconColor("id", "name", "FFFFFF", "description");
78 $black = new ilSystemStyleIconColor("id", "name", "000000", "description");
79
80 $grey = new ilSystemStyleIconColor("id", "name", "AAAAAA", "description");
81 $red = new ilSystemStyleIconColor("id", "name", "FF0000", "description");
82 $green = new ilSystemStyleIconColor("id", "name", "00FF00", "description");
83 $blue = new ilSystemStyleIconColor("id", "name", "0000FF", "description");
84
85 $this->assertEquals(ilSystemStyleIconColor::GREY, $white->getDominatAspect());
86 $this->assertEquals(ilSystemStyleIconColor::GREY, $black->getDominatAspect());
87 $this->assertEquals(ilSystemStyleIconColor::GREY, $grey->getDominatAspect());
88 $this->assertEquals(ilSystemStyleIconColor::RED, $red->getDominatAspect());
89 $this->assertEquals(ilSystemStyleIconColor::GREEN, $green->getDominatAspect());
90 $this->assertEquals(ilSystemStyleIconColor::BLUE, $blue->getDominatAspect());
91 }
92
94 {
95 $white = new ilSystemStyleIconColor("id", "name", "FFFFFF", "description");
96 $black = new ilSystemStyleIconColor("id", "name", "000000", "description");
97
98 $grey = new ilSystemStyleIconColor("id", "name", "AAAAAA", "description");
99 $red = new ilSystemStyleIconColor("id", "name", "FF0000", "description");
100 $green = new ilSystemStyleIconColor("id", "name", "00FF00", "description");
101 $blue = new ilSystemStyleIconColor("id", "name", "0000FF", "description");
102
103 $this->assertEquals(255, ceil($white->getPerceivedBrightness()));
104 $this->assertEquals(0, ceil($black->getPerceivedBrightness()));
105 $this->assertEquals(170, ceil($grey->getPerceivedBrightness()));
106 $this->assertEquals(140, ceil($red->getPerceivedBrightness()));
107 $this->assertEquals(196, ceil($green->getPerceivedBrightness()));
108 $this->assertEquals(87, ceil($blue->getPerceivedBrightness()));
109 }
110
111 public function testCompareColors()
112 {
113 $white = new ilSystemStyleIconColor("id", "name", "FFFFFF", "description");
114 $black = new ilSystemStyleIconColor("id", "name", "000000", "description");
115
116 $grey = new ilSystemStyleIconColor("id", "name", "AAAAAA", "description");
117 $red = new ilSystemStyleIconColor("id", "name", "FF0000", "description");
118 $green = new ilSystemStyleIconColor("id", "name", "00FF00", "description");
119 $blue = new ilSystemStyleIconColor("id", "name", "0000FF", "description");
120
121 $this->assertEquals(1, ilSystemStyleIconColor::compareColors($white, $black));
122 $this->assertEquals(-1, ilSystemStyleIconColor::compareColors($black, $white));
123 $this->assertEquals(0, ilSystemStyleIconColor::compareColors($grey, $grey));
124
125 $this->assertEquals(-1, ilSystemStyleIconColor::compareColors($red, $green));
126 $this->assertEquals(1, ilSystemStyleIconColor::compareColors($red, $blue));
127 $this->assertEquals(-1, ilSystemStyleIconColor::compareColors($blue, $green));
128 }
129}
An exception for terminatinating execution or to throw for unit testing.
Class for advanced editing exception handling in ILIAS.
static compareColors(ilSystemStyleIconColor $color1, ilSystemStyleIconColor $color2)
Used to sort colors according to their brightness.