ConsoleTest.php 1.75 KB
Newer Older
1 2 3 4 5 6 7 8
<?php

namespace yiiunit\framework\helpers;

use Yii;
use yii\helpers\Console;
use yiiunit\TestCase;

9 10 11 12
/**
 * @group helpers
 * @group console
 */
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
class ConsoleTest extends TestCase
{
	public function testStripAnsiFormat()
	{
		ob_start();
		ob_implicit_flush(false);
		echo 'a';
		Console::moveCursorForward(1);
		echo 'a';
		Console::moveCursorDown(1);
		echo 'a';
		Console::moveCursorUp(1);
		echo 'a';
		Console::moveCursorBackward(1);
		echo 'a';
		Console::moveCursorNextLine(1);
		echo 'a';
		Console::moveCursorPrevLine(1);
		echo 'a';
		Console::moveCursorTo(1);
		echo 'a';
		Console::moveCursorTo(1, 2);
		echo 'a';
		Console::clearLine();
		echo 'a';
		Console::clearLineAfterCursor();
		echo 'a';
		Console::clearLineBeforeCursor();
		echo 'a';
		Console::clearScreen();
		echo 'a';
		Console::clearScreenAfterCursor();
		echo 'a';
		Console::clearScreenBeforeCursor();
		echo 'a';
		Console::scrollDown();
		echo 'a';
		Console::scrollUp();
		echo 'a';
		Console::hideCursor();
		echo 'a';
		Console::showCursor();
		echo 'a';
		Console::saveCursorPosition();
		echo 'a';
		Console::restoreCursorPosition();
		echo 'a';
Alexander Makarov committed
60
		Console::beginAnsiFormat([Console::FG_GREEN, Console::BG_BLUE, Console::UNDERLINE]);
61 62 63
		echo 'a';
		Console::endAnsiFormat();
		echo 'a';
Alexander Makarov committed
64
		Console::beginAnsiFormat([Console::xtermBgColor(128), Console::xtermFgColor(55)]);
65 66 67 68 69 70 71 72 73 74 75
		echo 'a';
		Console::endAnsiFormat();
		echo 'a';
		$ouput = Console::stripAnsiFormat(ob_get_clean());
		ob_implicit_flush(true);
		// $output = str_replace("\033", 'X003', $ouput );// uncomment for debugging
		$this->assertEquals(str_repeat('a', 25), $ouput);
	}

/*	public function testScreenSize()
	{
76
		for ($i = 1; $i < 20; $i++) {
77 78 79 80 81 82
			echo implode(', ', Console::getScreenSize(true)) . "\n";
			ob_flush();
			sleep(1);
		}
	}*/
}