BUG Fix encoding of SiteTree.MetaTags

This commit is contained in:
Damian Mooyman 2014-04-29 08:54:17 +12:00
parent 9bff36c078
commit 89fbae2c2e
3 changed files with 118 additions and 92 deletions

View File

@ -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'));

View File

@ -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 &lt;br /&gt; and &lt;br&gt; 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 &amp; 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
*/ */

View File

@ -1,104 +1,107 @@
Group: Group:
editors: editors:
Title: Editors Title: Editors
admins: admins:
Title: Administrators Title: Administrators
allsections: allsections:
Title: All Section Editors Title: All Section Editors
securityadmins: securityadmins:
Title: Security Admins Title: Security Admins
Permission: Permission:
admins: admins:
Code: ADMIN Code: ADMIN
Group: =>Group.admins Group: =>Group.admins
editors: editors:
Code: CMS_ACCESS_CMSMain Code: CMS_ACCESS_CMSMain
Group: =>Group.editors Group: =>Group.editors
allsections: allsections:
Code: CMS_ACCESS_LeftAndMain Code: CMS_ACCESS_LeftAndMain
Group: =>Group.allsections Group: =>Group.allsections
securityadmins: securityadmins:
Code: CMS_ACCESS_SecurityAdmin Code: CMS_ACCESS_SecurityAdmin
Group: =>Group.securityadmins Group: =>Group.securityadmins
Member: Member:
editor: editor:
FirstName: Test FirstName: Test
Surname: Editor Surname: Editor
Groups: =>Group.editors Groups: =>Group.editors
admin: admin:
FirstName: Test FirstName: Test
Surname: Administrator Surname: Administrator
Groups: =>Group.admins Groups: =>Group.admins
allsections: allsections:
Groups: =>Group.allsections Groups: =>Group.allsections
securityadmin: securityadmin:
Groups: =>Group.securityadmins Groups: =>Group.securityadmins
Page: Page:
home: home:
Title: Home Title: Home
CanEditType: OnlyTheseUsers CanEditType: OnlyTheseUsers
EditorGroups: =>Group.admins EditorGroups: =>Group.admins
about: about:
Title: About Us Title: About Us
CanEditType: OnlyTheseUsers CanEditType: OnlyTheseUsers
EditorGroups: =>Group.admins EditorGroups: =>Group.admins
staff: staff:
Title: Staff Title: Staff
URLSegment: my-staff URLSegment: my-staff
Parent: =>Page.about Parent: =>Page.about
ceo: ceo:
Title: CEO Title: CEO
Parent: =>Page.staff Parent: =>Page.staff
staffduplicate: staffduplicate:
Title: Staff Title: Staff
URLSegment: my-staff URLSegment: my-staff
Parent: =>Page.about Parent: =>Page.about
products: products:
Title: Products Title: Products
CanEditType: OnlyTheseUsers CanEditType: OnlyTheseUsers
EditorGroups: =>Group.editors EditorGroups: =>Group.editors
product1: product1:
Title: 1.1 Test Product Title: 1.1 Test Product
Parent: =>Page.products Parent: =>Page.products
CanEditType: Inherit CanEditType: Inherit
product2: product2:
Title: Another Product Title: Another Product
Parent: =>Page.products Parent: =>Page.products
CanEditType: Inherit CanEditType: Inherit
product3: product3:
Title: Another Product Title: Another Product
Parent: =>Page.products Parent: =>Page.products
CanEditType: Inherit CanEditType: Inherit
product4: product4:
Title: Another Product Title: Another Product
Parent: =>Page.products Parent: =>Page.products
CanEditType: OnlyTheseUsers CanEditType: OnlyTheseUsers
EditorGroups: =>Group.admins EditorGroups: =>Group.admins
contact: contact:
Title: Contact Us Title: Contact Us
object: object:
Title: Object Title: Object
controller: controller:
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:
Title: Parent Title: Parent
ErrorPage: ErrorPage:
404: 404:
Title: Page not Found Title: Page not Found
ErrorCode: 404 ErrorCode: 404
RedirectorPage: RedirectorPage:
external: external:
Title: External Title: External
URLSegment: external URLSegment: external
RedirectionType: External RedirectionType: External
ExternalURL: "http://www.google.com?a&b" ExternalURL: "http://www.google.com?a&b"