From 1db69ee91ad8ed7a9c34a8e37b1d9338d1472dcb Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Mon, 15 Nov 2021 14:30:44 +1300 Subject: [PATCH] ENH: Add tests for absolute URLs in get_by_link --- tests/php/Model/SiteTreeTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/php/Model/SiteTreeTest.php b/tests/php/Model/SiteTreeTest.php index aa37f24a..00a139ed 100644 --- a/tests/php/Model/SiteTreeTest.php +++ b/tests/php/Model/SiteTreeTest.php @@ -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() { $about = $this->objFromFixture('Page', 'about');