Skip to content

Commit

Permalink
Merge pull request #686 from magento-tsg/2.0-prs
Browse files Browse the repository at this point in the history
[TSG] Backporting for 2.0 (prs)
  • Loading branch information
Volodymyr Klymenko authored Dec 20, 2016
2 parents d4f01eb + 8aa86ea commit ea6f29c
Show file tree
Hide file tree
Showing 21 changed files with 432 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ protected function setupOrderMock(
'getCustomerEmail',
'getCustomerId',
'getStoreId',
'getTotalDue'
'getBaseTotalDue'
]
)->getMock();

Expand All @@ -501,7 +501,7 @@ protected function setupOrderMock(
->method('getStoreId')
->willReturn($storeId);
$orderMock->expects(static::any())
->method('getTotalDue')
->method('getBaseTotalDue')
->willReturn(self::TOTAL_AMOUNT);

$this->orderRepository->expects(static::any())
Expand Down Expand Up @@ -1704,7 +1704,7 @@ protected function setupPaymentObjectForCapture($paymentId)
$order = $this->getMockBuilder('Magento\Sales\Api\Data\OrderInterface')
->getMockForAbstractClass();
$order->expects(static::any())
->method('getTotalDue')
->method('getBaseTotalDue')
->willReturn(self::TOTAL_AMOUNT);
$this->orderRepository->expects(static::any())
->method('get')
Expand Down
28 changes: 25 additions & 3 deletions app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Catalog\Controller\Adminhtml\Category;

use Magento\Store\Model\StoreManagerInterface;

/**
* Class Save
*/
Expand All @@ -25,6 +27,11 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Category
*/
protected $layoutFactory;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* Constructor
*
Expand Down Expand Up @@ -82,6 +89,9 @@ public function execute()
}

$storeId = $this->getRequest()->getParam('store');
$store = $this->getStoreManager()->getStore($storeId);
$this->getStoreManager()->setCurrentStore($store->getCode());

$refreshTree = false;
$data = $this->getRequest()->getPostValue();
if ($data) {
Expand All @@ -90,9 +100,7 @@ public function execute()
$parentId = $this->getRequest()->getParam('parent');
if (!$parentId) {
if ($storeId) {
$parentId = $this->_objectManager->get(
'Magento\Store\Model\StoreManagerInterface'
)->getStore(
$parentId = $this->getStoreManager()->getStore(
$storeId
)->getRootCategoryId();
} else {
Expand Down Expand Up @@ -211,4 +219,18 @@ public function execute()
$redirectParams
);
}

/**
* Get StoreManager object
*
* @return StoreManagerInterface
*/
private function getStoreManager()
{
if ($this->storeManager == null) {
$this->storeManager = $this->_objectManager->get(StoreManagerInterface::class);
}

return $this->storeManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function setUp()
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);

$this->contextMock = $this->getMock(
'Magento\Backend\App\Action\Context',
\Magento\Backend\App\Action\Context::class,
[
'getTitle',
'getRequest',
Expand All @@ -102,47 +102,47 @@ protected function setUp()
false
);
$this->resultRedirectFactoryMock = $this->getMock(
'Magento\Backend\Model\View\Result\RedirectFactory',
\Magento\Backend\Model\View\Result\RedirectFactory::class,
['create'],
[],
'',
false
);
$this->resultRawFactoryMock = $this->getMock(
'Magento\Framework\Controller\Result\RawFactory',
\Magento\Framework\Controller\Result\RawFactory::class,
[],
[],
'',
false
);
$this->resultJsonFactoryMock = $this->getMock(
'Magento\Framework\Controller\Result\JsonFactory',
\Magento\Framework\Controller\Result\JsonFactory::class,
['create'],
[],
'',
false
);
$this->layoutFactoryMock = $this->getMock(
'Magento\Framework\View\LayoutFactory',
\Magento\Framework\View\LayoutFactory::class,
['create'],
[],
'',
false
);
$this->requestMock = $this->getMockForAbstractClass(
'Magento\Framework\App\RequestInterface',
\Magento\Framework\App\RequestInterface::class,
[],
'',
false,
true,
true,
['getParam', 'getPost', 'getPostValue']
);
$this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface')
$this->objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$this->eventManagerMock = $this->getMockForAbstractClass(
'Magento\Framework\Event\ManagerInterface',
\Magento\Framework\Event\ManagerInterface::class,
[],
'',
false,
Expand All @@ -151,13 +151,13 @@ protected function setUp()
['dispatch']
);
$this->responseMock = $this->getMockForAbstractClass(
'Magento\Framework\App\ResponseInterface',
\Magento\Framework\App\ResponseInterface::class,
[],
'',
false
);
$this->messageManagerMock = $this->getMockForAbstractClass(
'Magento\Framework\Message\ManagerInterface',
\Magento\Framework\Message\ManagerInterface::class,
[],
'',
false,
Expand All @@ -177,7 +177,7 @@ protected function setUp()
->willReturn($this->resultRedirectFactoryMock);

$this->save = $this->objectManager->getObject(
'Magento\Catalog\Controller\Adminhtml\Category\Save',
\Magento\Catalog\Controller\Adminhtml\Category\Save::class,
[
'context' => $this->contextMock,
'resultRawFactory' => $this->resultRawFactoryMock,
Expand Down Expand Up @@ -212,7 +212,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
* |\PHPUnit_Framework_MockObject_MockObject $resultRedirectMock
*/
$resultRedirectMock = $this->getMock(
'Magento\Backend\Model\View\Result\Redirect',
\Magento\Backend\Model\View\Result\Redirect::class,
[],
[],
'',
Expand All @@ -223,7 +223,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
* |\PHPUnit_Framework_MockObject_MockObject $blockMock
*/
$blockMock = $this->getMock(
'Magento\Framework\View\Element\Messages',
\Magento\Framework\View\Element\Messages::class,
['setMessages', 'getGroupedHtml'],
[],
'',
Expand All @@ -234,7 +234,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
* |\PHPUnit_Framework_MockObject_MockObject $categoryMock
*/
$categoryMock = $this->getMock(
'Magento\Catalog\Model\Category',
\Magento\Catalog\Model\Category::class,
[
'setStoreId',
'load',
Expand Down Expand Up @@ -263,7 +263,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
* |\PHPUnit_Framework_MockObject_MockObject $parentCategoryMock
*/
$parentCategoryMock = $this->getMock(
'Magento\Catalog\Model\Category',
\Magento\Catalog\Model\Category::class,
[
'setStoreId',
'load',
Expand All @@ -287,7 +287,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
* |\PHPUnit_Framework_MockObject_MockObject $sessionMock
*/
$sessionMock = $this->getMock(
'Magento\Backend\Model\Auth\Session',
\Magento\Backend\Model\Auth\Session::class,
['setActiveTabId'],
[],
'',
Expand All @@ -298,7 +298,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
* |\PHPUnit_Framework_MockObject_MockObject $registryMock
*/
$registryMock = $this->getMock(
'Magento\Framework\Registry',
\Magento\Framework\Registry::class,
['register'],
[],
'',
Expand All @@ -309,7 +309,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
* |\PHPUnit_Framework_MockObject_MockObject $wysiwygConfigMock
*/
$wysiwygConfigMock = $this->getMock(
'Magento\Cms\Model\Wysiwyg\Config',
\Magento\Cms\Model\Wysiwyg\Config::class,
['setStoreId'],
[],
'',
Expand All @@ -320,20 +320,20 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
* |\PHPUnit_Framework_MockObject_MockObject $storeManagerMock
*/
$storeManagerMock = $this->getMockForAbstractClass(
'Magento\Store\Model\StoreManagerInterface',
\Magento\Store\Model\StoreManagerInterface::class,
[],
'',
false,
true,
true,
['getStore', 'getRootCategoryId']
['getStore', 'getRootCategoryId', 'setCurrentStore']
);
/**
* @var \Magento\Framework\View\Layout
* |\PHPUnit_Framework_MockObject_MockObject $layoutMock
*/
$layoutMock = $this->getMockForAbstractClass(
'Magento\Framework\View\Layout',
\Magento\Framework\View\Layout::class,
[],
'',
false,
Expand All @@ -346,7 +346,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
* |\PHPUnit_Framework_MockObject_MockObject $resultJsonMock
*/
$resultJsonMock = $this->getMock(
'Magento\Cms\Model\Wysiwyg\Config',
\Magento\Cms\Model\Wysiwyg\Config::class,
['setData'],
[],
'',
Expand All @@ -357,13 +357,26 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
* |\PHPUnit_Framework_MockObject_MockObject $messagesMock
*/
$messagesMock = $this->getMock(
'Magento\Framework\Message\Collection',
\Magento\Framework\Message\Collection::class,
[],
[],
'',
false
);

/**
* @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject $storeMock
*/
$storeMock = $this->getMock(
\Magento\Store\Model\Store::class,
[
'getCode',
],
[],
'',
false
);

$this->resultRedirectFactoryMock->expects($this->once())
->method('create')
->will($this->returnValue($resultRedirectMock));
Expand All @@ -379,6 +392,15 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
]
)
);

$storeMock->expects($this->once())
->method('getCode')
->will($this->returnValue('admin'));

$storeManagerMock->expects($this->once())
->method('setCurrentStore')
->with('admin');

$this->objectManagerMock->expects($this->atLeastOnce())
->method('create')
->will($this->returnValue($categoryMock));
Expand All @@ -387,10 +409,10 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
->will(
$this->returnValueMap(
[
['Magento\Backend\Model\Auth\Session', $sessionMock],
['Magento\Framework\Registry', $registryMock],
['Magento\Cms\Model\Wysiwyg\Config', $wysiwygConfigMock],
['Magento\Store\Model\StoreManagerInterface', $storeManagerMock],
[\Magento\Backend\Model\Auth\Session::class, $sessionMock],
[\Magento\Framework\Registry::class, $registryMock],
[\Magento\Cms\Model\Wysiwyg\Config::class, $wysiwygConfigMock],
[\Magento\Store\Model\StoreManagerInterface::class, $storeManagerMock],
]
)
);
Expand Down Expand Up @@ -441,15 +463,23 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)

if (!$parentId) {
if ($storeId) {
$storeManagerMock->expects($this->once())
$storeManagerMock->expects($this->exactly(2))
->method('getStore')
->with($storeId)
->will($this->returnSelf());
->willReturnOnConsecutiveCalls(
$storeMock,
$this->returnSelf()
);
$storeManagerMock->expects($this->once())
->method('getRootCategoryId')
->will($this->returnValue($rootCategoryId));
$parentId = $rootCategoryId;
}
} else {
$storeManagerMock->expects($this->once())
->method('getStore')
->with($storeId)
->will($this->returnValue($storeMock));
}
$categoryMock->expects($this->any())
->method('load')
Expand Down Expand Up @@ -494,7 +524,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
);

$categoryResource = $this->getMock(
'Magento\Catalog\Model\ResourceModel\Category',
\Magento\Catalog\Model\ResourceModel\Category::class,
[],
[],
'',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@

<!-- ko foreach: { data: currentBillingAddress().customAttributes, as: 'element' } -->
<!-- ko foreach: { data: Object.keys(element), as: 'attribute' } -->
<!-- ko text: element[attribute].value --><!-- /ko -->
<!-- ko if: (typeof element[attribute] === "object") -->
<!-- ko text: element[attribute].value --><!-- /ko -->
<!-- /ko -->

<!-- ko if: (typeof element[attribute] === "string") -->
<!-- ko text: element[attribute] --><!-- /ko -->
<!-- /ko --><br/>
<!-- /ko -->
<!-- /ko -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@

<!-- ko foreach: { data: address().customAttributes, as: 'element' } -->
<!-- ko foreach: { data: Object.keys(element), as: 'attribute' } -->
<!-- ko text: element[attribute].value --><!-- /ko -->
<!-- ko if: (typeof element[attribute] === "object") -->
<!-- ko text: element[attribute].value --><!-- /ko -->
<!-- /ko -->

<!-- ko if: (typeof element[attribute] === "string") -->
<!-- ko text: element[attribute] --><!-- /ko -->
<!-- /ko --><br/>
<!-- /ko -->
<!-- /ko -->

Expand Down
Loading

0 comments on commit ea6f29c

Please sign in to comment.