mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
Update meta generator tests to use isolated configuration and better assertions
This commit is contained in:
parent
92c0424d73
commit
7554b61325
@ -1227,35 +1227,36 @@ class SiteTreeTest extends SapphireTest
|
|||||||
{
|
{
|
||||||
$generator = Config::inst()->get(SiteTree::class, 'meta_generator');
|
$generator = Config::inst()->get(SiteTree::class, 'meta_generator');
|
||||||
|
|
||||||
|
// Stub to ensure customisations don't affect the test
|
||||||
|
Config::modify()->set(SiteTree::class, 'meta_generator', 'SilverStripe - https://www.silverstripe.org');
|
||||||
|
|
||||||
$page = new SiteTreeTest_PageNode();
|
$page = new SiteTreeTest_PageNode();
|
||||||
|
|
||||||
$meta = $page->MetaTags();
|
$meta = $page->MetaTags();
|
||||||
$this->assertEquals(
|
$this->assertContains('meta name="generator"', $meta, 'Should include generator tag');
|
||||||
1,
|
$this->assertContains(
|
||||||
preg_match('/.*meta name="generator" content="SilverStripe - http:\/\/silverstripe.org".*/', $meta),
|
'content="SilverStripe - https://www.silverstripe.org',
|
||||||
'test default functionality - uses value from Config'
|
$meta,
|
||||||
|
'Should contain default meta generator info'
|
||||||
);
|
);
|
||||||
|
|
||||||
// test proper escaping of quotes in attribute value
|
// test proper escaping of quotes in attribute value
|
||||||
Config::modify()->set(SiteTree::class, 'meta_generator', 'Generator with "quotes" in it');
|
Config::modify()->set(SiteTree::class, 'meta_generator', 'Generator with "quotes" in it');
|
||||||
$meta = $page->MetaTags();
|
$meta = $page->MetaTags();
|
||||||
$this->assertEquals(
|
$this->assertContains(
|
||||||
1,
|
'content="Generator with "quotes" in it',
|
||||||
preg_match('/.*meta name="generator" content="Generator with "quotes" in it".*/', $meta),
|
$meta,
|
||||||
'test proper escaping of values from Config'
|
'test proper escaping of values from Config'
|
||||||
);
|
);
|
||||||
|
|
||||||
// test empty generator - no tag should appear at all
|
// test empty generator - no tag should appear at all
|
||||||
Config::modify()->set(SiteTree::class, 'meta_generator', '');
|
Config::modify()->set(SiteTree::class, 'meta_generator', '');
|
||||||
$meta = $page->MetaTags();
|
$meta = $page->MetaTags();
|
||||||
$this->assertEquals(
|
$this->assertNotContains(
|
||||||
0,
|
'meta name="generator"',
|
||||||
preg_match('/.*meta name=.generator..*/', $meta),
|
$meta,
|
||||||
'test blank value means no tag generated'
|
'test blank value means no tag generated'
|
||||||
);
|
);
|
||||||
|
|
||||||
// reset original value
|
|
||||||
Config::modify()->set(SiteTree::class, 'meta_generator', $generator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user