Skip to content

Commit dc30d35

Browse files
committed
ACP2E-682: [Magento Cloud] - Add to cart button translation reverts back to English after clicking
- Added the test coverage.
1 parent 49692fa commit dc30d35

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Translation\Test\Unit\Model\Js;
9+
10+
use Magento\Framework\App\Area;
11+
use Magento\Framework\App\AreaList;
12+
use Magento\Framework\TranslateInterface;
13+
use Magento\Framework\View\Asset\File;
14+
use Magento\Framework\View\Asset\File\FallbackContext;
15+
use Magento\Framework\View\Asset\PreProcessor\Chain;
16+
use Magento\Translation\Model\Js\Config;
17+
use Magento\Translation\Model\Js\PreProcessor;
18+
use PHPUnit\Framework\TestCase;
19+
20+
class PreProcessorTest extends TestCase
21+
{
22+
/**
23+
* @var PreProcessor
24+
*/
25+
private PreProcessor $model;
26+
27+
/**
28+
* @var Config|MockObject
29+
*/
30+
private $configMock;
31+
32+
/**
33+
* @var AreaList|MockObject
34+
*/
35+
private $areaListMock;
36+
37+
/**
38+
* @var TranslateInterface|MockObject
39+
*/
40+
private $translateMock;
41+
42+
/**
43+
* @inheritdoc
44+
*/
45+
protected function setUp(): void
46+
{
47+
$this->configMock = $this->createMock(Config::class);
48+
$this->areaListMock = $this->createMock(AreaList::class);
49+
$this->translateMock = $this->getMockForAbstractClass(TranslateInterface::class);
50+
$this->model = new PreProcessor(
51+
$this->configMock,
52+
$this->areaListMock,
53+
$this->translateMock
54+
);
55+
}
56+
57+
/**
58+
* Test 'process' method.
59+
*
60+
*/
61+
public function testProcess()
62+
{
63+
$areaCode = 'frontend';
64+
$themePath = '*/*';
65+
66+
$chain = $this->createMock(Chain::class);
67+
$asset = $this->createMock(File::class);
68+
$context = $this->createMock(FallbackContext::class);
69+
$area = $this->createMock(Area::class);
70+
$this->configMock->expects($this->once())
71+
->method('isEmbeddedStrategy')
72+
->willReturn(1);
73+
$chain->expects($this->once())
74+
->method('getAsset')
75+
->willReturn($asset);
76+
$asset->expects($this->once())
77+
->method('getContext')
78+
->willReturn($context);
79+
$context->expects($this->atLeastOnce())
80+
->method('getAreaCode')
81+
->willReturn($areaCode);
82+
$context->expects($this->atLeastOnce())
83+
->method('getLocale')
84+
->willReturn('nl_NL');
85+
$this->translateMock->expects($this->once())
86+
->method('setLocale')
87+
->with('nl_NL')
88+
->willReturnSelf();
89+
$context->expects($this->atLeastOnce())
90+
->method('getThemePath')
91+
->willReturn($themePath);
92+
$this->translateMock->expects($this->once())
93+
->method('loadData')
94+
->with($areaCode, false)
95+
->willReturnSelf();
96+
$area->expects($this->once())->method('load')->willReturnSelf();
97+
$this->areaListMock->expects($this->once())
98+
->method('getArea')
99+
->with($areaCode)
100+
->willReturn($area);
101+
$chain->expects($this->once())
102+
->method('getContent')
103+
->willReturn('$t("Add to Cart")');
104+
$this->configMock->expects($this->any())
105+
->method('getPatterns')
106+
->willReturn(new \ArrayIterator(
107+
[
108+
'~(?s)\$t\(\s*([\'"])(\?\<translate\>.+?)(?<!\\\)\1\s*(*SKIP)\)(?s)~',
109+
'~\$\.mage\.__\(([\'"])(.+?)\1\)~'
110+
],
111+
));
112+
$this->model->process($chain);
113+
}
114+
}

0 commit comments

Comments
 (0)