Skip to content

Commit

Permalink
Fix failing test & simplify code.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 17, 2012
1 parent c752b75 commit a3ddff4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
22 changes: 13 additions & 9 deletions lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1856,27 +1856,31 @@ public function testCrumbListFirstLink() {
* @return void * @return void
*/ */
public function testCrumbListBootstrapStyle() { public function testCrumbListBootstrapStyle() {
$this->Html->addCrumb('Home', '/', array('class'=>'home')); $this->Html->addCrumb('Home', '/', array('class' => 'home'));
$this->Html->addCrumb('Library', '/lib'); $this->Html->addCrumb('Library', '/lib');
$this->Html->addCrumb('Data'); $this->Html->addCrumb('Data');
$result = $this->Html->getCrumbList( $result = $this->Html->getCrumbList(array(
array('class' => 'breadcrumb', 'separator' => '<span class="divider">/</span>', 'firstClass' => false, 'lastClass' => 'active') 'class' => 'breadcrumb',
); 'separator' => '<span class="divider">-</span>',
'firstClass' => false,
'lastClass' => 'active'
));
debug($result);
$this->assertTags( $this->assertTags(
$result, $result,
array( array(
array('ul' => array('class' => 'breadcrumb')), array('ul' => array('class' => 'breadcrumb')),
'<li', '<li',
array('a' => array('href' => '/')), 'Home', '/a', array('a' => array('class' => 'home', 'href' => '/')), 'Home', '/a',
array('span' =>array('class' => 'divider')), 'preg:/\//', '/span', array('span' =>array('class' => 'divider')), '-', '/span',
'/li', '/li',
'<li', '<li',
array('a' => array('href' => '/lib')), 'Library', '/a', array('a' => array('href' => '/lib')), 'Library', '/a',
array('span' => array('class' => 'divider')), 'preg:/\//', '/span', array('span' => array('class' => 'divider')), '-', '/span',
'/li', '/li',
array('li' => array('class' => 'active')), 'Data', '/li', array('li' => array('class' => 'active')), 'Data', '/li',
'/ul' '/ul'
), true )
); );
} }


Expand Down Expand Up @@ -1996,4 +2000,4 @@ public function testParseAttributeCompact() {
$this->assertEquals('', $helper->parseAttributes(array('require' => false))); $this->assertEquals('', $helper->parseAttributes(array('require' => false)));
} }


} }
55 changes: 26 additions & 29 deletions lib/Cake/View/Helper/HtmlHelper.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -699,37 +699,34 @@ public function getCrumbList($options = array(), $startText = false) {
$firstClass = $options['firstClass']; $firstClass = $options['firstClass'];
$lastClass = $options['lastClass']; $lastClass = $options['lastClass'];
$separator = $options['separator']; $separator = $options['separator'];
unset($options['firstClass'], $options['lastClass'], $options['separator']); unset($options['firstClass'], $options['lastClass'], $options['separator']);

$crumbs = $this->_prepareCrumbs($startText); $crumbs = $this->_prepareCrumbs($startText);
if (!empty($crumbs)) { if (empty($crumbs)) {
$result = ''; return '';
$crumbCount = count($crumbs); }
$ulOptions = $options;
foreach ($crumbs as $which => $crumb) { $result = '';
$options = array(); $crumbCount = count($crumbs);
if (empty($crumb[1])) { $ulOptions = $options;
$elementContent = $crumb[0]; foreach ($crumbs as $which => $crumb) {
} else { $options = array();
$elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]); if (empty($crumb[1])) {
} $elementContent = $crumb[0];
if (!$which) { } else {
if ($firstClass !== false) { $elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]);
$options['class'] = $firstClass;
}
} elseif ($which == $crumbCount - 1) {
if ($lastClass !== false) {
$options['class'] = $lastClass;
}
}
if (!empty($separator) && ($crumbCount - $which >= 2)) {
$elementContent .= $separator;
}
$result .= $this->tag('li', $elementContent, $options);
} }
return $this->tag('ul', $result, $ulOptions); if (!$which && $firstClass !== false) {
} else { $options['class'] = $firstClass;
return null; } elseif ($which == $crumbCount - 1 && $lastClass !== false) {
$options['class'] = $lastClass;
}
if (!empty($separator) && ($crumbCount - $which >= 2)) {
$elementContent .= $separator;
}
$result .= $this->tag('li', $elementContent, $options);
} }
return $this->tag('ul', $result, $ulOptions);
} }


/** /**
Expand Down Expand Up @@ -1229,4 +1226,4 @@ public function loadConfig($configFile, $path = null) {
return $configs; return $configs;
} }


} }

0 comments on commit a3ddff4

Please sign in to comment.