ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  $color = new ilSystemStyleIconColor("id","name","FF0000","description");
16 
17  $this->assertEquals("id",$color->getId());
18  $this->assertEquals("name",$color->getName());
19  $this->assertEquals("FF0000",$color->getColor());
20  $this->assertEquals("description",$color->getDescription());
21  }
22 
23  public function testSetMethods() {
24  $color = new ilSystemStyleIconColor("id","name","FF0000","description");
25 
26  $color->setId("idnew");
27  $color->setName("namenew");
28  $color->setColor("EE0000");
29  $color->setDescription("descriptionnew");
30 
31  $this->assertEquals("idnew",$color->getId());
32  $this->assertEquals("namenew",$color->getName());
33  $this->assertEquals("EE0000",$color->getColor());
34  $this->assertEquals("descriptionnew",$color->getDescription());
35  }
36 
37  public function testLowerCaseColor() {
38  $color = new ilSystemStyleIconColor("id","name","abcdef","description");
39 
40  $this->assertEquals("ABCDEF",$color->getColor());
41  }
42 
43  public function testInvalidColor1() {
44  try{
45  new ilSystemStyleIconColor("id","name","#FF0000","description");
46  $this->assertTrue(false);
47  }catch(ilSystemStyleColorException $e){
48  $this->assertEquals(ilSystemStyleColorException::INVALID_COLOR_EXCEPTION,$e->getCode());
49  }
50  }
51  public function testInvalidColor2() {
52  try{
53  new ilSystemStyleIconColor("id","name","ZZ0000","description");
54  $this->assertTrue(false);
55  }catch(ilSystemStyleColorException $e){
56  $this->assertEquals(ilSystemStyleColorException::INVALID_COLOR_EXCEPTION,$e->getCode());
57  }
58  }
59  public function testInvalidColor3() {
60  try{
61  new ilSystemStyleIconColor("id","name","F00","description");
62  $this->assertTrue(false);
63  }catch(ilSystemStyleColorException $e){
64  $this->assertEquals(ilSystemStyleColorException::INVALID_COLOR_EXCEPTION,$e->getCode());
65  }
66  }
67 
68  public function testGetDominantAspect() {
69  $white = new ilSystemStyleIconColor("id","name","FFFFFF","description");
70  $black = new ilSystemStyleIconColor("id","name","000000","description");
71 
72  $grey = new ilSystemStyleIconColor("id","name","AAAAAA","description");
73  $red = new ilSystemStyleIconColor("id","name","FF0000","description");
74  $green = new ilSystemStyleIconColor("id","name","00FF00","description");
75  $blue = new ilSystemStyleIconColor("id","name","0000FF","description");
76 
77  $this->assertEquals(ilSystemStyleIconColor::GREY,$white->getDominatAspect());
78  $this->assertEquals(ilSystemStyleIconColor::GREY,$black->getDominatAspect());
79  $this->assertEquals(ilSystemStyleIconColor::GREY,$grey->getDominatAspect());
80  $this->assertEquals(ilSystemStyleIconColor::RED,$red->getDominatAspect());
81  $this->assertEquals(ilSystemStyleIconColor::GREEN,$green->getDominatAspect());
82  $this->assertEquals(ilSystemStyleIconColor::BLUE,$blue->getDominatAspect());
83  }
84 
85  public function testGetPerceivedBrightness() {
86  $white = new ilSystemStyleIconColor("id","name","FFFFFF","description");
87  $black = new ilSystemStyleIconColor("id","name","000000","description");
88 
89  $grey = new ilSystemStyleIconColor("id","name","AAAAAA","description");
90  $red = new ilSystemStyleIconColor("id","name","FF0000","description");
91  $green = new ilSystemStyleIconColor("id","name","00FF00","description");
92  $blue = new ilSystemStyleIconColor("id","name","0000FF","description");
93 
94  $this->assertEquals(255,ceil ($white->getPerceivedBrightness()));
95  $this->assertEquals(0,ceil ($black->getPerceivedBrightness()));
96  $this->assertEquals(170,ceil ($grey->getPerceivedBrightness()));
97  $this->assertEquals(140,ceil ($red->getPerceivedBrightness()));
98  $this->assertEquals(196,ceil ($green->getPerceivedBrightness()));
99  $this->assertEquals(87,ceil ($blue->getPerceivedBrightness()));
100  }
101 
102  public function testCompareColors(){
103  $white = new ilSystemStyleIconColor("id","name","FFFFFF","description");
104  $black = new ilSystemStyleIconColor("id","name","000000","description");
105 
106  $grey = new ilSystemStyleIconColor("id","name","AAAAAA","description");
107  $red = new ilSystemStyleIconColor("id","name","FF0000","description");
108  $green = new ilSystemStyleIconColor("id","name","00FF00","description");
109  $blue = new ilSystemStyleIconColor("id","name","0000FF","description");
110 
111  $this->assertEquals(1,ilSystemStyleIconColor::compareColors($white,$black));
112  $this->assertEquals(-1,ilSystemStyleIconColor::compareColors($black,$white));
113  $this->assertEquals(0,ilSystemStyleIconColor::compareColors($grey,$grey));
114 
115  $this->assertEquals(-1,ilSystemStyleIconColor::compareColors($red,$green));
116  $this->assertEquals(1,ilSystemStyleIconColor::compareColors($red,$blue));
117  $this->assertEquals(-1,ilSystemStyleIconColor::compareColors($blue,$green));
118  }
119 }
$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