Skip to content

Commit

Permalink
FIX Use correct canonical tag on VirtualPage (#2688)
Browse files Browse the repository at this point in the history
  • Loading branch information
xini authored Nov 4, 2021
1 parent 9f7262f commit 480baa6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion code/Model/VirtualPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ public function MetaComponents()
$copied = $this->CopyContentFrom();
if ($copied && $copied->exists()) {
$tags['canonical'] = [
'tag' => 'link',
'attributes' => [
'rel' => 'canonical',
'content' => $copied->AbsoluteLink(),
'href' => $copied->AbsoluteLink(),
],
];
}
Expand Down
17 changes: 17 additions & 0 deletions tests/php/Model/VirtualPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -93,6 +94,22 @@ public function testEditingSourcePageUpdatesVirtualPages()
$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
Expand Down

0 comments on commit 480baa6

Please sign in to comment.