| 12345 |
anikendra |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* ConsoleOutputTest file
|
|
|
4 |
*
|
|
|
5 |
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
|
|
6 |
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
7 |
*
|
|
|
8 |
* Licensed under The MIT License
|
|
|
9 |
* For full copyright and license information, please see the LICENSE.txt
|
|
|
10 |
* Redistributions of files must retain the above copyright notice
|
|
|
11 |
*
|
|
|
12 |
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
13 |
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
|
|
14 |
* @package Cake.Test.Case.Console
|
|
|
15 |
* @since CakePHP(tm) v 1.2.0.5432
|
|
|
16 |
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
App::uses('ConsoleOutput', 'Console');
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Class ConsoleOutputTest
|
|
|
23 |
*
|
|
|
24 |
* @package Cake.Test.Case.Console
|
|
|
25 |
*/
|
|
|
26 |
class ConsoleOutputTest extends CakeTestCase {
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* setup
|
|
|
30 |
*
|
|
|
31 |
* @return void
|
|
|
32 |
*/
|
|
|
33 |
public function setUp() {
|
|
|
34 |
parent::setUp();
|
|
|
35 |
$this->output = $this->getMock('ConsoleOutput', array('_write'));
|
|
|
36 |
$this->output->outputAs(ConsoleOutput::COLOR);
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* tearDown
|
|
|
41 |
*
|
|
|
42 |
* @return void
|
|
|
43 |
*/
|
|
|
44 |
public function tearDown() {
|
|
|
45 |
parent::tearDown();
|
|
|
46 |
unset($this->output);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* test writing with no new line
|
|
|
51 |
*
|
|
|
52 |
* @return void
|
|
|
53 |
*/
|
|
|
54 |
public function testWriteNoNewLine() {
|
|
|
55 |
$this->output->expects($this->once())->method('_write')
|
|
|
56 |
->with('Some output');
|
|
|
57 |
|
|
|
58 |
$this->output->write('Some output', false);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
* test writing with no new line
|
|
|
63 |
*
|
|
|
64 |
* @return void
|
|
|
65 |
*/
|
|
|
66 |
public function testWriteNewLine() {
|
|
|
67 |
$this->output->expects($this->once())->method('_write')
|
|
|
68 |
->with('Some output' . PHP_EOL);
|
|
|
69 |
|
|
|
70 |
$this->output->write('Some output');
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
/**
|
|
|
74 |
* test write() with multiple new lines
|
|
|
75 |
*
|
|
|
76 |
* @return void
|
|
|
77 |
*/
|
|
|
78 |
public function testWriteMultipleNewLines() {
|
|
|
79 |
$this->output->expects($this->once())->method('_write')
|
|
|
80 |
->with('Some output' . PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL);
|
|
|
81 |
|
|
|
82 |
$this->output->write('Some output', 4);
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
/**
|
|
|
86 |
* test writing an array of messages.
|
|
|
87 |
*
|
|
|
88 |
* @return void
|
|
|
89 |
*/
|
|
|
90 |
public function testWriteArray() {
|
|
|
91 |
$this->output->expects($this->once())->method('_write')
|
|
|
92 |
->with('Line' . PHP_EOL . 'Line' . PHP_EOL . 'Line' . PHP_EOL);
|
|
|
93 |
|
|
|
94 |
$this->output->write(array('Line', 'Line', 'Line'));
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
/**
|
|
|
98 |
* test getting a style.
|
|
|
99 |
*
|
|
|
100 |
* @return void
|
|
|
101 |
*/
|
|
|
102 |
public function testStylesGet() {
|
|
|
103 |
$result = $this->output->styles('error');
|
|
|
104 |
$expected = array('text' => 'red', 'underline' => true);
|
|
|
105 |
$this->assertEquals($expected, $result);
|
|
|
106 |
|
|
|
107 |
$this->assertNull($this->output->styles('made_up_goop'));
|
|
|
108 |
|
|
|
109 |
$result = $this->output->styles();
|
|
|
110 |
$this->assertNotEmpty($result, 'error', 'Error is missing');
|
|
|
111 |
$this->assertNotEmpty($result, 'warning', 'Warning is missing');
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
/**
|
|
|
115 |
* test adding a style.
|
|
|
116 |
*
|
|
|
117 |
* @return void
|
|
|
118 |
*/
|
|
|
119 |
public function testStylesAdding() {
|
|
|
120 |
$this->output->styles('test', array('text' => 'red', 'background' => 'black'));
|
|
|
121 |
$result = $this->output->styles('test');
|
|
|
122 |
$expected = array('text' => 'red', 'background' => 'black');
|
|
|
123 |
$this->assertEquals($expected, $result);
|
|
|
124 |
|
|
|
125 |
$this->assertTrue($this->output->styles('test', false), 'Removing a style should return true.');
|
|
|
126 |
$this->assertNull($this->output->styles('test'), 'Removed styles should be null.');
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
/**
|
|
|
130 |
* test formatting text with styles.
|
|
|
131 |
*
|
|
|
132 |
* @return void
|
|
|
133 |
*/
|
|
|
134 |
public function testFormattingSimple() {
|
|
|
135 |
$this->output->expects($this->once())->method('_write')
|
|
|
136 |
->with("\033[31;4mError:\033[0m Something bad");
|
|
|
137 |
|
|
|
138 |
$this->output->write('<error>Error:</error> Something bad', false);
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
/**
|
|
|
142 |
* test that formatting doesn't eat tags it doesn't know about.
|
|
|
143 |
*
|
|
|
144 |
* @return void
|
|
|
145 |
*/
|
|
|
146 |
public function testFormattingNotEatingTags() {
|
|
|
147 |
$this->output->expects($this->once())->method('_write')
|
|
|
148 |
->with("<red> Something bad");
|
|
|
149 |
|
|
|
150 |
$this->output->write('<red> Something bad', false);
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
/**
|
|
|
154 |
* test formatting with custom styles.
|
|
|
155 |
*
|
|
|
156 |
* @return void
|
|
|
157 |
*/
|
|
|
158 |
public function testFormattingCustom() {
|
|
|
159 |
$this->output->styles('annoying', array(
|
|
|
160 |
'text' => 'magenta',
|
|
|
161 |
'background' => 'cyan',
|
|
|
162 |
'blink' => true,
|
|
|
163 |
'underline' => true
|
|
|
164 |
));
|
|
|
165 |
|
|
|
166 |
$this->output->expects($this->once())->method('_write')
|
|
|
167 |
->with("\033[35;46;5;4mAnnoy:\033[0m Something bad");
|
|
|
168 |
|
|
|
169 |
$this->output->write('<annoying>Annoy:</annoying> Something bad', false);
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
/**
|
|
|
173 |
* test formatting text with missing styles.
|
|
|
174 |
*
|
|
|
175 |
* @return void
|
|
|
176 |
*/
|
|
|
177 |
public function testFormattingMissingStyleName() {
|
|
|
178 |
$this->output->expects($this->once())->method('_write')
|
|
|
179 |
->with("<not_there>Error:</not_there> Something bad");
|
|
|
180 |
|
|
|
181 |
$this->output->write('<not_there>Error:</not_there> Something bad', false);
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
/**
|
|
|
185 |
* test formatting text with multiple styles.
|
|
|
186 |
*
|
|
|
187 |
* @return void
|
|
|
188 |
*/
|
|
|
189 |
public function testFormattingMultipleStylesName() {
|
|
|
190 |
$this->output->expects($this->once())->method('_write')
|
|
|
191 |
->with("\033[31;4mBad\033[0m \033[33mWarning\033[0m Regular");
|
|
|
192 |
|
|
|
193 |
$this->output->write('<error>Bad</error> <warning>Warning</warning> Regular', false);
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
/**
|
|
|
197 |
* test that multiple tags of the same name work in one string.
|
|
|
198 |
*
|
|
|
199 |
* @return void
|
|
|
200 |
*/
|
|
|
201 |
public function testFormattingMultipleSameTags() {
|
|
|
202 |
$this->output->expects($this->once())->method('_write')
|
|
|
203 |
->with("\033[31;4mBad\033[0m \033[31;4mWarning\033[0m Regular");
|
|
|
204 |
|
|
|
205 |
$this->output->write('<error>Bad</error> <error>Warning</error> Regular', false);
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
/**
|
|
|
209 |
* test raw output not getting tags replaced.
|
|
|
210 |
*
|
|
|
211 |
* @return void
|
|
|
212 |
*/
|
|
|
213 |
public function testOutputAsRaw() {
|
|
|
214 |
$this->output->outputAs(ConsoleOutput::RAW);
|
|
|
215 |
$this->output->expects($this->once())->method('_write')
|
|
|
216 |
->with('<error>Bad</error> Regular');
|
|
|
217 |
|
|
|
218 |
$this->output->write('<error>Bad</error> Regular', false);
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
/**
|
|
|
222 |
* test plain output.
|
|
|
223 |
*
|
|
|
224 |
* @return void
|
|
|
225 |
*/
|
|
|
226 |
public function testOutputAsPlain() {
|
|
|
227 |
$this->output->outputAs(ConsoleOutput::PLAIN);
|
|
|
228 |
$this->output->expects($this->once())->method('_write')
|
|
|
229 |
->with('Bad Regular');
|
|
|
230 |
|
|
|
231 |
$this->output->write('<error>Bad</error> Regular', false);
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
/**
|
|
|
235 |
* test plain output only strips tags used for formatting.
|
|
|
236 |
*
|
|
|
237 |
* @return void
|
|
|
238 |
*/
|
|
|
239 |
public function testOutputAsPlainSelectiveTagRemoval() {
|
|
|
240 |
$this->output->outputAs(ConsoleOutput::PLAIN);
|
|
|
241 |
$this->output->expects($this->once())->method('_write')
|
|
|
242 |
->with('Bad Regular <b>Left</b> <i>behind</i> <name>');
|
|
|
243 |
|
|
|
244 |
$this->output->write('<error>Bad</error> Regular <b>Left</b> <i>behind</i> <name>', false);
|
|
|
245 |
}
|
|
|
246 |
}
|