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