2010-10-03 18:54:41 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2010-10-04 03:00:48 +00:00
|
|
|
* ConsoleOutputTest file
|
2010-10-03 18:54:41 +00:00
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc.
|
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.console
|
|
|
|
* @since CakePHP(tm) v 1.2.0.5432
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
|
|
|
|
2010-10-17 21:39:05 +00:00
|
|
|
require_once CONSOLE_LIBS . 'console_output.php';
|
2010-10-03 18:54:41 +00:00
|
|
|
|
|
|
|
class ConsoleOutputTest extends CakeTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* setup
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->output = $this->getMock('ConsoleOutput', array('_write'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tearDown
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function tearDown() {
|
|
|
|
unset($this->output);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test writing with no new line
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testWriteNoNewLine() {
|
|
|
|
$this->output->expects($this->once())->method('_write')
|
|
|
|
->with('Some output');
|
|
|
|
|
|
|
|
$this->output->write('Some output', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test writing with no new line
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testWriteNewLine() {
|
|
|
|
$this->output->expects($this->once())->method('_write')
|
|
|
|
->with('Some output' . PHP_EOL);
|
|
|
|
|
|
|
|
$this->output->write('Some output');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test write() with multiple new lines
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testWriteMultipleNewLines() {
|
|
|
|
$this->output->expects($this->once())->method('_write')
|
|
|
|
->with('Some output' . PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL);
|
|
|
|
|
|
|
|
$this->output->write('Some output', 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test writing an array of messages.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testWriteArray() {
|
|
|
|
$this->output->expects($this->once())->method('_write')
|
|
|
|
->with('Line' . PHP_EOL . 'Line' . PHP_EOL . 'Line' . PHP_EOL);
|
|
|
|
|
|
|
|
$this->output->write(array('Line', 'Line', 'Line'));
|
|
|
|
}
|
|
|
|
|
2010-10-03 19:41:31 +00:00
|
|
|
/**
|
|
|
|
* test getting a style.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testStylesGet() {
|
|
|
|
$result = $this->output->styles('error');
|
2010-10-09 15:01:22 +00:00
|
|
|
$expected = array('text' => 'red', 'underline' => true);
|
2010-10-03 19:41:31 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2010-10-03 22:54:34 +00:00
|
|
|
|
2010-10-03 19:41:31 +00:00
|
|
|
$this->assertNull($this->output->styles('made_up_goop'));
|
2010-10-03 22:54:34 +00:00
|
|
|
|
|
|
|
$result = $this->output->styles();
|
|
|
|
$this->assertNotEmpty($result, 'error', 'Error is missing');
|
|
|
|
$this->assertNotEmpty($result, 'warning', 'Warning is missing');
|
2010-10-03 19:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test adding a style.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testStylesAdding() {
|
|
|
|
$this->output->styles('test', array('text' => 'red', 'background' => 'black'));
|
|
|
|
$result = $this->output->styles('test');
|
|
|
|
$expected = array('text' => 'red', 'background' => 'black');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$this->assertTrue($this->output->styles('test', false), 'Removing a style should return true.');
|
|
|
|
$this->assertNull($this->output->styles('test'), 'Removed styles should be null.');
|
|
|
|
}
|
|
|
|
|
2010-10-03 22:54:34 +00:00
|
|
|
/**
|
|
|
|
* test formatting text with styles.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testFormattingSimple() {
|
|
|
|
$this->output->expects($this->once())->method('_write')
|
2010-10-09 15:01:22 +00:00
|
|
|
->with("\033[31;4mError:\033[0m Something bad");
|
2010-10-03 22:54:34 +00:00
|
|
|
|
|
|
|
$this->output->write('<error>Error:</error> Something bad', false);
|
|
|
|
}
|
|
|
|
|
2010-10-10 16:24:37 +00:00
|
|
|
/**
|
|
|
|
* test that formatting doesn't eat tags it doesn't know about.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testFormattingNotEatingTags() {
|
|
|
|
$this->output->expects($this->once())->method('_write')
|
|
|
|
->with("<red> Something bad");
|
|
|
|
|
|
|
|
$this->output->write('<red> Something bad', false);
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:01:27 +00:00
|
|
|
/**
|
|
|
|
* test formatting with custom styles.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testFormattingCustom() {
|
|
|
|
$this->output->styles('annoying', array(
|
|
|
|
'text' => 'magenta',
|
|
|
|
'background' => 'cyan',
|
|
|
|
'blink' => true,
|
|
|
|
'underline' => true
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->output->expects($this->once())->method('_write')
|
|
|
|
->with("\033[35;46;5;4mAnnoy:\033[0m Something bad");
|
|
|
|
|
|
|
|
$this->output->write('<annoying>Annoy:</annoying> Something bad', false);
|
|
|
|
}
|
|
|
|
|
2010-10-03 22:54:34 +00:00
|
|
|
/**
|
|
|
|
* test formatting text with missing styles.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testFormattingMissingStyleName() {
|
|
|
|
$this->output->expects($this->once())->method('_write')
|
|
|
|
->with("Error: Something bad");
|
|
|
|
|
|
|
|
$this->output->write('<not_there>Error:</not_there> Something bad', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test formatting text with multiple styles.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testFormattingMultipleStylesName() {
|
|
|
|
$this->output->expects($this->once())->method('_write')
|
2010-10-09 15:01:22 +00:00
|
|
|
->with("\033[31;4mBad\033[0m \033[33mWarning\033[0m Regular");
|
2010-10-03 22:54:34 +00:00
|
|
|
|
|
|
|
$this->output->write('<error>Bad</error> <warning>Warning</warning> Regular', false);
|
|
|
|
}
|
|
|
|
|
2010-10-14 01:09:33 +00:00
|
|
|
/**
|
|
|
|
* test that multiple tags of the same name work in one string.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testFormattingMultipleSameTags() {
|
2010-10-15 02:16:42 +00:00
|
|
|
$this->output->expects($this->once())->method('_write')
|
|
|
|
->with("\033[31;4mBad\033[0m \033[31;4mWarning\033[0m Regular");
|
|
|
|
|
|
|
|
$this->output->write('<error>Bad</error> <error>Warning</error> Regular', false);
|
2010-10-14 01:09:33 +00:00
|
|
|
}
|
|
|
|
|
2010-10-03 18:54:41 +00:00
|
|
|
}
|