Skip to content

Fixed colspan issues with multiple render() calls #14983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Symfony/Component/Console/Helper/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class Table
*/
private $rows = array();

/**
* Original table rows.
*
* @var array
*/
private $originalRows = array();

/**
* Column widths cache.
*
Expand Down Expand Up @@ -205,6 +212,8 @@ public function setRow($column, array $row)
public function render()
{
$this->calculateNumberOfColumns();

$this->originalRows = $this->rows;
$this->rows = $this->buildTableRows($this->rows);
$this->headers = $this->buildTableRows($this->headers);

Expand Down Expand Up @@ -567,6 +576,7 @@ private function getCellWidth(array $row, $column)
*/
private function cleanup()
{
$this->rows = $this->originalRows;
$this->columnWidths = array();
$this->numberOfColumns = null;
}
Expand Down
37 changes: 32 additions & 5 deletions src/Symfony/Component/Console/Tests/Helper/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ public function testRenderProvider()
array(
array('ISBN', 'Title', 'Author'),
array(
array("99921-58-10-7", "Divine\nComedy", "Dante Alighieri"),
array("9971-5-0210-2", "Harry Potter\nand the Chamber of Secrets", "Rowling\nJoanne K."),
array("9971-5-0210-2", "Harry Potter\nand the Chamber of Secrets", "Rowling\nJoanne K."),
array("960-425-059-0", "The Lord of the Rings", "J. R. R.\nTolkien"),
array('99921-58-10-7', "Divine\nComedy", 'Dante Alighieri'),
array('9971-5-0210-2', "Harry Potter\nand the Chamber of Secrets", "Rowling\nJoanne K."),
array('9971-5-0210-2', "Harry Potter\nand the Chamber of Secrets", "Rowling\nJoanne K."),
array('960-425-059-0', 'The Lord of the Rings', "J. R. R.\nTolkien"),
),
'default',
<<<TABLE
Expand Down Expand Up @@ -427,7 +427,7 @@ public function testRenderProvider()
array('ISBN', 'Author'),
array(
array(
new TableCell("9971-5-0210-0", array('rowspan' => 3, 'colspan' => 1)),
new TableCell('9971-5-0210-0', array('rowspan' => 3, 'colspan' => 1)),
'Dante Alighieri',
),
array(new TableSeparator()),
Expand Down Expand Up @@ -547,6 +547,33 @@ public function testRowSeparator()
| Bar3 |
+------+

TABLE;

$this->assertEquals($expected, $this->getOutputContent($output));
}

public function testColspans()
{
$table = new Table($output = $this->getOutputStream());
$table->setRows(array(
array(new TableCell('foo', array('colspan' => 2))),
));
$table->render();
$table->render();
$table->render();

$expected =
<<<TABLE
+---+--+
| foo |
+---+--+
+---+--+
| foo |
+---+--+
+---+--+
| foo |
+---+--+

TABLE;

$this->assertEquals($expected, $this->getOutputContent($output));
Expand Down