diff --git a/app/code/Magento/Backend/view/adminhtml/requirejs-config.js b/app/code/Magento/Backend/view/adminhtml/requirejs-config.js index 514e89cafbdd8..592de62b5eeff 100644 --- a/app/code/Magento/Backend/view/adminhtml/requirejs-config.js +++ b/app/code/Magento/Backend/view/adminhtml/requirejs-config.js @@ -5,6 +5,7 @@ var config = { map: { '*': { + editTrigger: 'mage/edit-trigger', translateInline: 'mage/translate-inline', form: 'mage/backend/form', button: 'mage/backend/button', @@ -36,4 +37,4 @@ var config = { paths: { "jquery/ui": "jquery/jquery-ui-1.9.2" } -}; \ No newline at end of file +}; diff --git a/app/code/Magento/PageCache/Controller/Block.php b/app/code/Magento/PageCache/Controller/Block.php index 6684dc6c57a19..f5965b308eb29 100644 --- a/app/code/Magento/PageCache/Controller/Block.php +++ b/app/code/Magento/PageCache/Controller/Block.php @@ -8,6 +8,22 @@ class Block extends \Magento\Framework\App\Action\Action { + /** + * @var \Magento\Framework\Translate\InlineInterface + */ + protected $translateInline; + + /** + * @param \Magento\Framework\App\Action\Context $context + */ + public function __construct( + \Magento\Framework\App\Action\Context $context, + \Magento\Framework\Translate\InlineInterface $translateInline + ) { + parent::__construct($context); + $this->translateInline = $translateInline; + } + /** * Get blocks from layout by handles * diff --git a/app/code/Magento/PageCache/Controller/Block/Esi.php b/app/code/Magento/PageCache/Controller/Block/Esi.php index a7799ea37dd01..c7d9dc9dd8916 100644 --- a/app/code/Magento/PageCache/Controller/Block/Esi.php +++ b/app/code/Magento/PageCache/Controller/Block/Esi.php @@ -27,6 +27,7 @@ public function execute() $response->setHeader('X-Magento-Tags', implode(',', $blockInstance->getIdentities())); } } + $this->translateInline->processResponseBody($html); $response->appendBody($html); $response->setPublicHeaders($ttl); } diff --git a/app/code/Magento/PageCache/Controller/Block/Render.php b/app/code/Magento/PageCache/Controller/Block/Render.php index 43720c29b1f74..24051ae8038a9 100644 --- a/app/code/Magento/PageCache/Controller/Block/Render.php +++ b/app/code/Magento/PageCache/Controller/Block/Render.php @@ -26,6 +26,7 @@ public function execute() } $this->getResponse()->setPrivateHeaders(\Magento\PageCache\Helper\Data::PRIVATE_MAX_AGE_CACHE); + $this->translateInline->processResponseBody($data); $this->getResponse()->appendBody(json_encode($data)); } } diff --git a/app/code/Magento/Translation/Block/Js.php b/app/code/Magento/Translation/Block/Js.php index d430e644e7849..e53e0f6d8d85a 100644 --- a/app/code/Magento/Translation/Block/Js.php +++ b/app/code/Magento/Translation/Block/Js.php @@ -47,8 +47,8 @@ public function __construct( */ public function getTranslatedJson() { - $json = \Zend_Json::encode($this->dataProvider->getTranslateData()); - $this->translateInline->processResponseBody($json, false); - return $json; + $data = $this->dataProvider->getTranslateData(); + $this->translateInline->processResponseBody($data); + return \Zend_Json::encode($data); } } diff --git a/dev/tests/unit/testsuite/Magento/Framework/View/Result/LayoutTest.php b/dev/tests/unit/testsuite/Magento/Framework/View/Result/LayoutTest.php index a3bce8163edbe..16458751dcb2c 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/View/Result/LayoutTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/View/Result/LayoutTest.php @@ -26,6 +26,11 @@ class LayoutTest extends \PHPUnit_Framework_TestCase */ protected $layout; + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Translate\InlineInterface + */ + protected $translateInline; + /** * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\Result\Layout */ @@ -36,6 +41,7 @@ protected function setUp() $this->layout = $this->getMock('Magento\Framework\View\Layout', [], [], '', false); $this->request = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false); $this->eventManager = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false); + $this->translateInline = $this->getMock('Magento\Framework\Translate\InlineInterface'); $context = $this->getMock('Magento\Framework\View\Element\Template\Context', [], [], '', false); $context->expects($this->any())->method('getLayout')->will($this->returnValue($this->layout)); @@ -43,7 +49,10 @@ protected function setUp() $context->expects($this->any())->method('getEventManager')->will($this->returnValue($this->eventManager)); $this->resultLayout = (new \Magento\TestFramework\Helper\ObjectManager($this)) - ->getObject('Magento\Framework\View\Result\Layout', ['context' => $context]); + ->getObject( + 'Magento\Framework\View\Result\Layout', + ['context' => $context, 'translateInline' => $this->translateInline] + ); } /** @@ -90,12 +99,14 @@ public function testAddUpdate() * @param bool $replaceHeader * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $setHttpResponseCodeCount * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $setHeaderCount - * @dataProvider providerRenderResult + * @dataProvider dataProviderRenderResult */ public function testRenderResult( $httpCode, $headerName, $headerValue, $replaceHeader, $setHttpResponseCodeCount, $setHeaderCount ) { - $this->layout->expects($this->once())->method('getOutput')->will($this->returnValue('output')); + $layoutOutput = 'output'; + + $this->layout->expects($this->once())->method('getOutput')->will($this->returnValue($layoutOutput)); $this->request->expects($this->once())->method('getFullActionName') ->will($this->returnValue('Module_Controller_Action')); @@ -105,11 +116,16 @@ public function testRenderResult( ['layout_render_before_Module_Controller_Action'] ); + $this->translateInline->expects($this->once()) + ->method('processResponseBody') + ->with($layoutOutput) + ->willReturnSelf(); + /** @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject $response */ $response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false); $response->expects($setHttpResponseCodeCount)->method('setHttpResponseCode')->with($httpCode); $response->expects($setHeaderCount)->method('setHeader')->with($headerName, $headerValue, $replaceHeader); - $response->expects($this->once())->method('appendBody')->with('output'); + $response->expects($this->once())->method('appendBody')->with($layoutOutput); $this->resultLayout->setHttpResponseCode($httpCode); @@ -123,7 +139,7 @@ public function testRenderResult( /** * @return array */ - public function providerRenderResult() + public function dataProviderRenderResult() { return [ [200, 'content-type', 'text/html', true, $this->once(), $this->once()], diff --git a/dev/tests/unit/testsuite/Magento/PageCache/Controller/Block/EsiTest.php b/dev/tests/unit/testsuite/Magento/PageCache/Controller/Block/EsiTest.php index cee299481f3a5..aab3baded646f 100644 --- a/dev/tests/unit/testsuite/Magento/PageCache/Controller/Block/EsiTest.php +++ b/dev/tests/unit/testsuite/Magento/PageCache/Controller/Block/EsiTest.php @@ -32,31 +32,39 @@ class EsiTest extends \PHPUnit_Framework_TestCase */ protected $layoutMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Translate\InlineInterface + */ + protected $translateInline; + /** * Set up before test */ protected function setUp() { - $this->layoutMock = $this->getMockBuilder( - 'Magento\Framework\View\Layout' - )->disableOriginalConstructor()->getMock(); + $this->layoutMock = $this->getMockBuilder('Magento\Framework\View\Layout') + ->disableOriginalConstructor()->getMock(); $contextMock = $this->getMockBuilder('Magento\Framework\App\Action\Context')->disableOriginalConstructor()->getMock(); - $this->requestMock = $this->getMockBuilder( - 'Magento\Framework\App\Request\Http' - )->disableOriginalConstructor()->getMock(); - $this->responseMock = $this->getMockBuilder( - 'Magento\Framework\App\Response\Http' - )->disableOriginalConstructor()->getMock(); + $this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http') + ->disableOriginalConstructor()->getMock(); + $this->responseMock = $this->getMockBuilder('Magento\Framework\App\Response\Http') + ->disableOriginalConstructor()->getMock(); $this->viewMock = $this->getMockBuilder('Magento\Framework\App\View')->disableOriginalConstructor()->getMock(); $contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock)); $contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->responseMock)); $contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->viewMock)); - $this->action = new \Magento\PageCache\Controller\Block\Esi($contextMock); + $this->translateInline = $this->getMock('Magento\Framework\Translate\InlineInterface'); + + $helperObjectManager = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->action = $helperObjectManager->getObject( + 'Magento\PageCache\Controller\Block\Esi', + ['context' => $contextMock, 'translateInline' => $this->translateInline] + ); } /** @@ -88,15 +96,10 @@ public function testExecute($blockClass, $shouldSetHeaders) $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock)); - $this->layoutMock->expects( - $this->once() - )->method( - 'getBlock' - )->with( - $this->equalTo($block) - )->will( - $this->returnValue($blockInstance1) - ); + $this->layoutMock->expects($this->once()) + ->method('getBlock') + ->with($this->equalTo($block)) + ->will($this->returnValue($blockInstance1)); if ($shouldSetHeaders) { $this->responseMock->expects($this->once()) @@ -107,6 +110,11 @@ public function testExecute($blockClass, $shouldSetHeaders) ->method('setHeader'); } + $this->translateInline->expects($this->once()) + ->method('processResponseBody') + ->with($html) + ->willReturnSelf(); + $this->responseMock->expects($this->once()) ->method('appendBody') ->with($this->equalTo($html)); diff --git a/dev/tests/unit/testsuite/Magento/PageCache/Controller/Block/RenderTest.php b/dev/tests/unit/testsuite/Magento/PageCache/Controller/Block/RenderTest.php index 7fd3cd3d3544c..89727cc8707ac 100644 --- a/dev/tests/unit/testsuite/Magento/PageCache/Controller/Block/RenderTest.php +++ b/dev/tests/unit/testsuite/Magento/PageCache/Controller/Block/RenderTest.php @@ -28,6 +28,11 @@ class RenderTest extends \PHPUnit_Framework_TestCase */ protected $action; + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Translate\InlineInterface + */ + protected $translateInline; + /** * @var \Magento\Framework\View\Layout|\PHPUnit_Framework_MockObject_MockObject */ @@ -57,7 +62,13 @@ protected function setUp() $contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->responseMock)); $contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->viewMock)); - $this->action = new \Magento\PageCache\Controller\Block\Render($contextMock); + $this->translateInline = $this->getMock('Magento\Framework\Translate\InlineInterface'); + + $helperObjectManager = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->action = $helperObjectManager->getObject( + 'Magento\PageCache\Controller\Block\Render', + ['context' => $contextMock, 'translateInline' => $this->translateInline] + ); } public function testExecuteNotAjax() @@ -110,54 +121,33 @@ public function testExecute() $blockInstance2->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block2'])); $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(true)); - $this->requestMock->expects( - $this->at(1) - )->method( - 'getParam' - )->with( - $this->equalTo('blocks'), - $this->equalTo('') - )->will( - $this->returnValue(json_encode($blocks)) - ); - $this->requestMock->expects( - $this->at(2) - )->method( - 'getParam' - )->with( - $this->equalTo('handles'), - $this->equalTo('') - )->will( - $this->returnValue(json_encode($handles)) - ); + $this->requestMock->expects($this->at(1)) + ->method('getParam') + ->with($this->equalTo('blocks'), $this->equalTo('')) + ->will($this->returnValue(json_encode($blocks))); + $this->requestMock->expects($this->at(2)) + ->method('getParam') + ->with($this->equalTo('handles'), $this->equalTo('')) + ->will($this->returnValue(json_encode($handles))); $this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles)); $this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->layoutMock)); - $this->layoutMock->expects( - $this->at(0) - )->method( - 'getBlock' - )->with( - $this->equalTo($blocks[0]) - )->will( - $this->returnValue($blockInstance1) - ); - $this->layoutMock->expects( - $this->at(1) - )->method( - 'getBlock' - )->with( - $this->equalTo($blocks[1]) - )->will( - $this->returnValue($blockInstance2) - ); - - $this->responseMock->expects( - $this->once() - )->method( - 'appendBody' - )->with( - $this->equalTo(json_encode($expectedData)) - ); + $this->layoutMock->expects($this->at(0)) + ->method('getBlock') + ->with($this->equalTo($blocks[0])) + ->will($this->returnValue($blockInstance1)); + $this->layoutMock->expects($this->at(1)) + ->method('getBlock') + ->with($this->equalTo($blocks[1])) + ->will($this->returnValue($blockInstance2)); + + $this->translateInline->expects($this->once()) + ->method('processResponseBody') + ->with($expectedData) + ->willReturnSelf(); + + $this->responseMock->expects($this->once()) + ->method('appendBody') + ->with($this->equalTo(json_encode($expectedData))); $this->action->execute(); } diff --git a/lib/internal/Magento/Framework/View/Result/Layout.php b/lib/internal/Magento/Framework/View/Result/Layout.php index d4af9b22c203b..c378e5bcbb266 100644 --- a/lib/internal/Magento/Framework/View/Result/Layout.php +++ b/lib/internal/Magento/Framework/View/Result/Layout.php @@ -175,7 +175,9 @@ public function renderResult(ResponseInterface $response) */ protected function render(ResponseInterface $response) { - $response->appendBody($this->layout->getOutput()); + $output = $this->layout->getOutput(); + $this->translateInline->processResponseBody($output); + $response->appendBody($output); return $this; } } diff --git a/lib/internal/Magento/Framework/View/Result/Page.php b/lib/internal/Magento/Framework/View/Result/Page.php index c5435e9c4ceb7..a3c6676935470 100644 --- a/lib/internal/Magento/Framework/View/Result/Page.php +++ b/lib/internal/Magento/Framework/View/Result/Page.php @@ -238,9 +238,10 @@ protected function render(ResponseInterface $response) ]); $output = $this->getLayout()->getOutput(); - $this->translateInline->processResponseBody($output); $this->assign('layoutContent', $output); - $response->appendBody($this->renderPage()); + $output = $this->renderPage(); + $this->translateInline->processResponseBody($output); + $response->appendBody($output); } else { parent::render($response); }