MINOR Add unit test for MetaComponents

This commit is contained in:
Maxime Rainville 2019-02-01 16:00:11 +13:00 committed by Robbie Averill
parent e20be9293f
commit ed0680a264
2 changed files with 52 additions and 2 deletions

View File

@ -1380,7 +1380,6 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$tags['title'] = [ $tags['title'] = [
'tag' => 'title', 'tag' => 'title',
'attributes' => [],
'content' => $this->obj('Title')->forTemplate() 'content' => $this->obj('Title')->forTemplate()
]; ];
@ -1442,7 +1441,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
{ {
$tags = []; $tags = [];
$tagsArray = $this->MetaComponents(); $tagsArray = $this->MetaComponents();
if (!$includeTitle) { if (!$includeTitle || strtolower($includeTitle) == 'false') {
unset($tagsArray['title']); unset($tagsArray['title']);
} }

View File

@ -1353,6 +1353,57 @@ class SiteTreeTest extends SapphireTest
// Test without title // Test without title
$meta = $page->MetaTags(false); $meta = $page->MetaTags(false);
$this->assertNotContains('<title>', $meta); $this->assertNotContains('<title>', $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 &amp; 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());
} }
/** /**