Permalink
Browse files

Fix failing test & simplify code.

  • Loading branch information...
1 parent c752b75 commit a3ddff4aa7b01a9abebc2b614a19f729d1554be8 @markstory markstory committed Nov 17, 2012
Showing with 39 additions and 38 deletions.
  1. +13 −9 lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
  2. +26 −29 lib/Cake/View/Helper/HtmlHelper.php
@@ -1856,27 +1856,31 @@ public function testCrumbListFirstLink() {
* @return void
*/
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('Data');
- $result = $this->Html->getCrumbList(
- array('class' => 'breadcrumb', 'separator' => '<span class="divider">/</span>', 'firstClass' => false, 'lastClass' => 'active')
- );
+ $result = $this->Html->getCrumbList(array(
+ 'class' => 'breadcrumb',
+ 'separator' => '<span class="divider">-</span>',
+ 'firstClass' => false,
+ 'lastClass' => 'active'
+ ));
+ debug($result);
$this->assertTags(
$result,
array(
array('ul' => array('class' => 'breadcrumb')),
'<li',
- array('a' => array('href' => '/')), 'Home', '/a',
- array('span' =>array('class' => 'divider')), 'preg:/\//', '/span',
+ array('a' => array('class' => 'home', 'href' => '/')), 'Home', '/a',
+ array('span' =>array('class' => 'divider')), '-', '/span',
'/li',
'<li',
array('a' => array('href' => '/lib')), 'Library', '/a',
- array('span' => array('class' => 'divider')), 'preg:/\//', '/span',
+ array('span' => array('class' => 'divider')), '-', '/span',
'/li',
array('li' => array('class' => 'active')), 'Data', '/li',
'/ul'
- ), true
+ )
);
}
@@ -1996,4 +2000,4 @@ public function testParseAttributeCompact() {
$this->assertEquals('', $helper->parseAttributes(array('require' => false)));
}
-}
+}
@@ -699,37 +699,34 @@ public function getCrumbList($options = array(), $startText = false) {
$firstClass = $options['firstClass'];
$lastClass = $options['lastClass'];
$separator = $options['separator'];
- unset($options['firstClass'], $options['lastClass'], $options['separator']);
+ unset($options['firstClass'], $options['lastClass'], $options['separator']);
+
$crumbs = $this->_prepareCrumbs($startText);
- if (!empty($crumbs)) {
- $result = '';
- $crumbCount = count($crumbs);
- $ulOptions = $options;
- foreach ($crumbs as $which => $crumb) {
- $options = array();
- if (empty($crumb[1])) {
- $elementContent = $crumb[0];
- } else {
- $elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]);
- }
- if (!$which) {
- if ($firstClass !== false) {
- $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);
+ if (empty($crumbs)) {
+ return '';
+ }
+
+ $result = '';
+ $crumbCount = count($crumbs);
+ $ulOptions = $options;
+ foreach ($crumbs as $which => $crumb) {
+ $options = array();
+ if (empty($crumb[1])) {
+ $elementContent = $crumb[0];
+ } else {
+ $elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]);
}
- return $this->tag('ul', $result, $ulOptions);
- } else {
- return null;
+ if (!$which && $firstClass !== false) {
+ $options['class'] = $firstClass;
+ } 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);
}
/**
@@ -1229,4 +1226,4 @@ public function loadConfig($configFile, $path = null) {
return $configs;
}
-}
+}

0 comments on commit a3ddff4

Please sign in to comment.