1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
<?php
/*
* Copyright (C) 2015 <mlunzena@uos.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
class IconClassTest extends \Codeception\Test\Unit
{
private $memo_assets_url;
public function setUp(): void
{
$this->memo_assets_url = Assets::url();
Assets::set_assets_url('');
}
public function tearDown(): void
{
Assets::set_assets_url($this->memo_assets_url);
}
public function testIconCreateAsImg()
{
$this->assertEquals(
'<img src="images/icons/blue/vote.svg" alt="" class="studip-icon icon-role-clickable icon-shape-vote">',
Icon::create('vote')->asImg()
);
}
public function testIconCreateAsImgWithAddition()
{
$this->assertEquals(
'<img src="images/icons/blue/vote.svg" alt="" class="studip-icon icon-role-clickable icon-shape-vote">',
Icon::create('vote')->asImg()
);
}
public function testIconCreateAsImgWithSize()
{
$this->assertEquals(
'<img style="width:100px;height:100px" src="images/icons/blue/vote.svg" alt="" class="studip-icon icon-role-clickable icon-shape-vote">',
Icon::create('vote')->asImg(100)
);
}
public function testIconCreateAsImgWithTitle()
{
$this->assertEquals(
'<img title="Mit Anhang" style="width:24px;height:24px" src="images/icons/blue/vote.svg" class="studip-icon icon-role-clickable icon-shape-vote">',
Icon::create('vote')->asImg(24, ['title' => 'Mit Anhang'])
);
}
public function testIconCreateAsImgWithHspace()
{
$this->assertEquals(
'<img hspace="3" src="images/icons/blue/arr_2left.svg" alt="" class="studip-icon icon-role-clickable icon-shape-arr_2left">',
Icon::create('arr_2left')->asImg(['hspace' => 3])
);
}
public function testIconCreateAsImgWithClass()
{
$this->assertEquals(
'<img class="text-bottom studip-icon icon-role-info icon-shape-staple" style="width:24px;height:24px" src="images/icons/black/staple.svg" alt="">',
Icon::create('staple', Icon::ROLE_INFO)->asImg(24, ['class' => 'text-bottom'])
);
}
public function testIconCreateAsImgWithClassAndTitle()
{
$this->assertEquals(
'<img class="text-bottom studip-icon icon-role-new icon-shape-upload" title="Datei hochladen" style="width:24px;height:24px" src="images/icons/red/upload.svg">',
Icon::create('upload', Icon::ROLE_NEW, ['title' => 'Datei hochladen'])
->asImg(24, ['class' => 'text-bottom'])
);
}
public function testIconCreateAsInput()
{
$this->assertEquals(
'<input type="image" class="text-bottom studip-icon icon-role-clickable icon-shape-upload" style="width:24px;height:24px" src="images/icons/blue/upload.svg" alt="">',
Icon::create('upload')->asInput(24, ['class' => 'text-bottom'])
);
}
public function testIconIsImmutable()
{
$icon = Icon::create('upload', attributes: ['title' => 'a title']);
$copy = $icon->copyWithRole(Icon::ROLE_CLICKABLE);
$this->assertNotSame($icon, $copy);
}
public function testIconCopyWithRole()
{
$icon = Icon::create('upload', attributes: ['title' => 'a title']);
$copy = $icon->copyWithRole(Icon::ROLE_INFO);
$this->assertEquals($icon->getShape(), $copy->getShape());
$this->assertNotEquals($icon->getRole(), $copy->getRole());
$this->assertEquals($icon->getAttributes(), $copy->getAttributes());
}
public function testIconCopyWithShape()
{
$icon = Icon::create('upload', attributes: ['title' => 'a title']);
$copy = $icon->copyWithShape('staple');
$this->assertNotEquals($icon->getShape(), $copy->getShape());
$this->assertEquals($icon->getRole(), $copy->getRole());
$this->assertEquals($icon->getAttributes(), $copy->getAttributes());
}
public function testIconCopyWithAttributes()
{
$icon = Icon::create('upload', Icon::ROLE_CLICKABLE, ['title' => 'a title']);
$copy = $icon->copyWithAttributes(['title' => 'another title']);
$this->assertEquals($icon->getShape(), $copy->getShape());
$this->assertEquals($icon->getRole(), $copy->getRole());
$this->assertNotEquals($icon->getAttributes(), $copy->getAttributes());
}
public function testStaticIcon()
{
$icon = Icon::create('https://i.imgur.com/kpTtTh.gif');
$this->assertEquals($icon->asImagePath(), 'https://i.imgur.com/kpTtTh.gif');
}
public function testIconCreateAsCSSWithSize()
{
$this->assertEquals(
'background-image:url(images/icons/blue/vote.svg);background-size:17px 17px;',
Icon::create('vote')->asCSS(17)
);
}
public function testIconCreateAsImagePath()
{
$this->assertEquals(
'images/icons/blue/vote.svg',
Icon::create('vote')->asImagePath()
);
}
public function testIconCreateAsImgWithoutSize()
{
$this->assertEquals(
'<img src="images/icons/blue/vote.svg" alt="" class="studip-icon icon-role-clickable icon-shape-vote">',
Icon::create('vote')->asImg(false)
);
}
public function testIconCreateAsInputWithoutSize()
{
$this->assertEquals(
'<input type="image" src="images/icons/blue/upload.svg" alt="" class="studip-icon icon-role-clickable icon-shape-upload">',
Icon::create('upload')->asInput(false)
);
}
public function testIconCreateRemovedExtras()
{
$this->assertEquals(
'<img src="images/icons/blue/vote.svg" alt="" class="studip-icon icon-role-clickable icon-shape-vote">',
Icon::create('add/vote')->asImg(false)
);
$this->assertEquals(
'<img src="images/icons/blue/vote.svg" alt="" class="studip-icon icon-role-clickable icon-shape-vote">',
Icon::create('vote+add')->asImg(false)
);
}
}
|