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