ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilSystemStyleIconColorSetTest.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/Icons/class.ilSystemStyleIconColorSet.php");
5 include_once("Services/Style/System/classes/Exceptions/class.ilSystemStyleColorException.php");
6 include_once("Services/Style/System/classes/Exceptions/class.ilSystemStyleException.php");
7 
8 
15 
16  public function testConstruct() {
17  $set = new ilSystemStyleIconColorSet();
18 
19  $this->assertEquals([],$set->getColors());
20  }
21 
22  public function testAddColor() {
23  $color1 = new ilSystemStyleIconColor("id1","name","FF0000","description");
24  $color2 = new ilSystemStyleIconColor("id2","name","FF0000","description");
25 
26  $set = new ilSystemStyleIconColorSet();
27 
28  $this->assertEquals([],$set->getColors());
29 
30  $set->addColor($color1);
31 
32  $this->assertEquals(1,count($set->getColors()));
33  $this->assertEquals($color1,$set->getColorById("id1"));
34 
35  $set->addColor($color2);
36  $this->assertEquals(2,count($set->getColors()));
37  $this->assertEquals($color1,$set->getColorById("id1"));
38  $this->assertEquals($color2,$set->getColorById("id2"));
39 
40  $set->addColor($color2);
41  $this->assertEquals(2,count($set->getColors()));
42  $this->assertEquals($color1,$set->getColorById("id1"));
43  $this->assertEquals($color2,$set->getColorById("id2"));
44  }
45 
46  public function testGetInvalidId(){
47  $color1 = new ilSystemStyleIconColor("id1","name","FF0000","description");
48  $set = new ilSystemStyleIconColorSet();
49  $set->addColor($color1);
50 
51  try{
52  $set->getColorById("idXY");
53  $this->assertTrue(false);
54  }catch(ilSystemStyleException $e){
55  $this->assertEquals(ilSystemStyleException::INVALID_ID,$e->getCode());
56  }
57 
58  }
59 
60  public function testDoesColorExist(){
61  $color1 = new ilSystemStyleIconColor("id1","name","FF0000","description");
62  $set = new ilSystemStyleIconColorSet();
63  $set->addColor($color1);
64 
65  $this->assertTrue($set->doesColorExist("id1"));
66  $this->assertFalse($set->doesColorExist("otherId"));
67  $this->assertFalse($set->doesColorExist(""));
68  }
69 
70  public function testMergeColorSet() {
71  $color1 = new ilSystemStyleIconColor("id1","name","FF0000","description");
72  $color2 = new ilSystemStyleIconColor("id2","name","FF0000","description");
73  $color3 = new ilSystemStyleIconColor("id3","name","FF0000","description");
74 
75  $set1 = new ilSystemStyleIconColorSet();
76  $set2 = new ilSystemStyleIconColorSet();
77 
78  $set1->addColor($color1);
79  $set1->addColor($color2);
80 
81  $set2->addColor($color2);
82  $set2->addColor($color3);
83 
84  $set1->mergeColorSet($set2);
85 
86  $this->assertEquals(3,count($set1->getColors()));
87  $this->assertEquals($color1,$set1->getColorById("id1"));
88  $this->assertEquals($color2,$set1->getColorById("id2"));
89  $this->assertEquals($color3,$set1->getColorById("id3"));
90 
91  $this->assertEquals(2,count($set2->getColors()));
92  $this->assertEquals($color2,$set2->getColorById("id2"));
93  $this->assertEquals($color3,$set2->getColorById("id3"));
94  }
95 
96  public function testGetColorsSortedAsArray() {
97  $white = new ilSystemStyleIconColor("id1","name","FFFFFF","description");
98  $black = new ilSystemStyleIconColor("id2","name","000000","description");
99  $grey = new ilSystemStyleIconColor("id3","name","AAAAAA","description");
100 
101  $red = new ilSystemStyleIconColor("id4","name","FF0000","description");
102  $green = new ilSystemStyleIconColor("id5","name","00FF00","description");
103  $blue = new ilSystemStyleIconColor("id6","name","0000FF","description");
104 
105  $ordered_array = [
110  ];
111 
112  $set1 = new ilSystemStyleIconColorSet();
113 
114  $set1->addColor($white);
115  $set1->addColor($black);
116  $set1->addColor($grey);
117  $set1->addColor($red);
118  $set1->addColor($green);
119  $set1->addColor($blue);
120 
121  $this->assertEquals($ordered_array,$set1->getColorsSortedAsArray());
122  }
123 
124  public function testAsArray() {
125  $white = new ilSystemStyleIconColor("id1","name","FFFFFF","description");
126  $black = new ilSystemStyleIconColor("id2","name","000000","description");
127  $grey = new ilSystemStyleIconColor("id3","name","AAAAAA","description");
128 
129  $red = new ilSystemStyleIconColor("id4","name","FF0000","description");
130  $green = new ilSystemStyleIconColor("id5","name","00FF00","description");
131  $blue = new ilSystemStyleIconColor("id6","name","0000FF","description");
132 
133  $as_array = ["id1","id2","id3","id4","id5","id6"];
134 
135  $set1 = new ilSystemStyleIconColorSet();
136 
137  $set1->addColor($white);
138  $set1->addColor($black);
139  $set1->addColor($grey);
140  $set1->addColor($red);
141  $set1->addColor($green);
142  $set1->addColor($blue);
143 
144  $this->assertEquals($as_array,$set1->asArray());
145  }
146 
147  public function testAsString() {
148  $white = new ilSystemStyleIconColor("id1","name","FFFFFF","description");
149  $black = new ilSystemStyleIconColor("id2","name","000000","description");
150  $grey = new ilSystemStyleIconColor("id3","name","AAAAAA","description");
151 
152  $red = new ilSystemStyleIconColor("id4","name","FF0000","description");
153  $green = new ilSystemStyleIconColor("id5","name","00FF00","description");
154  $blue = new ilSystemStyleIconColor("id6","name","0000FF","description");
155 
156  $as_string = "id1; id2; id3; id4; id5; id6; ";
157 
158  $set1 = new ilSystemStyleIconColorSet();
159 
160  $set1->addColor($white);
161  $set1->addColor($black);
162  $set1->addColor($grey);
163  $set1->addColor($red);
164  $set1->addColor($green);
165  $set1->addColor($blue);
166 
167  $this->assertEquals($as_string,$set1->asString());
168  }
169 }
$blue
Definition: example_030.php:81
$red
Definition: example_030.php:80
$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