mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merge pull request #2685 from GuySartorelli/patch-1
FIX: Treat absolute links in a consistent manner in get_by_link.
This commit is contained in:
commit
c754486693
@ -415,9 +415,8 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
|||||||
$urlSegmentExpr = sprintf('"%s"."URLSegment"', $tableName);
|
$urlSegmentExpr = sprintf('"%s"."URLSegment"', $tableName);
|
||||||
$parentIDExpr = sprintf('"%s"."ParentID"', $tableName);
|
$parentIDExpr = sprintf('"%s"."ParentID"', $tableName);
|
||||||
|
|
||||||
if (trim($link, '/')) {
|
|
||||||
$link = trim(Director::makeRelative($link), '/');
|
$link = trim(Director::makeRelative($link), '/');
|
||||||
} else {
|
if (!$link) {
|
||||||
$link = RootURLController::get_homepage_link();
|
$link = RootURLController::get_homepage_link();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,6 +467,21 @@ class SiteTreeTest extends SapphireTest
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetByLinkAbsolute()
|
||||||
|
{
|
||||||
|
$home = $this->objFromFixture('Page', 'home');
|
||||||
|
$about = $this->objFromFixture('Page', 'about');
|
||||||
|
$staff = $this->objFromFixture('Page', 'staff');
|
||||||
|
$product = $this->objFromFixture('Page', 'product1');
|
||||||
|
|
||||||
|
$base = 'https://example.test/';
|
||||||
|
$this->assertEquals($home->ID, SiteTree::get_by_link(Controller::join_links($base, '/'), false)->ID);
|
||||||
|
$this->assertEquals($home->ID, SiteTree::get_by_link(Controller::join_links($base, '/home/'), false)->ID);
|
||||||
|
$this->assertEquals($about->ID, SiteTree::get_by_link(Controller::join_links($base, $about->Link()), false)->ID);
|
||||||
|
$this->assertEquals($staff->ID, SiteTree::get_by_link(Controller::join_links($base, $staff->Link()), false)->ID);
|
||||||
|
$this->assertEquals($product->ID, SiteTree::get_by_link(Controller::join_links($base, $product->Link()), false)->ID);
|
||||||
|
}
|
||||||
|
|
||||||
public function testRelativeLink()
|
public function testRelativeLink()
|
||||||
{
|
{
|
||||||
$about = $this->objFromFixture('Page', 'about');
|
$about = $this->objFromFixture('Page', 'about');
|
||||||
|
Loading…
Reference in New Issue
Block a user