Skip to content

Commit

Permalink
Merge pull request #1073 from creative-commoners/pulls/4.11/subsites
Browse files Browse the repository at this point in the history
MNT Fix broken unit test when subsites is installed
  • Loading branch information
GuySartorelli authored Jul 5, 2023
2 parents 4e4cbcb + ae496cb commit 405989f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tests/BaseElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,17 +482,25 @@ 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
// whatever's already there
$this->assertSame(1, substr_count($previewLink, '?'));
$this->assertSame(1, substr_count($previewLink, '#'));
} else {
$this->assertSame($link, $previewLink);
$this->assertEmpty(rtrim($previewLink ?? '', '/'));
}
}
}

0 comments on commit 405989f

Please sign in to comment.