From ed0680a26464dbc37ef35a3abd4e63014e361fd3 Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Fri, 1 Feb 2019 16:00:11 +1300 Subject: [PATCH] MINOR Add unit test for MetaComponents --- code/Model/SiteTree.php | 3 +- tests/php/Model/SiteTreeTest.php | 51 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/code/Model/SiteTree.php b/code/Model/SiteTree.php index 5b404c31..046eba3a 100755 --- a/code/Model/SiteTree.php +++ b/code/Model/SiteTree.php @@ -1380,7 +1380,6 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi $tags['title'] = [ 'tag' => 'title', - 'attributes' => [], 'content' => $this->obj('Title')->forTemplate() ]; @@ -1442,7 +1441,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi { $tags = []; $tagsArray = $this->MetaComponents(); - if (!$includeTitle) { + if (!$includeTitle || strtolower($includeTitle) == 'false') { unset($tagsArray['title']); } diff --git a/tests/php/Model/SiteTreeTest.php b/tests/php/Model/SiteTreeTest.php index e914129a..03b85493 100644 --- a/tests/php/Model/SiteTreeTest.php +++ b/tests/php/Model/SiteTreeTest.php @@ -1353,6 +1353,57 @@ class SiteTreeTest extends SapphireTest // Test without title $meta = $page->MetaTags(false); $this->assertNotContains('', $meta); + + $meta = $page->MetaTags('false'); + $this->assertNotContains('<title>', $meta); + } + + public function testMetaComponents() + { + $this->logInWithPermission('ADMIN'); + /** @var SiteTree $page */ + $page = $this->objFromFixture('Page', 'metapage'); + + $charset = Config::inst()->get(ContentNegotiator::class, 'encoding'); + + $expected = [ + 'title' => [ + 'tag' => 'title', + 'content' => "HTML & XML", + ], + 'generator' => [ + 'attributes' => [ + 'name' => 'generator', + 'content' => Config::inst()->get(SiteTree::class, 'meta_generator') + ], + ], + 'contentType' => [ + 'attributes' => [ + 'http-equiv' => 'Content-Type', + 'content' => "text/html; charset=$charset", + ], + ], + 'description' => [ + 'attributes' => [ + 'name' => 'description', + 'content' => 'The <br /> and <br> tags' + ] + ], + 'pageId' => [ + 'attributes' => [ + 'name' => 'x-page-id', + 'content' => $page->ID + ], + ], + 'cmsEditLink' => [ + 'attributes' => [ + 'name' => 'x-cms-edit-link', + 'content' => $page->CMSEditLink() + ] + ] + ]; + + $this->assertEquals($expected, $page->MetaComponents()); } /**