Browse Source

`BreadcrumbsHelper::render()` returns null with no crumbs

Mirko Pagliai 9 years ago
parent
commit
dc14d47615

+ 5 - 1
src/View/Helper/BreadcrumbsHelper.php

@@ -235,10 +235,14 @@ class BreadcrumbsHelper extends Helper
      * - *innerAttrs* To provide attributes in case your separator is divided in two elements.
      * All other properties will be converted as HTML attributes and will replace the *attrs* key in the template.
      * If you use the default for this option (empty), it will not render a separator.
-     * @return string The breadcrumbs trail
+     * @return string|null The breadcrumbs trail
      */
     public function render(array $attributes = [], array $separator = [])
     {
+        if (empty($this->crumbs)) {
+            return null;
+        }
+
         $crumbs = $this->crumbs;
         $crumbsCount = count($crumbs);
         $templater = $this->templater();

+ 2 - 0
tests/TestCase/View/Helper/BreadcrumbsHelperTest.php

@@ -357,6 +357,8 @@ class BreadcrumbsHelperTest extends TestCase
      */
     public function testRender()
     {
+        $this->assertEmpty($this->breadcrumbs->render());
+
         $this->breadcrumbs
             ->add('Home', '/', ['class' => 'first', 'innerAttrs' => ['data-foo' => 'bar']])
             ->add('Some text', ['controller' => 'tests_apps', 'action' => 'some_method'])