Skip to content

Commit e0abeaa

Browse files
committed
Add unit test and note in config form
1 parent 28ff5e9 commit e0abeaa

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

app/code/Magento/Theme/Block/Html/Footer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ protected function getCacheLifetime()
133133
{
134134
return parent::getCacheLifetime() ?: 3600;
135135
}
136-
136+
137137
/**
138138
* Replace YYYY by the current year
139139
*/
140140
private function replaceCurrentYear(string $text): string
141141
{
142-
return str_replace('YYYY', (new \DateTime())->format('Y'), $text)
142+
return str_replace('{YYYY}', (new \DateTime())->format('Y'), $text);
143143
}
144144
}

app/code/Magento/Theme/Test/Unit/Block/Html/FooterTest.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
namespace Magento\Theme\Test\Unit\Block\Html;
99

1010
use Magento\Cms\Model\Block;
11+
use Magento\Framework\App\Config;
12+
use Magento\Framework\Escaper;
1113
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
14+
use Magento\Framework\View\Element\Template\Context;
15+
use Magento\Store\Model\ScopeInterface;
1216
use Magento\Store\Model\Store;
1317
use Magento\Theme\Block\Html\Footer;
18+
use Magento\Theme\Block\Html\Header;
1419
use PHPUnit\Framework\TestCase;
1520

1621
class FooterTest extends TestCase
@@ -23,14 +28,41 @@ class FooterTest extends TestCase
2328
protected function setUp(): void
2429
{
2530
$objectManager = new ObjectManager($this);
26-
$this->block = $objectManager->getObject(Footer::class);
31+
32+
$context = $this->getMockBuilder(Context::class)
33+
->setMethods(['getScopeConfig'])
34+
->disableOriginalConstructor()
35+
->getMock();
36+
$this->scopeConfig = $this->getMockBuilder(Config::class)
37+
->setMethods(['getValue'])
38+
->disableOriginalConstructor()
39+
->getMock();
40+
$context->expects($this->once())->method('getScopeConfig')->willReturn($this->scopeConfig);
41+
42+
$this->block = $objectManager->getObject(
43+
Footer::class,
44+
[
45+
'context' => $context,
46+
]
47+
);
2748
}
2849

2950
protected function tearDown(): void
3051
{
3152
$this->block = null;
3253
}
3354

55+
public function testGetCopyright()
56+
{
57+
$this->scopeConfig->expects($this->once())->method('getValue')
58+
->with('design/footer/copyright', ScopeInterface::SCOPE_STORE)
59+
->willReturn('Copyright 2013-{YYYY}');
60+
61+
$this->assertEquals(
62+
'Copyright 2013-' . date('Y'),
63+
$this->block->getCopyright()
64+
);
65+
}
3466
public function testGetIdentities()
3567
{
3668
$this->assertEquals(

app/code/Magento/Theme/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ Header,Header
172172
Footer,Footer
173173
"This will be displayed just before the body closing tag.","This will be displayed just before the body closing tag."
174174
"Miscellaneous HTML","Miscellaneous HTML"
175+
"Use {YYYY} to insert the current year (updates on cache refresh).","Use {YYYY} to insert the current year (updates on cache refresh)."
175176
Copyright,Copyright
176177
"Default Robots","Default Robots"
177178
"Edit custom instruction of robots.txt File","Edit custom instruction of robots.txt File"

app/code/Magento/Theme/view/adminhtml/ui_component/design_config_form.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
<validation>
243243
<rule name="validate-no-html-tags" xsi:type="boolean">true</rule>
244244
</validation>
245+
<notice translate="true">Use {YYYY} to insert the current year (updates on cache refresh).</notice>
245246
<dataType>text</dataType>
246247
<label translate="true">Copyright</label>
247248
<dataScope>footer_copyright</dataScope>

0 commit comments

Comments
 (0)