Permalink
Browse files

ENHANCEMENT: allow sites to override meta generator tag

  • Loading branch information...
1 parent 4bc942d commit b8908efdf72fcfd72afd4b323f451869acd224c9 @jthomerson jthomerson committed Jun 17, 2013
Showing with 43 additions and 1 deletion.
  1. +12 −1 code/model/SiteTree.php
  2. +31 −0 tests/model/SiteTreeTest.php
View
@@ -203,6 +203,14 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
*/
private static $enforce_strict_hierarchy = true;
+ /**
+ * The value used for the meta generator tag. Leave blank to omit the tag.
+ *
+ * @config
+ * @var string
+ */
+ private static $meta_generator = 'SilverStripe - http://silverstripe.org';
+
protected $_cache_statusFlags = null;
/**
@@ -1298,7 +1306,10 @@ public function MetaTags($includeTitle = true) {
$tags .= "<title>" . $this->Title . "</title>\n";
}
- $tags .= "<meta name=\"generator\" content=\"SilverStripe - http://silverstripe.org\" />\n";
+ $generator = trim(Config::inst()->get('SiteTree', 'meta_generator'));
+ if (!empty($generator)) {
+ $tags .= "<meta name=\"generator\" content=\"" . Convert::raw2att($generator) . "\" />\n";
+ }
$charset = Config::inst()->get('ContentNegotiator', 'encoding');
$tags .= "<meta http-equiv=\"Content-type\" content=\"text/html; charset=$charset\" />\n";
@@ -889,6 +889,37 @@ public function testMenuTitleIsUnsetWhenEqualsTitle() {
$page = SiteTree::get()->byID($page->ID);
$this->assertEquals(null, $page->getField('MenuTitle'));
}
+
+ public function testMetaTagGeneratorDisabling() {
+ $generator = Config::inst()->get('SiteTree', 'meta_generator');
+
+ $page = new SiteTreeTest_PageNode();
+
+ $meta = $page->MetaTags();
+ $this->assertEquals(
+ 1,
+ preg_match('/.*meta name="generator" content="SilverStripe - http:\/\/silverstripe.org".*/', $meta),
+ 'test default functionality - uses value from Config');
+
+ // test proper escaping of quotes in attribute value
+ Config::inst()->update('SiteTree', 'meta_generator', 'Generator with "quotes" in it');
+ $meta = $page->MetaTags();
+ $this->assertEquals(
+ 1,
+ preg_match('/.*meta name="generator" content="Generator with &quot;quotes&quot; in it".*/', $meta),
+ 'test proper escaping of values from Config');
+
+ // test empty generator - no tag should appear at all
+ Config::inst()->update('SiteTree', 'meta_generator', '');
+ $meta = $page->MetaTags();
+ $this->assertEquals(
+ 0,
+ preg_match('/.*meta name=.generator..*/', $meta),
+ 'test blank value means no tag generated');
+
+ // reset original value
+ Config::inst()->update('SiteTree', 'meta_generator', $generator);
+ }
}

0 comments on commit b8908ef

Please sign in to comment.