Skip to content

Commit

Permalink
Merge pull request #475 from magento-falcons/MAGETWO-59282
Browse files Browse the repository at this point in the history
Bugs:
* MAGETWO-59282: There is no Scope Selector on Product Grid
  • Loading branch information
magicbunneh authored Oct 10, 2016
2 parents 7003dff + 91a4b18 commit d8eac00
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public function execute()
$productIds = $collection->getAllIds();
$storeId = (int) $this->getRequest()->getParam('store', 0);
$status = (int) $this->getRequest()->getParam('status');
$filters = (array)$this->getRequest()->getParam('filters', []);

if (isset($filters['store_id'])) {
$storeId = (int)$filters['store_id'];
}

try {
$this->_validateMassStatus($productIds, $status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,74 @@
*/
namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Product;

use Magento\Ui\Component\MassAction\Filter;
use Magento\Backend\Model\View\Result\Redirect;
use Magento\Catalog\Model\Indexer\Product\Price\Processor;
use Magento\Catalog\Controller\Adminhtml\Product\Builder;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Catalog\Model\Product\Action;

/**
* Class MassStatusTest
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class MassStatusTest extends \Magento\Catalog\Test\Unit\Controller\Adminhtml\ProductTest
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var Processor|\PHPUnit_Framework_MockObject_MockObject
*/
protected $priceProcessor;
private $priceProcessorMock;

/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Model\View\Result\Redirect */
protected $resultRedirect;
/**
* @var Redirect|\PHPUnit_Framework_MockObject_MockObject
*/
private $resultRedirectMock;

/**
* @var Filter|\PHPUnit_Framework_MockObject_MockObject
*/
private $filterMock;

/**
* @var Builder|\PHPUnit_Framework_MockObject_MockObject
*/
private $productBuilderMock;

/**
* @var AbstractDb|\PHPUnit_Framework_MockObject_MockObject
*/
private $abstractDbMock;

/**
* @var Action|\PHPUnit_Framework_MockObject_MockObject
*/
private $actionMock;

protected function setUp()
{
$this->priceProcessor = $this->getMockBuilder(\Magento\Catalog\Model\Indexer\Product\Price\Processor::class)
$this->priceProcessorMock = $this->getMockBuilder(Processor::class)
->disableOriginalConstructor()->getMock();
$this->productBuilderMock = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->disableOriginalConstructor()
->getMock();

$productBuilder = $this->getMockBuilder(
\Magento\Catalog\Controller\Adminhtml\Product\Builder::class
)->setMethods(['build'])->disableOriginalConstructor()->getMock();

$product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)->disableOriginalConstructor()
->setMethods(['getTypeId', 'getStoreId', '__sleep', '__wakeup'])->getMock();
$product->expects($this->any())->method('getTypeId')->will($this->returnValue('simple'));
$product->expects($this->any())->method('getStoreId')->will($this->returnValue('1'));
$productBuilder->expects($this->any())->method('build')->will($this->returnValue($product));
$productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
->disableOriginalConstructor()
->setMethods(['getTypeId', 'getStoreId', '__sleep', '__wakeup'])
->getMock();
$productMock->expects($this->any())
->method('getTypeId')
->willReturn('simple');
$productMock->expects($this->any())
->method('getStoreId')
->willReturn('1');
$this->productBuilderMock->expects($this->any())
->method('build')
->willReturn($productMock);

$this->resultRedirect = $this->getMockBuilder(\Magento\Backend\Model\View\Result\Redirect::class)
$this->resultRedirectMock = $this->getMockBuilder(\Magento\Backend\Model\View\Result\Redirect::class)
->disableOriginalConstructor()
->getMock();
$resultFactory = $this->getMockBuilder(\Magento\Framework\Controller\ResultFactory::class)
Expand All @@ -41,47 +83,71 @@ protected function setUp()
$resultFactory->expects($this->atLeastOnce())
->method('create')
->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT)
->willReturn($this->resultRedirect);
->willReturn($this->resultRedirectMock);

$abstractDbMock = $this->getMockBuilder(\Magento\Framework\Data\Collection\AbstractDb::class)
$this->abstractDbMock = $this->getMockBuilder(AbstractDb::class)
->disableOriginalConstructor()
->setMethods(['getAllIds', 'getResource'])
->getMock();
$abstractDbMock->expects($this->any())
->method('getAllIds')
->willReturn([]);

$filterMock = $this->getMockBuilder(\Magento\Ui\Component\MassAction\Filter::class)
$this->filterMock = $this->getMockBuilder(\Magento\Ui\Component\MassAction\Filter::class)
->disableOriginalConstructor()
->setMethods(['getCollection'])
->getMock();
$filterMock->expects($this->any())
->method('getCollection')
->willReturn($abstractDbMock);

$collectionFactoryMock = $this->getMockBuilder(
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class
)
$this->actionMock = $this->getMockBuilder(Action::class)
->disableOriginalConstructor()
->getMock();

$collectionFactoryMock =
$this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
$collectionFactoryMock->expects($this->any())
->method('create')
->willReturn($abstractDbMock);
->willReturn($this->abstractDbMock);

$additionalParams = [
'resultFactory' => $resultFactory
];
/** @var \Magento\Backend\App\Action\Context $context */
$context = $this->initContext($additionalParams, [[Action::class, $this->actionMock]]);

$additionalParams = ['resultFactory' => $resultFactory];
$this->action = new \Magento\Catalog\Controller\Adminhtml\Product\MassStatus(
$this->initContext($additionalParams),
$productBuilder,
$this->priceProcessor,
$filterMock,
$context,
$this->productBuilderMock,
$this->priceProcessorMock,
$this->filterMock,
$collectionFactoryMock
);
}

public function testMassStatusAction()
{
$this->priceProcessor->expects($this->once())->method('reindexList');
$storeId = 1;
$status = \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED;
$filters = [
'store_id' => 2,
];

$this->filterMock->expects($this->once())
->method('getCollection')
->willReturn($this->abstractDbMock);
$this->abstractDbMock->expects($this->once())
->method('getAllIds')
->willReturn([3]);
$this->request->expects($this->exactly(3))
->method('getParam')
->willReturnMap([
['store', 0, $storeId],
['status', null, $status],
['filters', [], $filters]
]);
$this->actionMock->expects($this->once())
->method('updateAttributes')
->with([3], ['status' => $status], 2);
$this->priceProcessorMock->expects($this->once())
->method('reindexList');

$this->action->execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Catalog\Test\Unit\Controller\Adminhtml;

use Magento\Catalog\Api\Data\ProductInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
Expand All @@ -25,17 +27,33 @@ abstract class ProductTest extends \PHPUnit_Framework_TestCase
/** @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject */
protected $request;

/**
* @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $objectManagerMock;

/**
* Init context object
*
* @param array $additionalParams
* @param array $objectManagerMap Object Manager mappings
* @return \PHPUnit_Framework_MockObject_MockObject
*/
protected function initContext(array $additionalParams = [])
protected function initContext(array $additionalParams = [], array $objectManagerMap = [])
{
$productActionMock = $this->getMock(\Magento\Catalog\Model\Product\Action::class, [], [], '', false);
$objectManagerMock = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class);
$objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($productActionMock));

$this->objectManagerMock = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class);

if ($objectManagerMap) {
$this->objectManagerMock->expects($this->any())
->method('get')
->willReturnMap($objectManagerMap);
}

$this->objectManagerMock->expects($this->any())
->method('get')
->willReturn($productActionMock);

$block = $this->getMockBuilder(\Magento\Framework\View\Element\AbstractBlock::class)
->disableOriginalConstructor()->getMockForAbstractClass();
Expand Down Expand Up @@ -93,7 +111,7 @@ protected function initContext(array $additionalParams = [])
$this->context->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager));
$this->context->expects($this->any())->method('getRequest')->will($this->returnValue($requestInterfaceMock));
$this->context->expects($this->any())->method('getResponse')->will($this->returnValue($responseInterfaceMock));
$this->context->expects($this->any())->method('getObjectManager')->will($this->returnValue($objectManagerMock));
$this->context->expects($this->any())->method('getObjectManager')->willReturn($this->objectManagerMock);

$this->context->expects($this->any())->method('getMessageManager')
->will($this->returnValue($managerInterfaceMock));
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Ui/view/base/web/js/grid/data-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ define([
getData: function (params, options) {
var cachedRequest = this.getRequest(params);

if (params && params.filters && params.filters['store_id']) {
cachedRequest = false;
}

options = options || {};

return !options.refresh && cachedRequest ?
Expand Down

0 comments on commit d8eac00

Please sign in to comment.