Merge branch '3' into 4

This commit is contained in:
github-actions 2024-08-14 23:47:27 +00:00
commit ff1b8dd52b
2 changed files with 19 additions and 3 deletions

View File

@ -217,9 +217,11 @@ class SubsiteDomain extends DataObject
*/ */
public function absoluteBaseURL() public function absoluteBaseURL()
{ {
return Controller::join_links( $slash = Controller::config()->get('add_trailing_slash') ? '/' : '';
$baseURL = Controller::join_links(
$this->getAbsoluteLink(), $this->getAbsoluteLink(),
Director::baseURL() Director::baseURL()
); );
return (rtrim($baseURL, '/')) . $slash;
} }
} }

View File

@ -4,6 +4,7 @@ namespace SilverStripe\Subsites\Tests;
use Page; use Page;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
@ -304,7 +305,7 @@ class SubsiteTest extends BaseSubsiteTest
// If there is a Director::baseURL() value this will also be included // If there is a Director::baseURL() value this will also be included
$this->assertEquals( $this->assertEquals(
'http://' . $_SERVER['HTTP_HOST'], $this->normaliseTrailingSlash('http://' . $_SERVER['HTTP_HOST']),
singleton(Subsite::class)->absoluteBaseURL() singleton(Subsite::class)->absoluteBaseURL()
); );
} }
@ -324,7 +325,7 @@ class SubsiteTest extends BaseSubsiteTest
$model = $this->objFromFixture($class, $identifier); $model = $this->objFromFixture($class, $identifier);
$protocol = $currentIsSecure ? 'https' : 'http'; $protocol = $currentIsSecure ? 'https' : 'http';
Config::modify()->set(Director::class, 'alternate_base_url', $protocol . '://www.mysite.com'); Config::modify()->set(Director::class, 'alternate_base_url', $protocol . '://www.mysite.com');
$this->assertSame($expected, $model->absoluteBaseURL()); $this->assertSame($this->normaliseTrailingSlash($expected), $model->absoluteBaseURL());
} }
public function domainProtocolProvider() public function domainProtocolProvider()
@ -502,4 +503,17 @@ class SubsiteTest extends BaseSubsiteTest
$pages = SiteTree::get(); $pages = SiteTree::get();
$this->assertGreaterThanOrEqual(1, $pages->count()); $this->assertGreaterThanOrEqual(1, $pages->count());
} }
/**
* Normalises a test URL's trailing slash, but ignores complexities
* such as whether the domain host in the UR matches Director::host()
*/
private function normaliseTrailingSlash(string $testURL): string
{
if ($testURL === '/' || $testURL === '') {
return '/';
}
$slash = Controller::config()->get('add_trailing_slash') ? '/' : '';
return (rtrim($testURL, '/')) . $slash;
}
} }