Skip to content

Commit 493a1de

Browse files
Merge remote-tracking branch '36754/patch-19' into comm_voted
2 parents 47aafa3 + 6b0e93e commit 493a1de

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function getCopyright()
9393
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
9494
);
9595
}
96-
return __($this->_copyright);
96+
return $this->replaceCurrentYear((string)__($this->_copyright));
9797
}
9898

9999
/**
@@ -133,4 +133,14 @@ protected function getCacheLifetime()
133133
{
134134
return parent::getCacheLifetime() ?: 3600;
135135
}
136+
137+
/**
138+
* Replace YYYY with the current year
139+
*
140+
* @param string $text
141+
*/
142+
private function replaceCurrentYear(string $text): string
143+
{
144+
return str_replace('{YYYY}', (new \DateTime())->format('Y'), $text);
145+
}
136146
}

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

Lines changed: 38 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
@@ -20,17 +25,49 @@ class FooterTest extends TestCase
2025
*/
2126
protected $block;
2227

28+
/**
29+
* @var Config
30+
*/
31+
private $scopeConfig;
32+
2333
protected function setUp(): void
2434
{
2535
$objectManager = new ObjectManager($this);
26-
$this->block = $objectManager->getObject(Footer::class);
36+
37+
$context = $this->getMockBuilder(Context::class)
38+
->setMethods(['getScopeConfig'])
39+
->disableOriginalConstructor()
40+
->getMock();
41+
$this->scopeConfig = $this->getMockBuilder(Config::class)
42+
->setMethods(['getValue'])
43+
->disableOriginalConstructor()
44+
->getMock();
45+
$context->expects($this->once())->method('getScopeConfig')->willReturn($this->scopeConfig);
46+
47+
$this->block = $objectManager->getObject(
48+
Footer::class,
49+
[
50+
'context' => $context,
51+
]
52+
);
2753
}
2854

2955
protected function tearDown(): void
3056
{
3157
$this->block = null;
3258
}
3359

60+
public function testGetCopyright()
61+
{
62+
$this->scopeConfig->expects($this->once())->method('getValue')
63+
->with('design/footer/copyright', ScopeInterface::SCOPE_STORE)
64+
->willReturn('Copyright 2013-{YYYY}');
65+
66+
$this->assertEquals(
67+
'Copyright 2013-' . date('Y'),
68+
$this->block->getCopyright()
69+
);
70+
}
3471
public function testGetIdentities()
3572
{
3673
$this->assertEquals(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ Header,Header
173173
Footer,Footer
174174
"This will be displayed just before the body closing tag.","This will be displayed just before the body closing tag."
175175
"Miscellaneous HTML","Miscellaneous HTML"
176+
"Use {YYYY} to insert the current year (updates on cache refresh).","Use {YYYY} to insert the current year (updates on cache refresh)."
176177
Copyright,Copyright
177178
"Default Robots","Default Robots"
178179
"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)