ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilSystemStyleIconTest.php
Go to the documentation of this file.
1 <?php
2 
3 include_once("Services/Style/System/classes/Utilities/class.ilSkinStyleXML.php");
4 include_once("Services/Style/System/classes/Utilities/class.ilSkinXML.php");
5 include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleSkinContainer.php");
6 include_once("Services/Style/System/test/fixtures/mocks/ilSystemStyleConfigMock.php");
7 include_once("Services/Style/System/test/fixtures/mocks/ilSystemStyleDICMock.php");
8 
9 include_once("Services/Style/System/classes/Icons/class.ilSystemStyleIcon.php");
10 
11 
18 {
19 
24 
28  protected $container;
29 
33  protected $style;
34 
38  protected $icon_name = "test_image_1.svg";
39 
43  protected $icon_type = "svg";
44 
45 
46  protected $save_dic = null;
47 
48  protected function setUp()
49  {
50  global $DIC;
51 
52  $this->save_dic = $DIC;
53 
54  $DIC = new ilSystemStyleDICMock();
55 
56  $this->system_style_config = new ilSystemStyleConfigMock();
57 
58  mkdir($this->system_style_config->test_skin_temp_path);
59  ilSystemStyleSkinContainer::xCopy($this->system_style_config->test_skin_original_path, $this->system_style_config->test_skin_temp_path);
60 
61  $this->container = ilSystemStyleSkinContainer::generateFromId("skin1", null, $this->system_style_config);
62  $this->style = $this->container->getSkin()->getStyle("style1");
63  }
64 
65  protected function tearDown()
66  {
67  global $DIC;
68  $DIC = $this->save_dic;
69  ilSystemStyleSkinContainer::recursiveRemoveDir($this->system_style_config->test_skin_temp_path);
70  }
71 
72  public function testConstruct()
73  {
74  $path = $this->container->getImagesSkinPath($this->style->getId()) . "/" . $this->icon_name;
75  $icon = new ilSystemStyleIcon($this->icon_name, $path, $this->icon_type);
76 
77  $this->assertEquals($icon->getName(), $this->icon_name);
78  $this->assertEquals($icon->getPath(), $path);
79  $this->assertEquals($icon->getType(), $this->icon_type);
80  }
81 
82  public function testGetColorSet()
83  {
84  $path = $this->container->getImagesSkinPath($this->style->getId()) . "/" . $this->icon_name;
85  $icon = new ilSystemStyleIcon($this->icon_name, $path, $this->icon_type);
86 
87  $expected_color_set = new ilSystemStyleIconColorSet();
88  $color1 = new ilSystemStyleIconColor("505050", "505050", "505050", "505050");
89  $color2 = new ilSystemStyleIconColor("6B6B6B", "6B6B6B", "6B6B6B", "6B6B6B");
90  $color3 = new ilSystemStyleIconColor("838383", "838383", "838383", "838383");
91  $color4 = new ilSystemStyleIconColor("8C8C8C", "8C8C8C", "8C8C8C", "8C8C8C");
92  $expected_color_set->addColor($color1);
93  $expected_color_set->addColor($color2);
94  $expected_color_set->addColor($color3);
95  $expected_color_set->addColor($color4);
96 
97  $this->assertEquals($expected_color_set, $icon->getColorSet());
98  }
99 
100  public function testChangeColor()
101  {
102  $path = $this->container->getImagesSkinPath($this->style->getId()) . "/" . $this->icon_name;
103  $icon = new ilSystemStyleIcon($this->icon_name, $path, $this->icon_type);
104 
105  $icon->changeColors(['505050' => '555555']);
106 
107  $expected_color_set = new ilSystemStyleIconColorSet();
108  $color1 = new ilSystemStyleIconColor("555555", "555555", "555555", "555555");
109  $color2 = new ilSystemStyleIconColor("6B6B6B", "6B6B6B", "6B6B6B", "6B6B6B");
110  $color3 = new ilSystemStyleIconColor("838383", "838383", "838383", "838383");
111  $color4 = new ilSystemStyleIconColor("8C8C8C", "8C8C8C", "8C8C8C", "8C8C8C");
112  $expected_color_set->addColor($color1);
113  $expected_color_set->addColor($color2);
114  $expected_color_set->addColor($color3);
115  $expected_color_set->addColor($color4);
116 
117  $this->assertEquals($expected_color_set, $icon->getColorSet());
118  }
119 
120  public function testChangeColorInIconFile()
121  {
122  $path = $this->container->getImagesSkinPath($this->style->getId()) . "/" . $this->icon_name;
123  $icon = new ilSystemStyleIcon($this->icon_name, $path, $this->icon_type);
124 
125  $icon->changeColors(['505050' => '555555']);
126 
127  $expected_color_set = new ilSystemStyleIconColorSet();
128  $color1 = new ilSystemStyleIconColor("555555", "555555", "555555", "555555");
129  $color2 = new ilSystemStyleIconColor("6B6B6B", "6B6B6B", "6B6B6B", "6B6B6B");
130  $color3 = new ilSystemStyleIconColor("838383", "838383", "838383", "838383");
131  $color4 = new ilSystemStyleIconColor("8C8C8C", "8C8C8C", "8C8C8C", "8C8C8C");
132  $expected_color_set->addColor($color1);
133  $expected_color_set->addColor($color2);
134  $expected_color_set->addColor($color3);
135  $expected_color_set->addColor($color4);
136 
137  $icon_new = new ilSystemStyleIcon($this->icon_name, $path, $this->icon_type);
138 
139  $this->assertEquals($expected_color_set, $icon_new->getColorSet());
140  }
141 }
142 
$path
Definition: aliased.php:25
Class ilLanguageMock.
"color:#CC0000 style
Definition: example_001.php:92
Abstracts an Icon and the necessary actions to get all colors out of an svg Icon. ...
static recursiveRemoveDir($dir)
Recursive delete of a folder.
static generateFromId($skin_id, ilSystemStyleMessageStack $message_stack=null, ilSystemStyleConfig $system_styles_conf=null)
Generate the container class by parsing the corresponding XML.
ilSystemStyleConfig wraps all &#39;constants&#39; to ensure the testability of all classes using those &#39;const...
global $DIC
static xCopy($src, $dest)
Recursive copy of a folder.