mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
BUG Fix encoding of SiteTree.MetaTags
This commit is contained in:
parent
9bff36c078
commit
89fbae2c2e
@ -1380,7 +1380,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
public function MetaTags($includeTitle = true) {
|
public function MetaTags($includeTitle = true) {
|
||||||
$tags = "";
|
$tags = "";
|
||||||
if($includeTitle === true || $includeTitle == 'true') {
|
if($includeTitle === true || $includeTitle == 'true') {
|
||||||
$tags .= "<title>" . $this->Title . "</title>\n";
|
$tags .= "<title>" . Convert::raw2xml($this->Title) . "</title>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$generator = trim(Config::inst()->get('SiteTree', 'meta_generator'));
|
$generator = trim(Config::inst()->get('SiteTree', 'meta_generator'));
|
||||||
|
@ -944,6 +944,29 @@ class SiteTreeTest extends SapphireTest {
|
|||||||
Config::inst()->update('SiteTree', 'meta_generator', $generator);
|
Config::inst()->update('SiteTree', 'meta_generator', $generator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests SiteTree::MetaTags
|
||||||
|
* Note that this test makes no assumption on the closing of tags (other than <title></title>)
|
||||||
|
*/
|
||||||
|
public function testMetaTags() {
|
||||||
|
$this->logInWithPermission('ADMIN');
|
||||||
|
$page = $this->objFromFixture('Page', 'metapage');
|
||||||
|
|
||||||
|
// Test with title
|
||||||
|
$meta = $page->MetaTags();
|
||||||
|
$charset = Config::inst()->get('ContentNegotiator', 'encoding');
|
||||||
|
$this->assertContains('<meta http-equiv="Content-type" content="text/html; charset='.$charset.'"', $meta);
|
||||||
|
$this->assertContains('<meta name="description" content="The <br /> and <br> tags"', $meta);
|
||||||
|
$this->assertContains('<link rel="canonical" href="http://www.mysite.com/html-and-xml"', $meta);
|
||||||
|
$this->assertContains('<meta name="x-page-id" content="'.$page->ID.'"', $meta);
|
||||||
|
$this->assertContains('<meta name="x-cms-edit-link" content="'.$page->CMSEditLink().'" />', $meta);
|
||||||
|
$this->assertContains('<title>HTML & XML</title>', $meta);
|
||||||
|
|
||||||
|
// Test without title
|
||||||
|
$meta = $page->MetaTags(false);
|
||||||
|
$this->assertNotContains('<title>', $meta);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that orphaned pages are handled correctly
|
* Test that orphaned pages are handled correctly
|
||||||
*/
|
*/
|
||||||
|
@ -85,6 +85,10 @@ Page:
|
|||||||
Title: Controller
|
Title: Controller
|
||||||
numericonly:
|
numericonly:
|
||||||
Title: 1930
|
Title: 1930
|
||||||
|
metapage:
|
||||||
|
Title: 'HTML & XML'
|
||||||
|
MetaDescription: 'The <br /> and <br> tags'
|
||||||
|
ExtraMeta: '<link rel="canonical" href="http://www.mysite.com/html-and-xml" />'
|
||||||
|
|
||||||
SiteTreeTest_Conflicted:
|
SiteTreeTest_Conflicted:
|
||||||
parent:
|
parent:
|
||||||
@ -101,4 +105,3 @@ RedirectorPage:
|
|||||||
URLSegment: external
|
URLSegment: external
|
||||||
RedirectionType: External
|
RedirectionType: External
|
||||||
ExternalURL: "http://www.google.com?a&b"
|
ExternalURL: "http://www.google.com?a&b"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user