From ae496cbd5780b43cbe104a929b8cddc9772e2e57 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 5 Jul 2023 17:12:22 +1200 Subject: [PATCH] MNT Fix broken unit test when subsites is installed --- tests/BaseElementTest.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/BaseElementTest.php b/tests/BaseElementTest.php index f0f58fd9..872bce3e 100644 --- a/tests/BaseElementTest.php +++ b/tests/BaseElementTest.php @@ -482,9 +482,17 @@ public function testPreviewLink(string $class, string $elementIdentifier, ?strin /** @var BaseElement $element */ $element = $this->objFromFixture($class, $elementIdentifier); $previewLink = $element->PreviewLink(); + // Remove SubsiteID from preview link in case subsites is installed + $rx = '/[?|&]SubsiteID=[0-9]+/'; + if (preg_match($rx, $previewLink)) { + $previewLink = preg_replace($rx, '', $previewLink); + } if ($link) { - $regex = '/^' . preg_quote($link, '/') . '[?&]' . preg_quote('ElementalPreview=', '/') + // Note that the preview link is suffixed with forward slash when subsites is installed + // because of BaseElementSubsites::updatePreviewLink() use of HTTP::setGetVar() + // which turns relative urls to absolute urls + $regex = '/^\/?' . preg_quote($link, '/') . '[?&]' . preg_quote('ElementalPreview=', '/') .'\d*#' . $element->getAnchor() . '$/'; $this->assertMatchesRegularExpression($regex, $previewLink); // Doesn't try to blindly append query string and anchor - but instead merges intelligently with @@ -492,7 +500,7 @@ public function testPreviewLink(string $class, string $elementIdentifier, ?strin $this->assertSame(1, substr_count($previewLink, '?')); $this->assertSame(1, substr_count($previewLink, '#')); } else { - $this->assertSame($link, $previewLink); + $this->assertEmpty(rtrim($previewLink ?? '', '/')); } } }