FIX Use correct canonical tag on VirtualPage (#2688)

This commit is contained in:
Florian Thoma 2021-11-04 12:59:14 +11:00 committed by GitHub
parent 9f7262f99d
commit 480baa6ef8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -143,9 +143,10 @@ class VirtualPage extends Page
$copied = $this->CopyContentFrom();
if ($copied && $copied->exists()) {
$tags['canonical'] = [
'tag' => 'link',
'attributes' => [
'rel' => 'canonical',
'content' => $copied->AbsoluteLink(),
'href' => $copied->AbsoluteLink(),
],
];
}

View File

@ -7,6 +7,7 @@ use SilverStripe\CMS\Controllers\ModelAsController;
use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\Control\ContentNegotiator;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\ORM\DataObject;
@ -93,6 +94,22 @@ class VirtualPageTest extends FunctionalTest
$this->assertEquals("<p>New content</p>", $vp2->Content);
}
public function testMetaTags()
{
$this->logInWithPermission('ADMIN');
$master = $this->objFromFixture('Page', 'master');
$vp1 = $this->objFromFixture(VirtualPage::class, 'vp1');
// Test with title
$meta = $vp1->MetaTags();
$charset = Config::inst()->get(ContentNegotiator::class, 'encoding');
$this->assertContains('<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'"', $meta);
$this->assertContains('<link rel="canonical" href="'.$master->AbsoluteLink().'"', $meta);
$this->assertContains('<meta name="x-page-id" content="'.$vp1->ID.'"', $meta);
$this->assertContains('<meta name="x-cms-edit-link" content="'.$vp1->CMSEditLink().'"', $meta);
$this->assertContains('<title>'.$master->Title.'</title>', $meta);
}
/**
* Test that, after you publish the source page of a virtual page, all the already published
* virtual pages are published