diff --git a/src/Model/BlogObject.php b/src/Model/BlogObject.php index c24e1556..a0f176b2 100644 --- a/src/Model/BlogObject.php +++ b/src/Model/BlogObject.php @@ -82,11 +82,10 @@ public function validate() */ public function getLink() { - return Controller::join_links( - $this->Blog()->Link(), + return $this->Blog()->Link(Controller::join_links( $this->getListUrlSegment(), $this->URLSegment - ); + )); } /** diff --git a/tests/php/BlogCategoryTest.php b/tests/php/BlogCategoryTest.php index c189e32d..204917e3 100755 --- a/tests/php/BlogCategoryTest.php +++ b/tests/php/BlogCategoryTest.php @@ -167,4 +167,34 @@ public function testDuplicateCategories() $this->assertEquals(BlogTag::DUPLICATE_EXCEPTION, $messages[0]['messageType']); } } + + /** + * @see https://github.com/silverstripe/silverstripe-blog/issues/606 + */ + public function testGetLink() + { + // Test normal blog location + $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); + $cat = new BlogCategory(); + $cat->BlogID = $blog->ID; + $cat->Title = 'Test Category'; + $cat->write(); + + $expectedLink = '/first-blog/category/test-category'; + $this->assertEquals($expectedLink, $cat->getLink()); + + // Test homepage blog location + $homeBlog = new Blog(); + $homeBlog->Title = 'Home Blog'; + $homeBlog->URLSegment = 'home'; + $homeBlog->write(); + + $homeCat = new BlogCategory(); + $homeCat->BlogID = $homeBlog->ID; + $homeCat->Title = 'Home Category'; + $homeCat->write(); + + $expectedHomeLink = '/home/category/home-category'; + $this->assertEquals($expectedHomeLink, $homeCat->getLink()); + } }