Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUG Fix encoding of SiteTree.MetaTags

  • Loading branch information...
commit 89fbae2c2e5f3cf93b5942f8570cd497f3a032b7 1 parent 9bff36c
@tractorcow tractorcow authored
View
2  code/model/SiteTree.php
@@ -1380,7 +1380,7 @@ public function collateDescendants($condition, &$collator) {
public function MetaTags($includeTitle = true) {
$tags = "";
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'));
View
23 tests/model/SiteTreeTest.php
@@ -945,6 +945,29 @@ public function testMetaTagGeneratorDisabling() {
}
/**
+ * 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
*/
public function testOrphanedPages() {
View
185 tests/model/SiteTreeTest.yml
@@ -1,104 +1,107 @@
Group:
- editors:
- Title: Editors
- admins:
- Title: Administrators
- allsections:
- Title: All Section Editors
- securityadmins:
- Title: Security Admins
+ editors:
+ Title: Editors
+ admins:
+ Title: Administrators
+ allsections:
+ Title: All Section Editors
+ securityadmins:
+ Title: Security Admins
Permission:
- admins:
- Code: ADMIN
- Group: =>Group.admins
- editors:
- Code: CMS_ACCESS_CMSMain
- Group: =>Group.editors
- allsections:
- Code: CMS_ACCESS_LeftAndMain
- Group: =>Group.allsections
- securityadmins:
- Code: CMS_ACCESS_SecurityAdmin
- Group: =>Group.securityadmins
+ admins:
+ Code: ADMIN
+ Group: =>Group.admins
+ editors:
+ Code: CMS_ACCESS_CMSMain
+ Group: =>Group.editors
+ allsections:
+ Code: CMS_ACCESS_LeftAndMain
+ Group: =>Group.allsections
+ securityadmins:
+ Code: CMS_ACCESS_SecurityAdmin
+ Group: =>Group.securityadmins
Member:
- editor:
- FirstName: Test
- Surname: Editor
- Groups: =>Group.editors
- admin:
- FirstName: Test
- Surname: Administrator
- Groups: =>Group.admins
- allsections:
- Groups: =>Group.allsections
- securityadmin:
- Groups: =>Group.securityadmins
+ editor:
+ FirstName: Test
+ Surname: Editor
+ Groups: =>Group.editors
+ admin:
+ FirstName: Test
+ Surname: Administrator
+ Groups: =>Group.admins
+ allsections:
+ Groups: =>Group.allsections
+ securityadmin:
+ Groups: =>Group.securityadmins
Page:
- home:
- Title: Home
- CanEditType: OnlyTheseUsers
- EditorGroups: =>Group.admins
- about:
- Title: About Us
- CanEditType: OnlyTheseUsers
- EditorGroups: =>Group.admins
- staff:
- Title: Staff
- URLSegment: my-staff
- Parent: =>Page.about
- ceo:
- Title: CEO
- Parent: =>Page.staff
- staffduplicate:
- Title: Staff
- URLSegment: my-staff
- Parent: =>Page.about
- products:
- Title: Products
- CanEditType: OnlyTheseUsers
- EditorGroups: =>Group.editors
- product1:
- Title: 1.1 Test Product
- Parent: =>Page.products
- CanEditType: Inherit
- product2:
- Title: Another Product
- Parent: =>Page.products
- CanEditType: Inherit
- product3:
- Title: Another Product
- Parent: =>Page.products
- CanEditType: Inherit
- product4:
- Title: Another Product
- Parent: =>Page.products
- CanEditType: OnlyTheseUsers
- EditorGroups: =>Group.admins
- contact:
- Title: Contact Us
- object:
- Title: Object
- controller:
- Title: Controller
- numericonly:
- Title: 1930
+ home:
+ Title: Home
+ CanEditType: OnlyTheseUsers
+ EditorGroups: =>Group.admins
+ about:
+ Title: About Us
+ CanEditType: OnlyTheseUsers
+ EditorGroups: =>Group.admins
+ staff:
+ Title: Staff
+ URLSegment: my-staff
+ Parent: =>Page.about
+ ceo:
+ Title: CEO
+ Parent: =>Page.staff
+ staffduplicate:
+ Title: Staff
+ URLSegment: my-staff
+ Parent: =>Page.about
+ products:
+ Title: Products
+ CanEditType: OnlyTheseUsers
+ EditorGroups: =>Group.editors
+ product1:
+ Title: 1.1 Test Product
+ Parent: =>Page.products
+ CanEditType: Inherit
+ product2:
+ Title: Another Product
+ Parent: =>Page.products
+ CanEditType: Inherit
+ product3:
+ Title: Another Product
+ Parent: =>Page.products
+ CanEditType: Inherit
+ product4:
+ Title: Another Product
+ Parent: =>Page.products
+ CanEditType: OnlyTheseUsers
+ EditorGroups: =>Group.admins
+ contact:
+ Title: Contact Us
+ object:
+ Title: Object
+ controller:
+ Title: Controller
+ numericonly:
+ 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:
- parent:
- Title: Parent
+ parent:
+ Title: Parent
ErrorPage:
- 404:
- Title: Page not Found
- ErrorCode: 404
+ 404:
+ Title: Page not Found
+ ErrorCode: 404
RedirectorPage:
- external:
- Title: External
- URLSegment: external
- RedirectionType: External
- ExternalURL: "http://www.google.com?a&b"
-
+ external:
+ Title: External
+ URLSegment: external
+ RedirectionType: External
+ ExternalURL: "http://www.google.com?a&b"
Please sign in to comment.
Something went wrong with that request. Please try again.