[Console] Fix TableCell issues with decoration

This commit is contained in:
Maxime Steinhausser 2017-01-27 19:52:37 +01:00
parent bc391c130e
commit 50373f3530
2 changed files with 38 additions and 9 deletions

View File

@ -518,7 +518,7 @@ class Table
foreach ($row as $i => $cell) { foreach ($row as $i => $cell) {
if ($cell instanceof TableCell) { if ($cell instanceof TableCell) {
$textLength = strlen($cell); $textLength = Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
if ($textLength > 0) { if ($textLength > 0) {
$contentColumns = str_split($cell, ceil($textLength / $cell->getColspan())); $contentColumns = str_split($cell, ceil($textLength / $cell->getColspan()));
foreach ($contentColumns as $position => $content) { foreach ($contentColumns as $position => $content) {

View File

@ -35,9 +35,9 @@ class TableTest extends \PHPUnit_Framework_TestCase
/** /**
* @dataProvider testRenderProvider * @dataProvider testRenderProvider
*/ */
public function testRender($headers, $rows, $style, $expected) public function testRender($headers, $rows, $style, $expected, $decorated = false)
{ {
$table = new Table($output = $this->getOutputStream()); $table = new Table($output = $this->getOutputStream($decorated));
$table $table
->setHeaders($headers) ->setHeaders($headers)
->setRows($rows) ->setRows($rows)
@ -51,9 +51,9 @@ class TableTest extends \PHPUnit_Framework_TestCase
/** /**
* @dataProvider testRenderProvider * @dataProvider testRenderProvider
*/ */
public function testRenderAddRows($headers, $rows, $style, $expected) public function testRenderAddRows($headers, $rows, $style, $expected, $decorated = false)
{ {
$table = new Table($output = $this->getOutputStream()); $table = new Table($output = $this->getOutputStream($decorated));
$table $table
->setHeaders($headers) ->setHeaders($headers)
->addRows($rows) ->addRows($rows)
@ -67,9 +67,9 @@ class TableTest extends \PHPUnit_Framework_TestCase
/** /**
* @dataProvider testRenderProvider * @dataProvider testRenderProvider
*/ */
public function testRenderAddRowsOneByOne($headers, $rows, $style, $expected) public function testRenderAddRowsOneByOne($headers, $rows, $style, $expected, $decorated = false)
{ {
$table = new Table($output = $this->getOutputStream()); $table = new Table($output = $this->getOutputStream($decorated));
$table $table
->setHeaders($headers) ->setHeaders($headers)
->setStyle($style) ->setStyle($style)
@ -485,6 +485,35 @@ TABLE
TABLE TABLE
), ),
'Coslpan and table cells with comment style' => array(
array(
new TableCell('<comment>Long Title</comment>', array('colspan' => 3)),
),
array(
array(
new TableCell('9971-5-0210-0', array('colspan' => 3)),
),
new TableSeparator(),
array(
'Dante Alighieri',
'J. R. R. Tolkien',
'J. R. R',
),
),
'default',
<<<TABLE
+-----------------+------------------+---------+
|\033[32m \033[39m\033[33mLong Title\033[39m\033[32m \033[39m|
+-----------------+------------------+---------+
| 9971-5-0210-0 |
+-----------------+------------------+---------+
| Dante Alighieri | J. R. R. Tolkien | J. R. R |
+-----------------+------------------+---------+
TABLE
,
true,
),
); );
} }
@ -596,9 +625,9 @@ TABLE;
Table::getStyleDefinition('absent'); Table::getStyleDefinition('absent');
} }
protected function getOutputStream() protected function getOutputStream($decorated = false)
{ {
return new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, false); return new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, $decorated);
} }
protected function getOutputContent(StreamOutput $output) protected function getOutputContent(StreamOutput $output)