-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathFontTest.php
More file actions
178 lines (141 loc) · 5.11 KB
/
FontTest.php
File metadata and controls
178 lines (141 loc) · 5.11 KB
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
declare(strict_types=1);
namespace PhpMyAdmin\Tests;
use PhpMyAdmin\Font;
/**
* @covers \PhpMyAdmin\Font
*/
class FontTest extends AbstractTestCase
{
/** @var Font */
private $font;
/**
* Sets up the fixture
*/
protected function setUp(): void
{
parent::setUp();
$this->font = new Font();
}
/**
* Test getStringWidth with different characters.
*/
public function testGetStringWidth(): void
{
// empty string
self::assertSame(0, $this->font->getStringWidth('', 'arial', 10));
// empty string
self::assertSame(3, $this->font->getStringWidth(' ', 'arial', 10));
// string "a"
self::assertSame(6, $this->font->getStringWidth('a', 'arial', 10));
// string "aa"
self::assertSame(12, $this->font->getStringWidth('aa', 'arial', 10));
// string "i"
self::assertSame(3, $this->font->getStringWidth('i', 'arial', 10));
// string "f"
self::assertSame(3, $this->font->getStringWidth('f', 'arial', 10));
// string "t"
self::assertSame(3, $this->font->getStringWidth('t', 'arial', 10));
// string "if"
self::assertSame(5, $this->font->getStringWidth('if', 'arial', 10));
// string "it"
self::assertSame(6, $this->font->getStringWidth('it', 'arial', 10));
// string "r"
self::assertSame(4, $this->font->getStringWidth('r', 'arial', 10));
// string "1"
self::assertSame(5, $this->font->getStringWidth('1', 'arial', 10));
// string "c"
self::assertSame(5, $this->font->getStringWidth('c', 'arial', 10));
// string "F"
self::assertSame(7, $this->font->getStringWidth('F', 'arial', 10));
// string "A"
self::assertSame(7, $this->font->getStringWidth('A', 'arial', 10));
// string "w"
self::assertSame(8, $this->font->getStringWidth('w', 'arial', 10));
// string "G"
self::assertSame(8, $this->font->getStringWidth('G', 'arial', 10));
// string "m"
self::assertSame(9, $this->font->getStringWidth('m', 'arial', 10));
// string "W"
self::assertSame(10, $this->font->getStringWidth('W', 'arial', 10));
// string "$"
self::assertSame(3, $this->font->getStringWidth('$', 'arial', 10));
}
/**
* Test getStringWidth with different fonts.
*/
public function testGetStringWidthFont(): void
{
// string "phpMyAdmin", with Arial 10
self::assertSame(59, $this->font->getStringWidth('phpMyAdmin', 'arial', 10));
// string "phpMyAdmin", with No font
self::assertSame(59, $this->font->getStringWidth('phpMyAdmin', '', 10));
// string "phpMyAdmin", with Times 10
self::assertSame(55, $this->font->getStringWidth('phpMyAdmin', 'times', 10));
// string "phpMyAdmin", with Broadway 10
self::assertSame(73, $this->font->getStringWidth('phpMyAdmin', 'broadway', 10));
}
/**
* Test getStringWidth with different font sizes.
*/
public function testGetStringWidthSize(): void
{
// string "phpMyAdmin", with font size 0
self::assertSame(0, $this->font->getStringWidth('phpMyAdmin', 'arial', 0));
// string "phpMyAdmin", with Arial 10
self::assertSame(59, $this->font->getStringWidth('phpMyAdmin', 'arial', 10));
// string "phpMyAdmin", with Arial 11
self::assertSame(65, $this->font->getStringWidth('phpMyAdmin', 'arial', 11));
// string "phpMyAdmin", with Arial 20
self::assertSame(118, $this->font->getStringWidth('phpMyAdmin', 'arial', 20));
}
/**
* Test getStringWidth with a custom charList.
*/
public function testGetStringWidthCharLists(): void
{
// string "a", with invalid charlist (= array without proper structure)
self::assertSame(6, $this->font->getStringWidth('a', 'arial', 10, ['list']));
// string "a", with invalid charlist (= array without proper structure :
// modifier is missing
self::assertSame(6, $this->font->getStringWidth(
'a',
'arial',
10,
[['chars' => 'a']]
));
// string "a", with invalid charlist (= array without proper structure :
// chars is missing
self::assertSame(6, $this->font->getStringWidth(
'a',
'arial',
10,
[['modifier' => 0.61]]
));
// string "a", with invalid charlist (= array without proper structure :
// chars is not an array
self::assertSame(6, $this->font->getStringWidth(
'a',
'arial',
10,
[
[
'chars' => 'a',
'modifier' => 0.61,
],
]
));
// string "a", with valid charlist
self::assertSame(7, $this->font->getStringWidth(
'a',
'arial',
10,
[
[
'chars' => ['a'],
'modifier' => 0.61,
],
]
));
}
}