Skip to content

Commit

Permalink
FIX #606, get correct URL for categories if Blog is on /home
Browse files Browse the repository at this point in the history
  • Loading branch information
lerni committed Jan 24, 2025
1 parent f168f1e commit 9de7564
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Model/BlogObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
));
}

/**
Expand Down
30 changes: 30 additions & 0 deletions tests/php/BlogCategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 9de7564

Please sign in to comment.