Skip to content

Commit

Permalink
Fix tableCells()
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Scherer committed May 2, 2015
1 parent 1cc7fce commit 4915e80
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,21 @@ public function testTableCells() {
$result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'), false, false);
$expected = "<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
$this->assertEquals($expected, $result);

$tr = array(
'td content 1',
'td content 2',
array('td content 3', array('class' => 'foo'))
);
$result = $this->Html->tableCells($tr, null, null, true);
$expected = array(
'<tr',
array('td' => array('class' => 'column-1')), 'td content 1', '/td',
array('td' => array('class' => 'column-2')), 'td content 2', '/td',
array('td' => array('class' => 'foo column-3')), 'td content 3', '/td',
'/tr'
);
$this->assertTags($result, $expected);
}

/**
Expand Down
11 changes: 9 additions & 2 deletions lib/Cake/View/Helper/HtmlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -901,9 +901,16 @@ public function tableCells($data, $oddTrOptions = null, $evenTrOptions = null, $
if (is_array($cell)) {
$cellOptions = $cell[1];
$cell = $cell[0];
} elseif ($useCount) {
$cellOptions['class'] = 'column-' . ++$i;
}

if ($useCount) {
if (isset($cellOptions['class'])) {
$cellOptions['class'] .= ' column-' . ++$i;
} else {
$cellOptions['class'] = 'column-' . ++$i;
}
}

$cellsOut[] = sprintf($this->_tags['tablecell'], $this->_parseAttributes($cellOptions), $cell);
}
$options = $this->_parseAttributes($count % 2 ? $oddTrOptions : $evenTrOptions);
Expand Down

0 comments on commit 4915e80

Please sign in to comment.