Skip to content

Commit 8b1ed6f

Browse files
author
Yurii Torbyk
committed
MAGETWO-28268: [GITHUB] Inline translate malfunctioning #658
1 parent 3bca5f4 commit 8b1ed6f

File tree

10 files changed

+114
-78
lines changed

10 files changed

+114
-78
lines changed

app/code/Magento/Backend/view/adminhtml/requirejs-config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
var config = {
66
map: {
77
'*': {
8+
editTrigger: 'mage/edit-trigger',
89
translateInline: 'mage/translate-inline',
910
form: 'mage/backend/form',
1011
button: 'mage/backend/button',
@@ -36,4 +37,4 @@ var config = {
3637
paths: {
3738
"jquery/ui": "jquery/jquery-ui-1.9.2"
3839
}
39-
};
40+
};

app/code/Magento/PageCache/Controller/Block.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88

99
class Block extends \Magento\Framework\App\Action\Action
1010
{
11+
/**
12+
* @var \Magento\Framework\Translate\InlineInterface
13+
*/
14+
protected $translateInline;
15+
16+
/**
17+
* @param \Magento\Framework\App\Action\Context $context
18+
*/
19+
public function __construct(
20+
\Magento\Framework\App\Action\Context $context,
21+
\Magento\Framework\Translate\InlineInterface $translateInline
22+
) {
23+
parent::__construct($context);
24+
$this->translateInline = $translateInline;
25+
}
26+
1127
/**
1228
* Get blocks from layout by handles
1329
*

app/code/Magento/PageCache/Controller/Block/Esi.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function execute()
2727
$response->setHeader('X-Magento-Tags', implode(',', $blockInstance->getIdentities()));
2828
}
2929
}
30+
$this->translateInline->processResponseBody($html);
3031
$response->appendBody($html);
3132
$response->setPublicHeaders($ttl);
3233
}

app/code/Magento/PageCache/Controller/Block/Render.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function execute()
2626
}
2727

2828
$this->getResponse()->setPrivateHeaders(\Magento\PageCache\Helper\Data::PRIVATE_MAX_AGE_CACHE);
29+
$this->translateInline->processResponseBody($data);
2930
$this->getResponse()->appendBody(json_encode($data));
3031
}
3132
}

app/code/Magento/Translation/Block/Js.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public function __construct(
4747
*/
4848
public function getTranslatedJson()
4949
{
50-
$json = \Zend_Json::encode($this->dataProvider->getTranslateData());
51-
$this->translateInline->processResponseBody($json, false);
52-
return $json;
50+
$data = $this->dataProvider->getTranslateData();
51+
$this->translateInline->processResponseBody($data);
52+
return \Zend_Json::encode($data);
5353
}
5454
}

dev/tests/unit/testsuite/Magento/Framework/View/Result/LayoutTest.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class LayoutTest extends \PHPUnit_Framework_TestCase
2626
*/
2727
protected $layout;
2828

29+
/**
30+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Translate\InlineInterface
31+
*/
32+
protected $translateInline;
33+
2934
/**
3035
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\Result\Layout
3136
*/
@@ -36,14 +41,18 @@ protected function setUp()
3641
$this->layout = $this->getMock('Magento\Framework\View\Layout', [], [], '', false);
3742
$this->request = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false);
3843
$this->eventManager = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false);
44+
$this->translateInline = $this->getMock('Magento\Framework\Translate\InlineInterface');
3945

4046
$context = $this->getMock('Magento\Framework\View\Element\Template\Context', [], [], '', false);
4147
$context->expects($this->any())->method('getLayout')->will($this->returnValue($this->layout));
4248
$context->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
4349
$context->expects($this->any())->method('getEventManager')->will($this->returnValue($this->eventManager));
4450

4551
$this->resultLayout = (new \Magento\TestFramework\Helper\ObjectManager($this))
46-
->getObject('Magento\Framework\View\Result\Layout', ['context' => $context]);
52+
->getObject(
53+
'Magento\Framework\View\Result\Layout',
54+
['context' => $context, 'translateInline' => $this->translateInline]
55+
);
4756
}
4857

4958
/**
@@ -90,12 +99,14 @@ public function testAddUpdate()
9099
* @param bool $replaceHeader
91100
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $setHttpResponseCodeCount
92101
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $setHeaderCount
93-
* @dataProvider providerRenderResult
102+
* @dataProvider dataProviderRenderResult
94103
*/
95104
public function testRenderResult(
96105
$httpCode, $headerName, $headerValue, $replaceHeader, $setHttpResponseCodeCount, $setHeaderCount
97106
) {
98-
$this->layout->expects($this->once())->method('getOutput')->will($this->returnValue('output'));
107+
$layoutOutput = 'output';
108+
109+
$this->layout->expects($this->once())->method('getOutput')->will($this->returnValue($layoutOutput));
99110

100111
$this->request->expects($this->once())->method('getFullActionName')
101112
->will($this->returnValue('Module_Controller_Action'));
@@ -105,11 +116,16 @@ public function testRenderResult(
105116
['layout_render_before_Module_Controller_Action']
106117
);
107118

119+
$this->translateInline->expects($this->once())
120+
->method('processResponseBody')
121+
->with($layoutOutput)
122+
->willReturnSelf();
123+
108124
/** @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject $response */
109125
$response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false);
110126
$response->expects($setHttpResponseCodeCount)->method('setHttpResponseCode')->with($httpCode);
111127
$response->expects($setHeaderCount)->method('setHeader')->with($headerName, $headerValue, $replaceHeader);
112-
$response->expects($this->once())->method('appendBody')->with('output');
128+
$response->expects($this->once())->method('appendBody')->with($layoutOutput);
113129

114130
$this->resultLayout->setHttpResponseCode($httpCode);
115131

@@ -123,7 +139,7 @@ public function testRenderResult(
123139
/**
124140
* @return array
125141
*/
126-
public function providerRenderResult()
142+
public function dataProviderRenderResult()
127143
{
128144
return [
129145
[200, 'content-type', 'text/html', true, $this->once(), $this->once()],

dev/tests/unit/testsuite/Magento/PageCache/Controller/Block/EsiTest.php

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,39 @@ class EsiTest extends \PHPUnit_Framework_TestCase
3232
*/
3333
protected $layoutMock;
3434

35+
/**
36+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Translate\InlineInterface
37+
*/
38+
protected $translateInline;
39+
3540
/**
3641
* Set up before test
3742
*/
3843
protected function setUp()
3944
{
40-
$this->layoutMock = $this->getMockBuilder(
41-
'Magento\Framework\View\Layout'
42-
)->disableOriginalConstructor()->getMock();
45+
$this->layoutMock = $this->getMockBuilder('Magento\Framework\View\Layout')
46+
->disableOriginalConstructor()->getMock();
4347

4448
$contextMock =
4549
$this->getMockBuilder('Magento\Framework\App\Action\Context')->disableOriginalConstructor()->getMock();
4650

47-
$this->requestMock = $this->getMockBuilder(
48-
'Magento\Framework\App\Request\Http'
49-
)->disableOriginalConstructor()->getMock();
50-
$this->responseMock = $this->getMockBuilder(
51-
'Magento\Framework\App\Response\Http'
52-
)->disableOriginalConstructor()->getMock();
51+
$this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http')
52+
->disableOriginalConstructor()->getMock();
53+
$this->responseMock = $this->getMockBuilder('Magento\Framework\App\Response\Http')
54+
->disableOriginalConstructor()->getMock();
5355
$this->viewMock = $this->getMockBuilder('Magento\Framework\App\View')->disableOriginalConstructor()->getMock();
5456

5557
$contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock));
5658
$contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->responseMock));
5759
$contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->viewMock));
5860

59-
$this->action = new \Magento\PageCache\Controller\Block\Esi($contextMock);
61+
$this->translateInline = $this->getMock('Magento\Framework\Translate\InlineInterface');
62+
63+
$helperObjectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
64+
$this->action = $helperObjectManager->getObject(
65+
'Magento\PageCache\Controller\Block\Esi',
66+
['context' => $contextMock, 'translateInline' => $this->translateInline]
67+
);
6068
}
6169

6270
/**
@@ -88,15 +96,10 @@ public function testExecute($blockClass, $shouldSetHeaders)
8896

8997
$this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock));
9098

91-
$this->layoutMock->expects(
92-
$this->once()
93-
)->method(
94-
'getBlock'
95-
)->with(
96-
$this->equalTo($block)
97-
)->will(
98-
$this->returnValue($blockInstance1)
99-
);
99+
$this->layoutMock->expects($this->once())
100+
->method('getBlock')
101+
->with($this->equalTo($block))
102+
->will($this->returnValue($blockInstance1));
100103

101104
if ($shouldSetHeaders) {
102105
$this->responseMock->expects($this->once())
@@ -107,6 +110,11 @@ public function testExecute($blockClass, $shouldSetHeaders)
107110
->method('setHeader');
108111
}
109112

113+
$this->translateInline->expects($this->once())
114+
->method('processResponseBody')
115+
->with($html)
116+
->willReturnSelf();
117+
110118
$this->responseMock->expects($this->once())
111119
->method('appendBody')
112120
->with($this->equalTo($html));

dev/tests/unit/testsuite/Magento/PageCache/Controller/Block/RenderTest.php

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class RenderTest extends \PHPUnit_Framework_TestCase
2828
*/
2929
protected $action;
3030

31+
/**
32+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Translate\InlineInterface
33+
*/
34+
protected $translateInline;
35+
3136
/**
3237
* @var \Magento\Framework\View\Layout|\PHPUnit_Framework_MockObject_MockObject
3338
*/
@@ -57,7 +62,13 @@ protected function setUp()
5762
$contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->responseMock));
5863
$contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->viewMock));
5964

60-
$this->action = new \Magento\PageCache\Controller\Block\Render($contextMock);
65+
$this->translateInline = $this->getMock('Magento\Framework\Translate\InlineInterface');
66+
67+
$helperObjectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
68+
$this->action = $helperObjectManager->getObject(
69+
'Magento\PageCache\Controller\Block\Render',
70+
['context' => $contextMock, 'translateInline' => $this->translateInline]
71+
);
6172
}
6273

6374
public function testExecuteNotAjax()
@@ -110,54 +121,33 @@ public function testExecute()
110121
$blockInstance2->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block2']));
111122

112123
$this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(true));
113-
$this->requestMock->expects(
114-
$this->at(1)
115-
)->method(
116-
'getParam'
117-
)->with(
118-
$this->equalTo('blocks'),
119-
$this->equalTo('')
120-
)->will(
121-
$this->returnValue(json_encode($blocks))
122-
);
123-
$this->requestMock->expects(
124-
$this->at(2)
125-
)->method(
126-
'getParam'
127-
)->with(
128-
$this->equalTo('handles'),
129-
$this->equalTo('')
130-
)->will(
131-
$this->returnValue(json_encode($handles))
132-
);
124+
$this->requestMock->expects($this->at(1))
125+
->method('getParam')
126+
->with($this->equalTo('blocks'), $this->equalTo(''))
127+
->will($this->returnValue(json_encode($blocks)));
128+
$this->requestMock->expects($this->at(2))
129+
->method('getParam')
130+
->with($this->equalTo('handles'), $this->equalTo(''))
131+
->will($this->returnValue(json_encode($handles)));
133132
$this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles));
134133
$this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->layoutMock));
135-
$this->layoutMock->expects(
136-
$this->at(0)
137-
)->method(
138-
'getBlock'
139-
)->with(
140-
$this->equalTo($blocks[0])
141-
)->will(
142-
$this->returnValue($blockInstance1)
143-
);
144-
$this->layoutMock->expects(
145-
$this->at(1)
146-
)->method(
147-
'getBlock'
148-
)->with(
149-
$this->equalTo($blocks[1])
150-
)->will(
151-
$this->returnValue($blockInstance2)
152-
);
153-
154-
$this->responseMock->expects(
155-
$this->once()
156-
)->method(
157-
'appendBody'
158-
)->with(
159-
$this->equalTo(json_encode($expectedData))
160-
);
134+
$this->layoutMock->expects($this->at(0))
135+
->method('getBlock')
136+
->with($this->equalTo($blocks[0]))
137+
->will($this->returnValue($blockInstance1));
138+
$this->layoutMock->expects($this->at(1))
139+
->method('getBlock')
140+
->with($this->equalTo($blocks[1]))
141+
->will($this->returnValue($blockInstance2));
142+
143+
$this->translateInline->expects($this->once())
144+
->method('processResponseBody')
145+
->with($expectedData)
146+
->willReturnSelf();
147+
148+
$this->responseMock->expects($this->once())
149+
->method('appendBody')
150+
->with($this->equalTo(json_encode($expectedData)));
161151

162152
$this->action->execute();
163153
}

lib/internal/Magento/Framework/View/Result/Layout.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ public function renderResult(ResponseInterface $response)
175175
*/
176176
protected function render(ResponseInterface $response)
177177
{
178-
$response->appendBody($this->layout->getOutput());
178+
$output = $this->layout->getOutput();
179+
$this->translateInline->processResponseBody($output);
180+
$response->appendBody($output);
179181
return $this;
180182
}
181183
}

lib/internal/Magento/Framework/View/Result/Page.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,10 @@ protected function render(ResponseInterface $response)
238238
]);
239239

240240
$output = $this->getLayout()->getOutput();
241-
$this->translateInline->processResponseBody($output);
242241
$this->assign('layoutContent', $output);
243-
$response->appendBody($this->renderPage());
242+
$output = $this->renderPage();
243+
$this->translateInline->processResponseBody($output);
244+
$response->appendBody($output);
244245
} else {
245246
parent::render($response);
246247
}

0 commit comments

Comments
 (0)