From 68cf74047df4c63e805d70ca3395a0f907db7251 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Tue, 23 Dec 2014 15:43:58 +0200 Subject: [PATCH 01/16] MAGETWO-17690: 'Orders & Returns' widget type contain unnecessary tab --- .../Widget/Instance/Edit/Tab/Properties.php | 17 +++- .../Instance/Edit/Tab/PropertiesTest.php | 88 +++++++++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/PropertiesTest.php diff --git a/app/code/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php b/app/code/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php index 614eeaa7eb2be..6ccfbddc22120 100644 --- a/app/code/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php +++ b/app/code/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php @@ -13,6 +13,11 @@ class Properties extends \Magento\Widget\Block\Adminhtml\Widget\Options implements \Magento\Backend\Block\Widget\Tab\TabInterface { + /** + * Widget config parameter + */ + const WIDGET_PARAMETER = 'template'; + /** * Prepare label for tab * @@ -46,11 +51,19 @@ public function canShowTab() /** * Returns status flag about this tab hidden or not * - * @return true + * @return bool */ public function isHidden() { - return false; + $parameters = $this->getWidgetInstance()->getWidgetConfigAsArray()['parameters']; + + foreach ($parameters as $key => $parameter) { + if ($parameter['visible'] == 1 && $key != self::WIDGET_PARAMETER) { + return false; + } + } + + return true; } /** diff --git a/dev/tests/unit/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/PropertiesTest.php b/dev/tests/unit/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/PropertiesTest.php new file mode 100644 index 0000000000000..a88967f2d0a3e --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/PropertiesTest.php @@ -0,0 +1,88 @@ + [ + 'title' => [ + 'type' => 'text', + 'visible' => '0', + ], + 'template' => [ + 'type' => 'select', + 'visible' => '1', + ], + ] + ]; + + /** @var \Magento\Widget\Model\Widget\Instance|\PHPUnit_Framework_MockObject_MockObject $widget */ + $widget = $this->getMock('Magento\Widget\Model\Widget\Instance', [], [], '', false); + $widget->expects($this->atLeastOnce()) + ->method('getWidgetConfigAsArray') + ->will($this->returnValue($widgetConfig)); + + /** @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject $registry */ + $registry = $this->getMock('Magento\Framework\Registry', [], [], '', false); + $registry->expects($this->atLeastOnce()) + ->method('registry') + ->with('current_widget_instance') + ->will($this->returnValue($widget)); + + $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); + /** @var \Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Properties $propertiesBlock */ + $propertiesBlock = $objectManager->getObject( + 'Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Properties', + [ + 'registry' => $registry + ] + ); + + $this->assertTrue($propertiesBlock->isHidden()); + } + + public function testIsHiddenFalse() + { + $widgetConfig = [ + 'parameters' => [ + 'types' => [ + 'type' => 'multiselect', + 'visible' => '1', + ], + 'template' => [ + 'type' => 'select', + 'visible' => '1', + ], + ] + ]; + + /** @var \Magento\Widget\Model\Widget\Instance|\PHPUnit_Framework_MockObject_MockObject $widget */ + $widget = $this->getMock('Magento\Widget\Model\Widget\Instance', [], [], '', false); + $widget->expects($this->atLeastOnce()) + ->method('getWidgetConfigAsArray') + ->will($this->returnValue($widgetConfig)); + + /** @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject $registry */ + $registry = $this->getMock('Magento\Framework\Registry', [], [], '', false); + $registry->expects($this->atLeastOnce()) + ->method('registry') + ->with('current_widget_instance') + ->will($this->returnValue($widget)); + + $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); + /** @var \Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Properties $propertiesBlock */ + $propertiesBlock = $objectManager->getObject( + 'Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Properties', + [ + 'registry' => $registry + ] + ); + + $this->assertFalse($propertiesBlock->isHidden()); + } +} From 8b1ed6f481ee0b19c97396ae56a39836b6d3b3e4 Mon Sep 17 00:00:00 2001 From: Yurii Torbyk Date: Wed, 24 Dec 2014 18:23:23 +0200 Subject: [PATCH 02/16] MAGETWO-28268: [GITHUB] Inline translate malfunctioning #658 --- .../view/adminhtml/requirejs-config.js | 3 +- .../Magento/PageCache/Controller/Block.php | 16 ++++ .../PageCache/Controller/Block/Esi.php | 1 + .../PageCache/Controller/Block/Render.php | 1 + app/code/Magento/Translation/Block/Js.php | 6 +- .../Framework/View/Result/LayoutTest.php | 26 ++++-- .../PageCache/Controller/Block/EsiTest.php | 46 +++++----- .../PageCache/Controller/Block/RenderTest.php | 84 ++++++++----------- .../Magento/Framework/View/Result/Layout.php | 4 +- .../Magento/Framework/View/Result/Page.php | 5 +- 10 files changed, 114 insertions(+), 78 deletions(-) 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); } From 1ba23ce19c19d095da70c8d36fe8fed2def645c4 Mon Sep 17 00:00:00 2001 From: Yuri Kovsher Date: Thu, 25 Dec 2014 12:40:47 +0200 Subject: [PATCH 03/16] MAGETWO-17189: Recently Compared / Viewed widgets aren't displayed in side columns --- .../Magento/Reports/Model/Event/Observer.php | 10 ++- .../Reports/Model/Event/ObserverTest.php | 74 +++++++++++++++++++ 2 files changed, 81 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Reports/Model/Event/Observer.php b/app/code/Magento/Reports/Model/Event/Observer.php index 29a7c544c17b3..0b319265954c6 100644 --- a/app/code/Magento/Reports/Model/Event/Observer.php +++ b/app/code/Magento/Reports/Model/Event/Observer.php @@ -215,9 +215,13 @@ public function catalogProductCompareClear(\Magento\Framework\Event\Observer $ob public function catalogProductCompareAddProduct(\Magento\Framework\Event\Observer $observer) { $productId = $observer->getEvent()->getProduct()->getId(); - - $this->_productCompFactory->create()->setProductId($productId)->save()->calculate(); - + $viewData = ['product_id' => $productId]; + if ($this->_customerSession->isLoggedIn()) { + $viewData['customer_id'] = $this->_customerSession->getCustomerId(); + } else { + $viewData['visitor_id'] = $this->_customerVisitor->getId(); + } + $this->_productCompFactory->create()->setData($viewData)->save()->calculate(); return $this->_event(\Magento\Reports\Model\Event::EVENT_PRODUCT_COMPARE, $productId); } diff --git a/dev/tests/unit/testsuite/Magento/Reports/Model/Event/ObserverTest.php b/dev/tests/unit/testsuite/Magento/Reports/Model/Event/ObserverTest.php index 941fb7843d459..44f854a19c1ab 100644 --- a/dev/tests/unit/testsuite/Magento/Reports/Model/Event/ObserverTest.php +++ b/dev/tests/unit/testsuite/Magento/Reports/Model/Event/ObserverTest.php @@ -36,6 +36,16 @@ class ObserverTest extends \PHPUnit_Framework_TestCase */ protected $storeMock; + /** + * @var \Magento\Reports\Model\Product\Index\ComparedFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $productCompFactoryMock; + + /** + * @var \Magento\Reports\Model\Product\Index\Compared|\PHPUnit_Framework_MockObject_MockObject + */ + protected $productCompModelMock; + public function setUp() { $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); @@ -73,6 +83,12 @@ public function setUp() $storeManager->expects($this->any()) ->method('getStore') ->willReturn($this->storeMock); + $this->productCompFactoryMock = $this->getMockBuilder('Magento\Reports\Model\Product\Index\ComparedFactory') + ->disableOriginalConstructor() + ->getMock(); + $this->productCompModelMock = $this->getMockBuilder('Magento\Reports\Model\Product\Index\Compared') + ->disableOriginalConstructor() + ->getMock(); $this->observer = $objectManager->getObject( 'Magento\Reports\Model\Event\Observer', @@ -80,6 +96,7 @@ public function setUp() 'customerSession' => $this->customerSessionMock, 'customerVisitor' => $this->customerVisitorMock, 'productIndxFactory' => $productIndexFactoryMock, + 'productCompFactory' => $this->productCompFactoryMock, 'storeManager' => $storeManager, 'event' => $reportEventFactory ] @@ -158,6 +175,63 @@ public function testCatalogProductViewVisitor() $this->observer->catalogProductView($eventObserver); } + /** + * @param bool $isLoggedIn + * @param str $userKey + * @param int $userId + * @dataProvider catalogProductCompareAddProductDataProvider + */ + public function testCatalogProductCompareAddProduct($isLoggedIn, $userKey, $userId) + { + $productId = 111; + $customerId = 222; + $visitorId = 333; + $viewData = [ + 'product_id' => $productId, + $userKey => $userId + ]; + $observerMock = $this->getObserverMock($productId); + $this->customerSessionMock->expects($this->any()) + ->method('isLoggedIn') + ->willReturn($isLoggedIn); + $this->customerSessionMock->expects($this->any()) + ->method('getCustomerId') + ->willReturn($customerId); + $this->customerVisitorMock->expects($this->any()) + ->method('getId') + ->willReturn($visitorId); + $this->productCompFactoryMock->expects($this->any()) + ->method('create') + ->willReturn($this->productCompModelMock); + $this->productCompModelMock->expects($this->any()) + ->method('setData') + ->with($viewData) + ->willReturnSelf(); + $this->productCompModelMock->expects($this->any()) + ->method('save') + ->willReturnSelf(); + $this->productCompModelMock->expects($this->any()) + ->method('calculate') + ->willReturnSelf(); + $this->assertEquals($this->observer, $this->observer->catalogProductCompareAddProduct($observerMock)); + } + + public function catalogProductCompareAddProductDataProvider() + { + return [ + 'logged in' => [ + 'isLoggedIn' => true, + 'userKey' => 'customer_id', + 'userId' => 222 + ], + 'not logged in' => [ + 'isLoggedIn' => false, + 'userKey' => 'visitor_id', + 'userId' => 333 + ] + ]; + } + /** * @param array $expectedViewedData * @return void From 979ed620151c552a0a6460d7669108036320df5f Mon Sep 17 00:00:00 2001 From: Yuri Kovsher Date: Thu, 25 Dec 2014 13:00:21 +0200 Subject: [PATCH 04/16] MAGETWO-17189: Recently Compared / Viewed widgets aren't displayed in side columns --- .../testsuite/Magento/Reports/Model/Event/ObserverTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dev/tests/unit/testsuite/Magento/Reports/Model/Event/ObserverTest.php b/dev/tests/unit/testsuite/Magento/Reports/Model/Event/ObserverTest.php index 44f854a19c1ab..4e0bb6c8755a5 100644 --- a/dev/tests/unit/testsuite/Magento/Reports/Model/Event/ObserverTest.php +++ b/dev/tests/unit/testsuite/Magento/Reports/Model/Event/ObserverTest.php @@ -85,6 +85,11 @@ public function setUp() ->willReturn($this->storeMock); $this->productCompFactoryMock = $this->getMockBuilder('Magento\Reports\Model\Product\Index\ComparedFactory') ->disableOriginalConstructor() + ->setMethods( + [ + 'create' + ] + ) ->getMock(); $this->productCompModelMock = $this->getMockBuilder('Magento\Reports\Model\Product\Index\Compared') ->disableOriginalConstructor() From 56dc1865d7c298c327f241760c6444ca56298b53 Mon Sep 17 00:00:00 2001 From: Yuri Kovsher Date: Mon, 5 Jan 2015 12:51:28 +0200 Subject: [PATCH 05/16] MAGETWO-17189: Recently Compared / Viewed widgets aren't displayed in side columns --- .../testsuite/Magento/Reports/Model/Event/ObserverTest.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Reports/Model/Event/ObserverTest.php b/dev/tests/unit/testsuite/Magento/Reports/Model/Event/ObserverTest.php index 4e0bb6c8755a5..ede960203c341 100644 --- a/dev/tests/unit/testsuite/Magento/Reports/Model/Event/ObserverTest.php +++ b/dev/tests/unit/testsuite/Magento/Reports/Model/Event/ObserverTest.php @@ -85,11 +85,7 @@ public function setUp() ->willReturn($this->storeMock); $this->productCompFactoryMock = $this->getMockBuilder('Magento\Reports\Model\Product\Index\ComparedFactory') ->disableOriginalConstructor() - ->setMethods( - [ - 'create' - ] - ) + ->setMethods(['create']) ->getMock(); $this->productCompModelMock = $this->getMockBuilder('Magento\Reports\Model\Product\Index\Compared') ->disableOriginalConstructor() From 4a8ba7c838b953dc52179179922b63c84fc0dac3 Mon Sep 17 00:00:00 2001 From: Yurii Torbyk Date: Tue, 6 Jan 2015 12:38:58 +0200 Subject: [PATCH 06/16] MAGETWO-28268: [GITHUB] Inline translate malfunctioning #658 --- .../testsuite/Magento/Framework/View/Result/LayoutTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 16458751dcb2c..de4aec1e59ea0 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/View/Result/LayoutTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/View/Result/LayoutTest.php @@ -99,7 +99,7 @@ public function testAddUpdate() * @param bool $replaceHeader * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $setHttpResponseCodeCount * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $setHeaderCount - * @dataProvider dataProviderRenderResult + * @dataProvider renderResultDataProvider */ public function testRenderResult( $httpCode, $headerName, $headerValue, $replaceHeader, $setHttpResponseCodeCount, $setHeaderCount @@ -139,7 +139,7 @@ public function testRenderResult( /** * @return array */ - public function dataProviderRenderResult() + public function renderResultDataProvider() { return [ [200, 'content-type', 'text/html', true, $this->once(), $this->once()], From 186ef13b1b91fb73a16fa3d0f2898af2709523ec Mon Sep 17 00:00:00 2001 From: Yuri Kovsher Date: Tue, 6 Jan 2015 17:58:11 +0200 Subject: [PATCH 07/16] MAGETWO-21201: CLONE - Apply SUPEE-1805: Issue with disablign allow_url_fopen using the CMS WYSIWYG editor (patch) --- .../Adminhtml/Wysiwyg/Directive.php | 8 +- .../Magento/Cms/Model/Template/Filter.php | 6 + app/code/Magento/Cms/Model/Wysiwyg/Config.php | 27 +- app/code/Magento/Store/Model/Store.php | 20 ++ .../Adminhtml/Wysiwyg/DirectiveTest.php | 248 ++++++++++++++++++ .../Magento/Cms/Model/Template/FilterTest.php | 65 +++++ .../Magento/Cms/Model/Wysiwyg/ConfigTest.php | 77 +++++- .../Magento/Store/Model/StoreTest.php | 46 ++++ 8 files changed, 484 insertions(+), 13 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/DirectiveTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Cms/Model/Template/FilterTest.php diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php b/app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php index 6b5ac115db2b2..0a3c43336a54f 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php @@ -6,6 +6,7 @@ namespace Magento\Cms\Controller\Adminhtml\Wysiwyg; use Magento\Backend\App\Action; +use SebastianBergmann\Exporter\Exception; class Directive extends \Magento\Backend\App\Action { @@ -37,15 +38,16 @@ public function execute() { $directive = $this->getRequest()->getParam('___directive'); $directive = $this->urlDecoder->decode($directive); - $url = $this->_objectManager->create('Magento\Email\Model\Template\Filter')->filter($directive); + $imagePath = $this->_objectManager->create('Magento\Cms\Model\Template\Filter')->filter($directive); /** @var \Magento\Framework\Image\Adapter\AdapterInterface $image */ $image = $this->_objectManager->get('Magento\Framework\Image\AdapterFactory')->create(); $response = $this->getResponse(); try { - $image->open($url); + $image->open($imagePath); $response->setHeader('Content-Type', $image->getMimeType())->setBody($image->getImage()); } catch (\Exception $e) { - $image->open($this->_objectManager->get('Magento\Cms\Model\Wysiwyg\Config')->getSkinImagePlaceholderUrl()); + $imagePath = $this->_objectManager->get('Magento\Cms\Model\Wysiwyg\Config')->getSkinImagePlaceholderPath(); + $image->open($imagePath); $response->setHeader('Content-Type', $image->getMimeType())->setBody($image->getImage()); $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); } diff --git a/app/code/Magento/Cms/Model/Template/Filter.php b/app/code/Magento/Cms/Model/Template/Filter.php index 82b4e3ec54281..52b84500a78d0 100644 --- a/app/code/Magento/Cms/Model/Template/Filter.php +++ b/app/code/Magento/Cms/Model/Template/Filter.php @@ -27,4 +27,10 @@ public function setUseSessionInUrl($flag) $this->_useSessionInUrl = (bool)$flag; return $this; } + + public function mediaDirective($construction) + { + $params = $this->_getIncludeParameters($construction[2]); + return $this->_storeManager->getStore()->getBaseMediaDir() . '/' . $params['url']; + } } diff --git a/app/code/Magento/Cms/Model/Wysiwyg/Config.php b/app/code/Magento/Cms/Model/Wysiwyg/Config.php index e361aedf2b9a9..0b394f3743e5e 100644 --- a/app/code/Magento/Cms/Model/Wysiwyg/Config.php +++ b/app/code/Magento/Cms/Model/Wysiwyg/Config.php @@ -19,6 +19,11 @@ class Config extends \Magento\Framework\Object */ const WYSIWYG_STATUS_CONFIG_PATH = 'cms/wysiwyg/enabled'; + /** + * + */ + const WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID = 'Magento_Cms::images/wysiwyg_skin_image.png'; + /** * Wysiwyg status hidden */ @@ -78,6 +83,11 @@ class Config extends \Magento\Framework\Object */ protected $_backendUrl; + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + protected $_storeManager; + /** * @param \Magento\Backend\Model\UrlInterface $backendUrl * @param \Magento\Framework\Event\ManagerInterface $eventManager @@ -86,6 +96,7 @@ class Config extends \Magento\Framework\Object * @param \Magento\Core\Model\Variable\Config $variableConfig * @param \Magento\Widget\Model\Widget\Config $widgetConfig * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param array $windowSize * @param array $data */ @@ -97,6 +108,7 @@ public function __construct( \Magento\Core\Model\Variable\Config $variableConfig, \Magento\Widget\Model\Widget\Config $widgetConfig, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, + \Magento\Store\Model\StoreManagerInterface $storeManager, array $windowSize = [], array $data = [] ) { @@ -108,6 +120,7 @@ public function __construct( $this->_variableConfig = $variableConfig; $this->_widgetConfig = $widgetConfig; $this->_windowSize = $windowSize; + $this->_storeManager = $storeManager; parent::__construct($data); } @@ -189,7 +202,19 @@ public function getConfig($data = []) */ public function getSkinImagePlaceholderUrl() { - return $this->_assetRepo->getUrl('Magento_Cms::images/wysiwyg_skin_image.png'); + return $this->_assetRepo->getUrl(self::WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID); + } + + /** + * Return path for skin images placeholder + * + * @return string + */ + public function getSkinImagePlaceholderPath() + { + $staticPath = $this->_storeManager->getStore()->getBaseStaticDir(); + $placeholderPath = $this->_assetRepo->createAsset(self::WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID)->getPath(); + return $staticPath . '/' . $placeholderPath; } /** diff --git a/app/code/Magento/Store/Model/Store.php b/app/code/Magento/Store/Model/Store.php index 2d51a5f161858..94d5c2fd91551 100644 --- a/app/code/Magento/Store/Model/Store.php +++ b/app/code/Magento/Store/Model/Store.php @@ -594,6 +594,26 @@ public function getBaseUrl($type = \Magento\Framework\UrlInterface::URL_TYPE_LIN return $this->_baseUrlCache[$cacheKey]; } + /** + * Retrieve base media directory path + * + * @return string + */ + public function getBaseMediaDir() + { + return $this->filesystem->getUri(DirectoryList::MEDIA); + } + + /** + * Retrieve base static directory path + * + * @return string + */ + public function getBaseStaticDir() + { + return $this->filesystem->getUri(DirectoryList::STATIC_VIEW); + } + /** * Append script file name to url in case when server rewrites are disabled * diff --git a/dev/tests/unit/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/DirectiveTest.php b/dev/tests/unit/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/DirectiveTest.php new file mode 100644 index 0000000000000..d5fe5a685c795 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/DirectiveTest.php @@ -0,0 +1,248 @@ +actionContextMock = $this->getMockBuilder('Magento\Backend\App\Action\Context') + ->disableOriginalConstructor() + ->getMock(); + $this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface') + ->disableOriginalConstructor() + ->getMock(); + $this->urlDecoderMock = $this->getMockBuilder('Magento\Framework\Url\DecoderInterface') + ->disableOriginalConstructor() + ->getMock(); + $this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface') + ->disableOriginalConstructor() + ->getMock(); + $this->templateFilterMock = $this->getMockBuilder('Magento\Cms\Model\Template\Filter') + ->disableOriginalConstructor() + ->getMock(); + $this->imageAdapterFactoryMock = $this->getMockBuilder('Magento\Framework\Image\AdapterFactory') + ->disableOriginalConstructor() + ->getMock(); + $this->imageAdapterMock = $this->getMockBuilder('Magento\Framework\Image\Adapter\AdapterInterface') + ->disableOriginalConstructor() + ->setMethods( + [ + 'getMimeType', + 'getColorAt', + 'getImage', + 'watermark', + 'refreshImageDimensions', + 'checkDependencies', + 'createPngFromString', + 'open', + 'resize', + 'crop', + 'save', + 'rotate' + ] + ) + ->getMock(); + $this->responseMock = $this->getMockBuilder('Magento\Framework\App\ResponseInterface') + ->disableOriginalConstructor() + ->setMethods(['setHeader', 'setBody', 'sendResponse']) + ->getMock(); + $this->wysiwygConfigMock = $this->getMockBuilder('Magento\Cms\Model\Wysiwyg\Config') + ->disableOriginalConstructor() + ->getMock(); + $this->loggerMock = $this->getMockBuilder('Psr\Log\LoggerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $this->actionContextMock->expects($this->any()) + ->method('getRequest') + ->willReturn($this->requestMock); + $this->actionContextMock->expects($this->any()) + ->method('getResponse') + ->willReturn($this->responseMock); + $this->actionContextMock->expects($this->any()) + ->method('getObjectManager') + ->willReturn($this->objectManagerMock); + + $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->wysiwygDirective = $objectManager->getObject( + 'Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive', + [ + 'context' => $this->actionContextMock, + 'urlDecoder' => $this->urlDecoderMock + ] + ); + } + + /** + * @covers \Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive::execute + */ + public function testExecute() + { + $mimeType = 'image/jpeg'; + $imageBody = 'abcdefghijklmnopqrstuvwxyz0123456789'; + $this->prepareExecuteTest(); + + $this->imageAdapterMock->expects($this->once()) + ->method('open') + ->with(self::IMAGE_PATH); + $this->imageAdapterMock->expects($this->once()) + ->method('getMimeType') + ->willReturn($mimeType); + $this->responseMock->expects($this->once()) + ->method('setHeader') + ->with('Content-Type', $mimeType) + ->willReturnSelf(); + $this->imageAdapterMock->expects($this->once()) + ->method('getImage') + ->willReturn($imageBody); + $this->responseMock->expects($this->once()) + ->method('setBody') + ->with($imageBody) + ->willReturnSelf(); + + $this->wysiwygDirective->execute(); + } + + /** + * @covers \Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive::execute + */ + public function testExecuteException() + { + $exception = new \Exception('epic fail'); + $placeholderPath = 'pub/static/adminhtml/Magento/backend/en_US/Magento_Cms/images/wysiwyg_skin_image.png'; + $mimeType = 'image/png'; + $imageBody = '0123456789abcdefghijklmnopqrstuvwxyz'; + $this->prepareExecuteTest(); + + $this->imageAdapterMock->expects($this->at(0)) + ->method('open') + ->with(self::IMAGE_PATH) + ->willThrowException($exception); + $this->wysiwygConfigMock->expects($this->once()) + ->method('getSkinImagePlaceholderPath') + ->willReturn($placeholderPath); + $this->imageAdapterMock->expects($this->at(1)) + ->method('open') + ->with($placeholderPath); + $this->imageAdapterMock->expects($this->once()) + ->method('getMimeType') + ->willReturn($mimeType); + $this->responseMock->expects($this->once()) + ->method('setHeader') + ->with('Content-Type', $mimeType) + ->willReturnSelf(); + $this->imageAdapterMock->expects($this->once()) + ->method('getImage') + ->willReturn($imageBody); + $this->responseMock->expects($this->once()) + ->method('setBody') + ->with($imageBody) + ->willReturnSelf(); + $this->loggerMock->expects($this->once()) + ->method('critical') + ->with($exception); + + $this->wysiwygDirective->execute(); + } + + protected function prepareExecuteTest() + { + $directiveParam = 'e3ttZWRpYSB1cmw9Ind5c2l3eWcvYnVubnkuanBnIn19'; + $directive = '{{media url="wysiwyg/image.jpg"}}'; + + $this->requestMock->expects($this->once()) + ->method('getParam') + ->with('___directive') + ->willReturn($directiveParam); + $this->urlDecoderMock->expects($this->once()) + ->method('decode') + ->with($directiveParam) + ->willReturn($directive); + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with('Magento\Cms\Model\Template\Filter') + ->willReturn($this->templateFilterMock); + $this->templateFilterMock->expects($this->once()) + ->method('filter') + ->with($directive) + ->willReturn(self::IMAGE_PATH); + $this->objectManagerMock->expects($this->any()) + ->method('get') + ->willReturnMap( + [ + ['Magento\Framework\Image\AdapterFactory', $this->imageAdapterFactoryMock], + ['Magento\Cms\Model\Wysiwyg\Config', $this->wysiwygConfigMock], + ['Psr\Log\LoggerInterface', $this->loggerMock] + ] + ); + $this->imageAdapterFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->imageAdapterMock); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Cms/Model/Template/FilterTest.php b/dev/tests/unit/testsuite/Magento/Cms/Model/Template/FilterTest.php new file mode 100644 index 0000000000000..846d1078217a1 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Cms/Model/Template/FilterTest.php @@ -0,0 +1,65 @@ +storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface') + ->disableOriginalConstructor() + ->getMock(); + $this->storeMock = $this->getMockBuilder('Magento\Store\Model\Store') + ->disableOriginalConstructor() + ->getMock(); + $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->filter = $objectManager->getObject( + 'Magento\Cms\Model\Template\Filter', + ['storeManager' => $this->storeManagerMock] + ); + $this->storeManagerMock->expects($this->any()) + ->method('getStore') + ->willReturn($this->storeMock); + } + + /** + * @covers \Magento\Cms\Model\Template\Filter::mediaDirective + */ + public function testMediaDirective() + { + $baseMediaDir = 'pub/media'; + $construction = [ + '{{media url="wysiwyg/image.jpg"}}', + 'media', + ' url="wysiwyg/image.jpg"' + ]; + $expectedResult = 'pub/media/wysiwyg/image.jpg'; + $this->storeMock->expects($this->once()) + ->method('getBaseMediaDir') + ->willReturn($baseMediaDir); + $this->assertEquals($expectedResult, $this->filter->mediaDirective($construction)); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Cms/Model/Wysiwyg/ConfigTest.php b/dev/tests/unit/testsuite/Magento/Cms/Model/Wysiwyg/ConfigTest.php index ef11bec338eb8..c83e432b807da 100644 --- a/dev/tests/unit/testsuite/Magento/Cms/Model/Wysiwyg/ConfigTest.php +++ b/dev/tests/unit/testsuite/Magento/Cms/Model/Wysiwyg/ConfigTest.php @@ -9,10 +9,12 @@ */ class ConfigTest extends \PHPUnit_Framework_TestCase { + const WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID = 'Magento_Cms::images/wysiwyg_skin_image.png'; + /** * @var \Magento\Cms\Model\Wysiwyg\Config */ - protected $this; + protected $wysiwygConfig; /** * @var \Magento\Backend\Model\UrlInterface|\PHPUnit_Framework_MockObject_MockObject @@ -44,6 +46,21 @@ class ConfigTest extends \PHPUnit_Framework_TestCase */ protected $scopeConfigMock; + /** + * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $storeManagerMock; + + /** + * @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject + */ + protected $storeMock; + + /** + * @var \Magento\Framework\View\Asset\File|\PHPUnit_Framework_MockObject_MockObject + */ + protected $assetFileMock; + /** * @var array */ @@ -69,13 +86,22 @@ protected function setUp() $this->scopeConfigMock = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface') ->disableOriginalConstructor() ->getMock(); + $this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface') + ->disableOriginalConstructor() + ->getMock(); + $this->storeMock = $this->getMockBuilder('Magento\Store\Model\Store') + ->disableOriginalConstructor() + ->getMock(); + $this->assetFileMock = $this->getMockBuilder('Magento\Framework\View\Asset\File') + ->disableOriginalConstructor() + ->getMock(); $this->windowSize = [ 'width' => 1200, 'height' => 800, ]; $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); - $this->this = $objectManager->getObject( + $this->wysiwygConfig = $objectManager->getObject( 'Magento\Cms\Model\Wysiwyg\Config', [ 'backendUrl' => $this->backendUrlMock, @@ -84,7 +110,8 @@ protected function setUp() 'variableConfig' => $this->variableConfigMock, 'widgetConfig' => $this->widgetConfigMock, 'scopeConfig' => $this->scopeConfigMock, - 'windowSize' => $this->windowSize + 'windowSize' => $this->windowSize, + 'storeManager' => $this->storeManagerMock ] ); } @@ -130,7 +157,7 @@ public function testGetConfig($data, $isAuthorizationAllowed, $expectedResults) ->method('getPluginSettings') ->willReturn($pluginSettings); - $config = $this->this->getConfig($data); + $config = $this->wysiwygConfig->getConfig($data); $this->assertInstanceOf('Magento\Framework\Object', $config); $this->assertEquals($expectedResults[0], $config->getData('someData')); $this->assertEquals($expectedResults[1], $config->getData('wysiwygPluginSettings')); @@ -169,10 +196,36 @@ public function testGetSkinImagePlaceholderUrl() $this->assetRepoMock->expects($this->atLeastOnce()) ->method('getUrl') - ->with('Magento_Cms::images/wysiwyg_skin_image.png') + ->with(self::WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID) ->willReturn($url); - $this->assertEquals($url, $this->this->getSkinImagePlaceholderUrl()); + $this->assertEquals($url, $this->wysiwygConfig->getSkinImagePlaceholderUrl()); + } + + /** + * @covers \Magento\Cms\Model\Wysiwyg\Config::getSkinImagePlaceholderPath + */ + public function testGetSkinImagePlaceholderPath() + { + $staticPath = 'pub/static'; + $placeholderPath = 'adminhtml/Magento/backend/en_US/Magento_Cms/images/wysiwyg_skin_image.png'; + $expectedResult = 'pub/static/adminhtml/Magento/backend/en_US/Magento_Cms/images/wysiwyg_skin_image.png'; + + $this->storeManagerMock->expects($this->any()) + ->method('getStore') + ->willReturn($this->storeMock); + $this->storeMock->expects($this->any()) + ->method('getBaseStaticDir') + ->willReturn($staticPath); + $this->assetRepoMock->expects($this->any()) + ->method('createAsset') + ->with(self::WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID) + ->willReturn($this->assetFileMock); + $this->assetFileMock->expects($this->once()) + ->method('getPath') + ->willReturn($placeholderPath); + + $this->assertEquals($expectedResult, $this->wysiwygConfig->getSkinImagePlaceholderPath()); } /** @@ -185,16 +238,19 @@ public function testGetSkinImagePlaceholderUrl() public function testIsEnabled($wysiwygState, $expectedResult) { $storeId = 1; - $this->this->setStoreId($storeId); + $this->wysiwygConfig->setStoreId($storeId); $this->scopeConfigMock->expects($this->atLeastOnce()) ->method('getValue') ->with('cms/wysiwyg/enabled', 'store', $storeId) ->willReturn($wysiwygState); - $this->assertEquals($expectedResult, $this->this->isEnabled()); + $this->assertEquals($expectedResult, $this->wysiwygConfig->isEnabled()); } + /** + * @return array + */ public function isEnabledDataProvider() { return [ @@ -218,9 +274,12 @@ public function testIsHidden($status, $expectedResult) ->with('cms/wysiwyg/enabled', 'store') ->willReturn($status); - $this->assertEquals($expectedResult, $this->this->isHidden()); + $this->assertEquals($expectedResult, $this->wysiwygConfig->isHidden()); } + /** + * @return array + */ public function isHiddenDataProvider() { return [ diff --git a/dev/tests/unit/testsuite/Magento/Store/Model/StoreTest.php b/dev/tests/unit/testsuite/Magento/Store/Model/StoreTest.php index 27915e5bd7a1e..72b075f37b7b4 100644 --- a/dev/tests/unit/testsuite/Magento/Store/Model/StoreTest.php +++ b/dev/tests/unit/testsuite/Magento/Store/Model/StoreTest.php @@ -12,6 +12,14 @@ */ class StoreTest extends \PHPUnit_Framework_TestCase { + const MEDIA = 'media'; + const STATIC_VIEW = 'static'; + + /** + * @var \Magento\Store\Model\Store + */ + protected $store; + /** * @var \Magento\TestFramework\Helper\ObjectManager */ @@ -32,6 +40,11 @@ class StoreTest extends \PHPUnit_Framework_TestCase */ protected $cookieMetadataFactoryMock; + /** + * @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject + */ + protected $filesystemMock; + public function setUp() { $this->objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this); @@ -55,6 +68,13 @@ public function setUp() '', false ); + $this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem') + ->disableOriginalConstructor() + ->getMock(); + $this->store = $this->objectManagerHelper->getObject( + 'Magento\Store\Model\Store', + ['filesystem' => $this->filesystemMock] + ); } /** @@ -575,4 +595,30 @@ public function isCurrentlySecureDataProvider() 'unsecure request, not using registered port' => [false, ['SERVER_PORT' => 80]], ]; } + + /** + * @covers \Magento\Store\Model\Store::getBaseMediaDir + */ + public function testGetBaseMediaDir() + { + $expectedResult = 'pub/media'; + $this->filesystemMock->expects($this->once()) + ->method('getUri') + ->with(self::MEDIA) + ->willReturn($expectedResult); + $this->assertEquals($expectedResult, $this->store->getBaseMediaDir()); + } + + /** + * @covers \Magento\Store\Model\Store::getBaseStaticDir + */ + public function testGetBaseStaticDir() + { + $expectedResult = 'pub/static'; + $this->filesystemMock->expects($this->once()) + ->method('getUri') + ->with(self::STATIC_VIEW) + ->willReturn($expectedResult); + $this->assertEquals($expectedResult, $this->store->getBaseStaticDir()); + } } From cde23e9e232e89419d7ec3ac9a2aa63ccce9aa18 Mon Sep 17 00:00:00 2001 From: Yuri Kovsher Date: Tue, 6 Jan 2015 18:07:31 +0200 Subject: [PATCH 08/16] MAGETWO-21201: CLONE - Apply SUPEE-1805: Issue with disablign allow_url_fopen using the CMS WYSIWYG editor (patch) --- .../Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php | 1 - .../Cms/Controller/Adminhtml/Wysiwyg/DirectiveTest.php | 5 +---- .../unit/testsuite/Magento/Cms/Model/Template/FilterTest.php | 5 +---- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php b/app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php index 0a3c43336a54f..55f0f01839565 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php @@ -1,6 +1,5 @@ Date: Tue, 6 Jan 2015 18:25:00 +0200 Subject: [PATCH 09/16] MAGETWO-21201: CLONE - Apply SUPEE-1805: Issue with disablign allow_url_fopen using the CMS WYSIWYG editor (patch) --- app/code/Magento/Cms/Model/Template/Filter.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/code/Magento/Cms/Model/Template/Filter.php b/app/code/Magento/Cms/Model/Template/Filter.php index 52b84500a78d0..77f6c388c97f8 100644 --- a/app/code/Magento/Cms/Model/Template/Filter.php +++ b/app/code/Magento/Cms/Model/Template/Filter.php @@ -28,6 +28,12 @@ public function setUseSessionInUrl($flag) return $this; } + /** + * Retrieve media file URL directive + * + * @param string[] $construction + * @return string + */ public function mediaDirective($construction) { $params = $this->_getIncludeParameters($construction[2]); From 90f0f857e35faa4adfb94a3b32f016aec7a4908c Mon Sep 17 00:00:00 2001 From: Yuri Kovsher Date: Tue, 6 Jan 2015 18:36:05 +0200 Subject: [PATCH 10/16] MAGETWO-21201: CLONE - Apply SUPEE-1805: Issue with disablign allow_url_fopen using the CMS WYSIWYG editor (patch) --- app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php b/app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php index 55f0f01839565..14d8e979cb3f9 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php @@ -5,7 +5,6 @@ namespace Magento\Cms\Controller\Adminhtml\Wysiwyg; use Magento\Backend\App\Action; -use SebastianBergmann\Exporter\Exception; class Directive extends \Magento\Backend\App\Action { From 9b6d01936ca4311ff79f60ba05c597c54a069053 Mon Sep 17 00:00:00 2001 From: Yuri Kovsher Date: Thu, 8 Jan 2015 16:19:30 +0200 Subject: [PATCH 11/16] MAGETWO-21201: CLONE - Apply SUPEE-1805: Issue with disablign allow_url_fopen using the CMS WYSIWYG editor (patch) --- app/code/Magento/Cms/Model/Wysiwyg/Config.php | 10 ---------- .../Test/Legacy/_files/obsolete_methods.php | 3 ++- .../Magento/Cms/Model/Wysiwyg/ConfigTest.php | 19 +------------------ .../Magento/Store/Model/StoreTest.php | 7 ++----- 4 files changed, 5 insertions(+), 34 deletions(-) diff --git a/app/code/Magento/Cms/Model/Wysiwyg/Config.php b/app/code/Magento/Cms/Model/Wysiwyg/Config.php index 0b394f3743e5e..d7dcac1eff04c 100644 --- a/app/code/Magento/Cms/Model/Wysiwyg/Config.php +++ b/app/code/Magento/Cms/Model/Wysiwyg/Config.php @@ -195,16 +195,6 @@ public function getConfig($data = []) return $config; } - /** - * Return URL for skin images placeholder - * - * @return string - */ - public function getSkinImagePlaceholderUrl() - { - return $this->_assetRepo->getUrl(self::WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID); - } - /** * Return path for skin images placeholder * diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php index 425044b2bdd62..d5ad5bb01f36a 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php @@ -2008,5 +2008,6 @@ ], ['getLinksConfig', 'Magento\Downloadable\Block\Catalog\Product\Links'], ['getAuthorizationAmounts', 'Magento\Paypal\Model\Config'], - ['cleanTransactions', 'Magento\Paypal\Model\Observer'] + ['cleanTransactions', 'Magento\Paypal\Model\Observer'], + ['getSkinImagePlaceholderUrl', 'Magento\Cms\Model\Wysiwyg\Config'] ]; diff --git a/dev/tests/unit/testsuite/Magento/Cms/Model/Wysiwyg/ConfigTest.php b/dev/tests/unit/testsuite/Magento/Cms/Model/Wysiwyg/ConfigTest.php index c83e432b807da..501107e443334 100644 --- a/dev/tests/unit/testsuite/Magento/Cms/Model/Wysiwyg/ConfigTest.php +++ b/dev/tests/unit/testsuite/Magento/Cms/Model/Wysiwyg/ConfigTest.php @@ -9,8 +9,6 @@ */ class ConfigTest extends \PHPUnit_Framework_TestCase { - const WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID = 'Magento_Cms::images/wysiwyg_skin_image.png'; - /** * @var \Magento\Cms\Model\Wysiwyg\Config */ @@ -187,21 +185,6 @@ public function getConfigDataProvider() ]; } - /** - * @covers \Magento\Cms\Model\Wysiwyg\Config::getSkinImagePlaceholderUrl - */ - public function testGetSkinImagePlaceholderUrl() - { - $url = '/some/url'; - - $this->assetRepoMock->expects($this->atLeastOnce()) - ->method('getUrl') - ->with(self::WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID) - ->willReturn($url); - - $this->assertEquals($url, $this->wysiwygConfig->getSkinImagePlaceholderUrl()); - } - /** * @covers \Magento\Cms\Model\Wysiwyg\Config::getSkinImagePlaceholderPath */ @@ -219,7 +202,7 @@ public function testGetSkinImagePlaceholderPath() ->willReturn($staticPath); $this->assetRepoMock->expects($this->any()) ->method('createAsset') - ->with(self::WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID) + ->with(\Magento\Cms\Model\Wysiwyg\Config::WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID) ->willReturn($this->assetFileMock); $this->assetFileMock->expects($this->once()) ->method('getPath') diff --git a/dev/tests/unit/testsuite/Magento/Store/Model/StoreTest.php b/dev/tests/unit/testsuite/Magento/Store/Model/StoreTest.php index 72b075f37b7b4..9ff8d03279ac8 100644 --- a/dev/tests/unit/testsuite/Magento/Store/Model/StoreTest.php +++ b/dev/tests/unit/testsuite/Magento/Store/Model/StoreTest.php @@ -12,9 +12,6 @@ */ class StoreTest extends \PHPUnit_Framework_TestCase { - const MEDIA = 'media'; - const STATIC_VIEW = 'static'; - /** * @var \Magento\Store\Model\Store */ @@ -604,7 +601,7 @@ public function testGetBaseMediaDir() $expectedResult = 'pub/media'; $this->filesystemMock->expects($this->once()) ->method('getUri') - ->with(self::MEDIA) + ->with(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA) ->willReturn($expectedResult); $this->assertEquals($expectedResult, $this->store->getBaseMediaDir()); } @@ -617,7 +614,7 @@ public function testGetBaseStaticDir() $expectedResult = 'pub/static'; $this->filesystemMock->expects($this->once()) ->method('getUri') - ->with(self::STATIC_VIEW) + ->with(\Magento\Framework\App\Filesystem\DirectoryList::STATIC_VIEW) ->willReturn($expectedResult); $this->assertEquals($expectedResult, $this->store->getBaseStaticDir()); } From 7d04df2e101dc983e8966c8c4d34d705f1558c3e Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Thu, 8 Jan 2015 16:46:22 +0200 Subject: [PATCH 12/16] MAGETWO-17690: 'Orders & Returns' widget type contain unnecessary tab - Method isHidden modified; - Added dataProvider to unit test; --- .../Widget/Instance/Edit/Tab/Properties.php | 12 ++- .../Instance/Edit/Tab/PropertiesTest.php | 94 +++++++++---------- 2 files changed, 49 insertions(+), 57 deletions(-) diff --git a/app/code/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php b/app/code/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php index 6ccfbddc22120..561382d6e9f57 100644 --- a/app/code/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php +++ b/app/code/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php @@ -16,7 +16,7 @@ class Properties extends \Magento\Widget\Block\Adminhtml\Widget\Options implemen /** * Widget config parameter */ - const WIDGET_PARAMETER = 'template'; + const WIDGET_TEMPLATE_PARAMETER = 'template'; /** * Prepare label for tab @@ -55,11 +55,13 @@ public function canShowTab() */ public function isHidden() { - $parameters = $this->getWidgetInstance()->getWidgetConfigAsArray()['parameters']; + $widgetConfig = $this->getWidgetInstance()->getWidgetConfigAsArray(); - foreach ($parameters as $key => $parameter) { - if ($parameter['visible'] == 1 && $key != self::WIDGET_PARAMETER) { - return false; + if (in_array('parameters', array_keys($widgetConfig))) { + foreach ($widgetConfig['parameters'] as $key => $parameter) { + if ($parameter['visible'] == 1 && $key != self::WIDGET_TEMPLATE_PARAMETER) { + return false; + } } } diff --git a/dev/tests/unit/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/PropertiesTest.php b/dev/tests/unit/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/PropertiesTest.php index a88967f2d0a3e..61ace42b649a5 100644 --- a/dev/tests/unit/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/PropertiesTest.php +++ b/dev/tests/unit/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/PropertiesTest.php @@ -6,33 +6,24 @@ class PropertiesTest extends \PHPUnit_Framework_TestCase { - public function testIsHiddenTrue() + /** + * @param array $widgetConfig + * @param boolean $expected + * + * @dataProvider isHiddenDataProvider + */ + public function testIsHidden($widgetConfig, $expected) { - $widgetConfig = [ - 'parameters' => [ - 'title' => [ - 'type' => 'text', - 'visible' => '0', - ], - 'template' => [ - 'type' => 'select', - 'visible' => '1', - ], - ] - ]; - /** @var \Magento\Widget\Model\Widget\Instance|\PHPUnit_Framework_MockObject_MockObject $widget */ $widget = $this->getMock('Magento\Widget\Model\Widget\Instance', [], [], '', false); - $widget->expects($this->atLeastOnce()) - ->method('getWidgetConfigAsArray') - ->will($this->returnValue($widgetConfig)); + $widget->expects($this->atLeastOnce())->method('getWidgetConfigAsArray')->willReturn($widgetConfig); /** @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject $registry */ $registry = $this->getMock('Magento\Framework\Registry', [], [], '', false); $registry->expects($this->atLeastOnce()) ->method('registry') ->with('current_widget_instance') - ->will($this->returnValue($widget)); + ->willReturn($widget); $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); /** @var \Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Properties $propertiesBlock */ @@ -43,46 +34,45 @@ public function testIsHiddenTrue() ] ); - $this->assertTrue($propertiesBlock->isHidden()); + $this->assertEquals($expected, $propertiesBlock->isHidden()); } - public function testIsHiddenFalse() + /** + * @return array + */ + public function isHiddenDataProvider() { - $widgetConfig = [ - 'parameters' => [ - 'types' => [ - 'type' => 'multiselect', - 'visible' => '1', + return [ + [ + 'widgetConfig' => [ + 'parameters' => [ + 'title' => [ + 'type' => 'text', + 'visible' => '0', + ], + 'template' => [ + 'type' => 'select', + 'visible' => '1', + ], + ] ], - 'template' => [ - 'type' => 'select', - 'visible' => '1', + 'expected' => true + ], + [ + 'widgetConfig' => [ + 'parameters' => [ + 'types' => [ + 'type' => 'multiselect', + 'visible' => '1', + ], + 'template' => [ + 'type' => 'select', + 'visible' => '1', + ], + ] ], + 'expected' => false ] ]; - - /** @var \Magento\Widget\Model\Widget\Instance|\PHPUnit_Framework_MockObject_MockObject $widget */ - $widget = $this->getMock('Magento\Widget\Model\Widget\Instance', [], [], '', false); - $widget->expects($this->atLeastOnce()) - ->method('getWidgetConfigAsArray') - ->will($this->returnValue($widgetConfig)); - - /** @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject $registry */ - $registry = $this->getMock('Magento\Framework\Registry', [], [], '', false); - $registry->expects($this->atLeastOnce()) - ->method('registry') - ->with('current_widget_instance') - ->will($this->returnValue($widget)); - - $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); - /** @var \Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Properties $propertiesBlock */ - $propertiesBlock = $objectManager->getObject( - 'Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Properties', - [ - 'registry' => $registry - ] - ); - - $this->assertFalse($propertiesBlock->isHidden()); } } From 2b07c12d11fe96ff0569822058a0e668ad5c1916 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Fri, 9 Jan 2015 15:52:07 +0200 Subject: [PATCH 13/16] MAGETWO-17690: 'Orders & Returns' widget type contain unnecessary tab - Method isHidden and _addField modified; - Added method setUp and dataProviders to unit test; --- .../Widget/Instance/Edit/Tab/Properties.php | 14 ++-- .../Instance/Edit/Tab/PropertiesTest.php | 73 +++++++++++++------ 2 files changed, 61 insertions(+), 26 deletions(-) diff --git a/app/code/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php b/app/code/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php index 561382d6e9f57..bc8e6462140e3 100644 --- a/app/code/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php +++ b/app/code/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php @@ -14,9 +14,13 @@ class Properties extends \Magento\Widget\Block\Adminhtml\Widget\Options implemen \Magento\Backend\Block\Widget\Tab\TabInterface { /** - * Widget config parameter + * Widget config parameters + * + * @var array */ - const WIDGET_TEMPLATE_PARAMETER = 'template'; + protected $hiddenParameters = [ + 'template' + ]; /** * Prepare label for tab @@ -57,9 +61,9 @@ public function isHidden() { $widgetConfig = $this->getWidgetInstance()->getWidgetConfigAsArray(); - if (in_array('parameters', array_keys($widgetConfig))) { + if (isset($widgetConfig['parameters'])) { foreach ($widgetConfig['parameters'] as $key => $parameter) { - if ($parameter['visible'] == 1 && $key != self::WIDGET_TEMPLATE_PARAMETER) { + if ($parameter['visible'] == 1 && !in_array($key, $this->hiddenParameters)) { return false; } } @@ -102,7 +106,7 @@ protected function _preparelayout() */ protected function _addField($parameter) { - if ($parameter->getKey() != 'template') { + if (!in_array($parameter->getKey(), $this->hiddenParameters)) { return parent::_addField($parameter); } return false; diff --git a/dev/tests/unit/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/PropertiesTest.php b/dev/tests/unit/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/PropertiesTest.php index 61ace42b649a5..d08e4bae2db74 100644 --- a/dev/tests/unit/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/PropertiesTest.php +++ b/dev/tests/unit/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/PropertiesTest.php @@ -7,34 +7,50 @@ class PropertiesTest extends \PHPUnit_Framework_TestCase { /** - * @param array $widgetConfig - * @param boolean $expected - * - * @dataProvider isHiddenDataProvider + * @var \PHPUnit_Framework_MockObject_MockObject */ - public function testIsHidden($widgetConfig, $expected) - { - /** @var \Magento\Widget\Model\Widget\Instance|\PHPUnit_Framework_MockObject_MockObject $widget */ - $widget = $this->getMock('Magento\Widget\Model\Widget\Instance', [], [], '', false); - $widget->expects($this->atLeastOnce())->method('getWidgetConfigAsArray')->willReturn($widgetConfig); + protected $widget; - /** @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject $registry */ - $registry = $this->getMock('Magento\Framework\Registry', [], [], '', false); - $registry->expects($this->atLeastOnce()) - ->method('registry') - ->with('current_widget_instance') - ->willReturn($widget); + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $registry; + + /** + * @var \Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Properties + */ + protected $propertiesBlock; + + protected function setUp() + { + $this->widget = $this->getMock('Magento\Widget\Model\Widget\Instance', [], [], '', false); + $this->registry = $this->getMock('Magento\Framework\Registry', [], [], '', false); $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); - /** @var \Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Properties $propertiesBlock */ - $propertiesBlock = $objectManager->getObject( + $this->propertiesBlock = $objectManager->getObject( 'Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Properties', [ - 'registry' => $registry + 'registry' => $this->registry ] ); + } + + /** + * @param array $widgetConfig + * @param boolean $isHidden + * + * @dataProvider isHiddenDataProvider + */ + public function testIsHidden($widgetConfig, $isHidden) + { + $this->widget->expects($this->atLeastOnce())->method('getWidgetConfigAsArray')->willReturn($widgetConfig); - $this->assertEquals($expected, $propertiesBlock->isHidden()); + $this->registry->expects($this->atLeastOnce()) + ->method('registry') + ->with('current_widget_instance') + ->willReturn($this->widget); + + $this->assertEquals($isHidden, $this->propertiesBlock->isHidden()); } /** @@ -56,7 +72,7 @@ public function isHiddenDataProvider() ], ] ], - 'expected' => true + 'isHidden' => true ], [ 'widgetConfig' => [ @@ -71,7 +87,22 @@ public function isHiddenDataProvider() ], ] ], - 'expected' => false + 'isHidden' => false + ], + [ + 'widgetConfig' => [], + 'isHidden' => true + ], + [ + 'widgetConfig' => [ + 'parameters' => [ + 'template' => [ + 'type' => 'select', + 'visible' => '0', + ], + ] + ], + 'isHidden' => true ] ]; } From 722978818d36c307ed05230040175af41a71f134 Mon Sep 17 00:00:00 2001 From: Yuri Kovsher Date: Mon, 12 Jan 2015 13:02:00 +0200 Subject: [PATCH 14/16] MAGETWO-32475: Create pull request for bug fixing --- .../Magento/Test/Legacy/_files/obsolete_methods.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php index 4776f732dac30..2ba7251b8a32e 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php @@ -2015,11 +2015,10 @@ ['getLinksConfig', 'Magento\Downloadable\Block\Catalog\Product\Links'], ['getAuthorizationAmounts', 'Magento\Paypal\Model\Config'], ['cleanTransactions', 'Magento\Paypal\Model\Observer'], - ['getSkinImagePlaceholderUrl', 'Magento\Cms\Model\Wysiwyg\Config'] - ['cleanTransactions', 'Magento\Paypal\Model\Observer'], + ['getSkinImagePlaceholderUrl', 'Magento\Cms\Model\Wysiwyg\Config'], ['compareIndexColumnProperties', 'Magento\Catalog\Model\Resource\Helper'], ['getIsNullNotNullCondition', 'Magento\Catalog\Model\Resource\Helper'], ['_getCategoryPath', 'Magento\Catalog\Model\Resource\Setup'], ['_getCategoryEntityRow', 'Magento\Catalog\Model\Resource\Setup'], - ['createEavAttributeResource', 'Magento\Catalog\Model\Resource\Setup'], + ['createEavAttributeResource', 'Magento\Catalog\Model\Resource\Setup'] ]; From 8910cbc442bdb11e4517a54a43f4cf9b7eed4086 Mon Sep 17 00:00:00 2001 From: Yuri Kovsher Date: Mon, 12 Jan 2015 14:00:06 +0200 Subject: [PATCH 15/16] MAGETWO-32475: Create pull request for bug fixing --- app/code/Magento/PageCache/Controller/Block.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/PageCache/Controller/Block.php b/app/code/Magento/PageCache/Controller/Block.php index f5965b308eb29..8f93c943f5df4 100644 --- a/app/code/Magento/PageCache/Controller/Block.php +++ b/app/code/Magento/PageCache/Controller/Block.php @@ -15,6 +15,7 @@ class Block extends \Magento\Framework\App\Action\Action /** * @param \Magento\Framework\App\Action\Context $context + * @param \Magento\Framework\Translate\InlineInterface $translateInline */ public function __construct( \Magento\Framework\App\Action\Context $context, From 733006d156cae93a1b942fbd62de84ff3bfb8e42 Mon Sep 17 00:00:00 2001 From: Yuri Kovsher Date: Tue, 13 Jan 2015 17:57:53 +0200 Subject: [PATCH 16/16] MAGETWO-32475: Create pull request for bug fixing --- .../Magento/Cms/Controller/Adminhtml/Wysiwyg/DirectiveTest.php | 3 ++- .../unit/testsuite/Magento/Cms/Model/Template/FilterTest.php | 3 ++- .../Adminhtml/Widget/Instance/Edit/Tab/PropertiesTest.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/DirectiveTest.php b/dev/tests/unit/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/DirectiveTest.php index 6358ee0162fa2..021506cdbb634 100644 --- a/dev/tests/unit/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/DirectiveTest.php +++ b/dev/tests/unit/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/DirectiveTest.php @@ -1,6 +1,7 @@