This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
FigletTest.php
239 lines (178 loc) · 7.56 KB
/
FigletTest.php
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Text
*/
namespace ZendTest\Text;
use Zend\Text\Figlet;
/**
* @category Zend
* @package Zend_Text
* @subpackage UnitTests
* @group Zend_Text
*/
class FigletTest extends \PHPUnit_Framework_TestCase
{
public function testStandardAlignLeft()
{
$figlet = new Figlet\Figlet();
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignLeft.figlet');
}
public function testStandardAlignCenter()
{
$figlet = new Figlet\Figlet(array('justification' => Figlet\Figlet::JUSTIFICATION_CENTER));
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignCenter.figlet');
}
public function testStandardAlignRight()
{
$figlet = new Figlet\Figlet(array('justification' => Figlet\Figlet::JUSTIFICATION_RIGHT));
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignRight.figlet');
}
public function testStandardRightToLeftAlignLeft()
{
$figlet = new Figlet\Figlet(array('justification' => Figlet\Figlet::JUSTIFICATION_LEFT,
'rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT));
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardRightToLeftAlignLeft.figlet');
}
public function testStandardRightToLeftAlignCenter()
{
$figlet = new Figlet\Figlet(array('justification' => Figlet\Figlet::JUSTIFICATION_CENTER,
'rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT));
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardRightToLeftAlignCenter.figlet');
}
public function testStandardRightToLeftAlignRight()
{
$figlet = new Figlet\Figlet(array('rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT));
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardRightToLeftAlignRight.figlet');
}
public function testWrongParameter()
{
$figlet = new Figlet\Figlet();
$this->setExpectedException('Zend\Text\Figlet\Exception\InvalidArgumentException', 'must be a string');
$figlet->render(1);
}
public function testCorrectEncodingUTF8()
{
$figlet = new Figlet\Figlet();
$this->_equalAgainstFile($figlet->render('Ömläüt'), 'CorrectEncoding.figlet');
}
public function testCorrectEncodingISO885915()
{
if (PHP_OS == 'AIX') {
$this->markTestSkipped('Test case cannot run on AIX');
}
$figlet = new Figlet\Figlet();
$isoText = iconv('UTF-8', 'ISO-8859-15', 'Ömläüt');
$this->_equalAgainstFile($figlet->render($isoText, 'ISO-8859-15'), 'CorrectEncoding.figlet');
}
public function testIncorrectEncoding()
{
$this->setExpectedException('Zend\Text\Figlet\Exception\UnexpectedValueException',
'text is not encoded with UTF-8');
$isoText = iconv('UTF-8', 'ISO-8859-15', 'Ömläüt');
$figlet = new Figlet\Figlet();
$figlet->render($isoText);
}
public function testNonExistentFont()
{
$this->setExpectedException('Zend\Text\Figlet\Exception\RuntimeException', 'not found');
$figlet = new Figlet\Figlet(array('font' => __DIR__ . '/Figlet/NonExistentFont.flf'));
}
public function testInvalidFont()
{
$this->setExpectedException('Zend\Text\Figlet\Exception\UnexpectedValueException', 'Not a FIGlet');
$figlet = new Figlet\Figlet(array('font' => __DIR__ . '/Figlet/InvalidFont.flf'));
}
public function testGzippedFont()
{
$figlet = new Figlet\Figlet(array('font' => __DIR__ . '/Figlet/GzippedFont.gz'));
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignLeft.figlet');
}
public function testConfig()
{
$config = new \Zend\Config\Config(array('justification' => Figlet\Figlet::JUSTIFICATION_RIGHT));
$figlet = new Figlet\Figlet($config);
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignRight.figlet');
}
public function testOutputWidth()
{
$figlet = new Figlet\Figlet(array('outputWidth' => 50,
'justification' => Figlet\Figlet::JUSTIFICATION_RIGHT));
$this->_equalAgainstFile($figlet->render('Dummy'), 'OutputWidth50AlignRight.figlet');
}
public function testSmushModeRemoved()
{
$figlet = new Figlet\Figlet(array('smushMode' => -1));
$this->_equalAgainstFile($figlet->render('Dummy'), 'NoSmush.figlet');
}
public function testSmushModeRemovedRightToLeft()
{
$figlet = new Figlet\Figlet(array('smushMode' => -1,
'rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT));
$this->_equalAgainstFile($figlet->render('Dummy'), 'NoSmushRightToLeft.figlet');
}
public function testSmushModeInvalid()
{
$figlet = new Figlet\Figlet(array('smushMode' => -5));
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignLeft.figlet');
}
public function testSmushModeTooSmall()
{
$figlet = new Figlet\Figlet(array('smushMode' => -2));
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignLeft.figlet');
}
public function testSmushModeDefault()
{
$figlet = new Figlet\Figlet(array('smushMode' => 0));
$this->_equalAgainstFile($figlet->render('Dummy'), 'SmushDefault.figlet');
}
public function testSmushModeForced()
{
$figlet = new Figlet\Figlet(array('smushMode' => 5));
$this->_equalAgainstFile($figlet->render('Dummy'), 'SmushForced.figlet');
}
public function testWordWrapLeftToRight()
{
$figlet = new Figlet\Figlet();
$this->_equalAgainstFile($figlet->render('Dummy Dummy Dummy'), 'WordWrapLeftToRight.figlet');
}
public function testWordWrapRightToLeft()
{
$figlet = new Figlet\Figlet(array('rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT));
$this->_equalAgainstFile($figlet->render('Dummy Dummy Dummy'), 'WordWrapRightToLeft.figlet');
}
public function testCharWrapLeftToRight()
{
$figlet = new Figlet\Figlet();
$this->_equalAgainstFile($figlet->render('DummyDumDummy'), 'CharWrapLeftToRight.figlet');
}
public function testCharWrapRightToLeft()
{
$figlet = new Figlet\Figlet(array('rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT));
$this->_equalAgainstFile($figlet->render('DummyDumDummy'), 'CharWrapRightToLeft.figlet');
}
public function testParagraphOff()
{
$figlet = new Figlet\Figlet();
$this->_equalAgainstFile($figlet->render("Dum\nDum\n\nDum\n"), 'ParagraphOff.figlet');
}
public function testParagraphOn()
{
$figlet = new Figlet\Figlet(array('handleParagraphs' => true));
$this->_equalAgainstFile($figlet->render("Dum\nDum\n\nDum\n"), 'ParagraphOn.figlet');
}
public function testEmptyString()
{
$figlet = new Figlet\Figlet();
$this->assertEquals('', $figlet->render(''));
}
protected function _equalAgainstFile($output, $file)
{
$compareString = file_get_contents(__DIR__ . '/Figlet/' . $file);
$this->assertEquals($compareString, $output);
}
}