1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This is the part of Povils open-source library. |
5
|
|
|
* |
6
|
|
|
* @author Povilas Susinskas |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Povils\Figlet\Tests; |
10
|
|
|
|
11
|
|
|
use Povils\Figlet\Figlet; |
12
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class FigletTest |
16
|
|
|
*/ |
17
|
|
|
class FigletTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
public function testRender_Default() |
20
|
|
|
{ |
21
|
|
|
$figlet = new Figlet(); |
22
|
|
|
$output = $figlet->render('Test'); |
23
|
|
|
|
24
|
|
|
$this->assertEquals($this->getDefaultBigFontText(), $output); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testRender_SlantFont() |
28
|
|
|
{ |
29
|
|
|
$figlet = new Figlet(); |
30
|
|
|
$figlet->setFont('slant'); |
31
|
|
|
$output = $figlet->render('Test'); |
32
|
|
|
|
33
|
|
|
$this->assertEquals($this->getSlantFontText(), $output); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testRender_StretchedAndColorized() |
37
|
|
|
{ |
38
|
|
|
$figlet = new Figlet(); |
39
|
|
|
$figlet |
40
|
|
|
->setFontStretching(1) |
41
|
|
|
->setFontColor('red') |
42
|
|
|
->setBackgroundColor('light_gray'); |
43
|
|
|
|
44
|
|
|
$output = $figlet->render('Test'); |
45
|
|
|
|
46
|
|
|
$this->assertEquals($this->getModifiedDefaultBigFontText("0;31", "47"), $output); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @expectedException InvalidArgumentException |
51
|
|
|
*/ |
52
|
|
|
public function testRender_UndefinedFontColor() |
53
|
|
|
{ |
54
|
|
|
$figlet = new Figlet(); |
55
|
|
|
$figlet |
56
|
|
|
->setFontColor('bright_red'); |
57
|
|
|
$figlet->render('Test'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @expectedException InvalidArgumentException |
62
|
|
|
*/ |
63
|
|
|
public function testRender_UndefinedBackgroundColor() |
64
|
|
|
{ |
65
|
|
|
$figlet = new Figlet(); |
66
|
|
|
$figlet |
67
|
|
|
->setBackgroundColor('bright_light_gray'); |
68
|
|
|
$figlet->render('Test'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testRender_ChangeFontAndCachedLetters() |
72
|
|
|
{ |
73
|
|
|
$figlet = new Figlet(); |
74
|
|
|
$figlet->setFont('slant'); |
75
|
|
|
$figlet->render('Test'); |
76
|
|
|
$figlet->setFont('big'); |
77
|
|
|
$figlet->render('Test'); |
78
|
|
|
$output = $figlet->render('Test'); |
79
|
|
|
|
80
|
|
|
$this->assertEquals($this->getDefaultBigFontText(), $output); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testRender_NewFontDir() |
84
|
|
|
{ |
85
|
|
|
$figlet = new Figlet(); |
86
|
|
|
|
87
|
|
|
$figlet |
88
|
|
|
->setFontDir(__DIR__ .'/font/') |
89
|
|
|
->setFont('slant'); |
90
|
|
|
|
91
|
|
|
$output = $figlet->render('Test'); |
92
|
|
|
|
93
|
|
|
$this->assertEquals($this->getSlantFontText(), $output); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @expectedException Exception |
98
|
|
|
*/ |
99
|
|
|
public function testRender_BandFont() |
100
|
|
|
{ |
101
|
|
|
$figlet = new Figlet(); |
102
|
|
|
|
103
|
|
|
$figlet |
104
|
|
|
->setFontDir(__DIR__ .'/font/') |
105
|
|
|
->setFont('badfile'); |
106
|
|
|
|
107
|
|
|
$figlet->render('Test'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
private function getDefaultBigFontText() |
114
|
|
|
{ |
115
|
|
|
return |
116
|
|
|
' _______ _ ' . "\n" . |
117
|
|
|
' |__ __| | | ' . "\n" . |
118
|
|
|
' | | ___ ___ | |_ ' . "\n" . |
119
|
|
|
' | | / _ \ / __| | __|' . "\n" . |
120
|
|
|
' | | | __/ \__ \ | |_ ' . "\n" . |
121
|
|
|
' |_| \___| |___/ \__|' . "\n" . |
122
|
|
|
' ' . "\n" . |
123
|
|
|
' ' . "\n"; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
private function getModifiedDefaultBigFontText($fontColor, $backgroundColor) |
130
|
|
|
{ |
131
|
|
|
return |
132
|
|
|
"\033[" . $fontColor . 'm' . "\033[" . $backgroundColor . 'm' . |
133
|
|
|
' _______ _ ' . "\n" . |
134
|
|
|
' |__ __| | | ' . "\n" . |
135
|
|
|
' | | ___ ___ | |_ ' . "\n" . |
136
|
|
|
' | | / _ \ / __| | __| ' . "\n" . |
137
|
|
|
' | | | __/ \__ \ | |_ ' . "\n" . |
138
|
|
|
' |_| \___| |___/ \__| ' . "\n" . |
139
|
|
|
' ' . "\n" . |
140
|
|
|
' ' . "\n" . |
141
|
|
|
"\033[0m"; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
private function getSlantFontText() |
145
|
|
|
{ |
146
|
|
|
return |
147
|
|
|
' ______ __ ' . "\n" . |
148
|
|
|
' /_ __/ ___ _____ / /_' . "\n" . |
149
|
|
|
' / / / _ \ / ___/ / __/' . "\n" . |
150
|
|
|
' / / / __/ (__ ) / /_ ' . "\n" . |
151
|
|
|
'/_/ \___/ /____/ \__/ ' . "\n" . |
152
|
|
|
' ' . "\n"; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
} |
156
|
|
|
|