Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX #606, correct URL for categories if Blog is on /home #804

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
Loading