Browse Source

Add reset method to BreadcrumbsHelper

Cory Thompson 9 years ago
parent
commit
e49d0957c0

+ 12 - 0
src/View/Helper/BreadcrumbsHelper.php

@@ -224,6 +224,18 @@ class BreadcrumbsHelper extends Helper
     }
 
     /**
+     * Removes all existing crumbs.
+     *
+     * @return $this
+     */
+    public function reset()
+    {
+        $this->crumbs = [];
+
+        return $this;
+    }
+
+    /**
      * Renders the breadcrumbs trail.
      *
      * @param array $attributes Array of attributes applied to the `wrapper` template. Accepts the `templateVars` key to

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

@@ -201,6 +201,24 @@ class BreadcrumbsHelperTest extends TestCase
     }
 
     /**
+     * Test ability to empty crumbs list.
+     *
+     * @return void
+     */
+    public function testReset()
+    {
+        $this->breadcrumbs->add('Home', '/');
+        $this->breadcrumbs->add('Products', '/products');
+
+        $crumbs = $this->breadcrumbs->getCrumbs();
+        $this->assertEquals(count($crumbs), 2);
+
+        $this->breadcrumbs->reset();
+        $actual = $this->breadcrumbs->getCrumbs();
+        $this->assertEquals($actual, []);
+    }
+
+    /**
      * Test adding crumbs to a specific index
      *
      * @return void