diff --git a/src/View/Helper/BreadcrumbsHelper.php b/src/View/Helper/BreadcrumbsHelper.php index 393c6eadf23..8f5651d23f5 100644 --- a/src/View/Helper/BreadcrumbsHelper.php +++ b/src/View/Helper/BreadcrumbsHelper.php @@ -194,7 +194,7 @@ public function insertAfter($matchingTitle, $title, $url = null, array $options throw new LogicException(sprintf("No crumb matching '%s' could be found.", $matchingTitle)); } - return $this->insertAt($key, $title, $url, $options); + return $this->insertAt($key + 1, $title, $url, $options); } /** diff --git a/tests/TestCase/View/Helper/BreadcrumbsHelperTest.php b/tests/TestCase/View/Helper/BreadcrumbsHelperTest.php index 91c09d8c00c..7678793028f 100644 --- a/tests/TestCase/View/Helper/BreadcrumbsHelperTest.php +++ b/tests/TestCase/View/Helper/BreadcrumbsHelperTest.php @@ -42,6 +42,7 @@ public function setUp() /** * Test adding crumbs to the trail using add() + * * @return void */ public function testAdd() @@ -74,6 +75,7 @@ public function testAdd() /** * Test adding multiple crumbs at once to the trail using add() + * * @return void */ public function testAddMultiple() @@ -122,6 +124,7 @@ public function testAddMultiple() /** * Test adding crumbs to the trail using prepend() + * * @return void */ public function testPrepend() @@ -159,6 +162,7 @@ public function testPrepend() /** * Test adding crumbs to a specific index + * * @return void */ public function testInsertAt() @@ -206,8 +210,21 @@ public function testInsertAt() $this->assertEquals($expected, $result); } + /** + * Test adding crumbs to a specific index + * + * @expectedException \LogicException + */ + public function testInsertAtIndexOutOfBounds() + { + $this->breadcrumbs + ->add('Home', '/', ['class' => 'first']) + ->insertAt(2, 'Insert At Again', ['controller' => 'Insert', 'action' => 'at_again']); + } + /** * Test adding crumbs before a specific one + * * @return void */ public function testInsertBefore() @@ -251,6 +268,7 @@ public function testInsertBefore() /** * Test adding crumbs after a specific one + * * @return void */ public function testInsertAfter() @@ -294,6 +312,7 @@ public function testInsertAfter() /** * Tests the render method + * * @return void */ public function testRender() @@ -343,6 +362,7 @@ public function testRender() /** * Tests the render method with custom templates + * * @return void */ public function testRenderCustomTemplate() @@ -383,6 +403,7 @@ public function testRenderCustomTemplate() /** * Tests the render method with template vars + * * @return void */ public function testRenderCustomTemplateTemplateVars()