class Regular {
+ function __construct( $in_color ) {
+ $this->in_color = $in_color;
+ }
+
+ protected function write( $handle, $str ) {
+ fwrite( $handle, $str );
+ }
+
private function _line( $message, $label, $color, $handle = STDOUT ) {
- fwrite( $handle, \WP_CLI::colorize( "$color$label:%n" ) . " $message\n" );
+ $label = \cli\Colors::colorize( "$color$label:%n", $this->in_color );
+ $this->write( $handle, "$label $message\n" );
}
function info( $message ) {
- fwrite( STDOUT, $message . "\n" );
+ $this->write( STDOUT, $message . "\n" );
}
function success( $message ) {
if ( $this->config['quiet'] )
$logger = new \WP_CLI\Loggers\Quiet;
else
- $logger = new \WP_CLI\Loggers\Regular;
+ $logger = new \WP_CLI\Loggers\Regular( $this->in_color() );
WP_CLI::set_logger( $logger );
}
--- /dev/null
+<?php
+
+class LoggerMock extends WP_CLI\Loggers\Regular {
+
+ protected function write( $handle, $str ) {
+ echo $str;
+ }
+}
+
+
+class LoggingTests extends PHPUnit_Framework_TestCase {
+
+ function testLogEscaping() {
+ $logger = new LoggerMock( false );
+
+ $message = 'foo%20bar';
+
+ $this->expectOutputString( "Success: $message\n" );
+ $logger->success( $message );
+ }
+}
+