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