Skip to content

Commit

Permalink
Merge pull request #518 from magento-fearless-kiwis/FearlessKiwis-MAG…
Browse files Browse the repository at this point in the history
…ETWO-59284-New

Fixed issue:
- MAGETWO-59284: There is no Scope Selector on Product Grid
  • Loading branch information
MomotenkoNatalia authored Oct 19, 2016
2 parents 606b04d + 5a20ba7 commit 05619f7
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ class MassStatus extends \Magento\Catalog\Controller\Adminhtml\Product
/**
* MassActions filter
*
* @var Filter
* @var \Magento\Ui\Component\MassAction\Filter
*/
protected $filter;

/**
* @var CollectionFactory
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
*/
protected $collectionFactory;

/**
* @param Action\Context $context
* @param Builder $productBuilder
* @param \Magento\Catalog\Model\Indexer\Product\Price\Processor $productPriceIndexerProcessor
* @param Filter $filter
* @param CollectionFactory $collectionFactory
* @param \Magento\Ui\Component\MassAction\Filter $filter
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
Expand Down Expand Up @@ -81,6 +81,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,80 +6,165 @@
*/
namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Product;

class MassStatusTest extends \Magento\Catalog\Test\Unit\Controller\Adminhtml\ProductTest
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
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;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Catalog\Controller\Adminhtml\Product\MassStatus;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\App\Request\Http;
use Magento\Catalog\Model\Product;
use Magento\Framework\ObjectManager\ObjectManager as Manager;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class MassStatusTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $priceProcessor;
private $priceProcessorMock;

/**
* @var \Magento\Catalog\Controller\Adminhtml\Product\MassStatus
*/
private $action;

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

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

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $requestMock;

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

protected function setUp()
{
$this->priceProcessor = $this->getMockBuilder('Magento\Catalog\Model\Indexer\Product\Price\Processor')
$objectManagerMock = $this->getMockBuilder(Manager::class)
->disableOriginalConstructor()
->getMock();

$objectManagerHelper = new ObjectManager($this);
$this->priceProcessorMock = $this->getMockBuilder(Processor::class)
->disableOriginalConstructor()->getMock();

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

$product = $this->getMockBuilder('\Magento\Catalog\Model\Product')->disableOriginalConstructor()
$this->requestMock = $this->getMockBuilder(Http::class)->setMethods(
['getParam', 'getPost', 'getFullActionName', 'getPostValue']
)->disableOriginalConstructor()->getMock();

$productMock = $this->getMockBuilder(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->expects($this->any())->method('getTypeId')->will($this->returnValue('simple'));
$productMock->expects($this->any())->method('getStoreId')->will($this->returnValue('1'));
$productBuilderMock->expects($this->any())->method('build')->will($this->returnValue($productMock));

$this->resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect')
$resultRedirectMock = $this->getMockBuilder(Redirect::class)
->disableOriginalConstructor()
->getMock();
$resultFactory = $this->getMockBuilder('Magento\Framework\Controller\ResultFactory')
$resultFactory = $this->getMockBuilder(ResultFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
$resultFactory->expects($this->atLeastOnce())
->method('create')
->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT)
->willReturn($this->resultRedirect);
->with(ResultFactory::TYPE_REDIRECT)
->willReturn($resultRedirectMock);

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

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

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

$additionalParams = ['resultFactory' => $resultFactory];
$this->action = new \Magento\Catalog\Controller\Adminhtml\Product\MassStatus(
$this->initContext($additionalParams),
$productBuilder,
$this->priceProcessor,
$filterMock,
$collectionFactoryMock
->willReturn($this->abstractDbMock);
$this->requestMock = $this->getMockBuilder(Http::class)->setMethods(
['getParam', 'getPost', 'getFullActionName', 'getPostValue']
)->disableOriginalConstructor()->getMock();

$this->action = $objectManagerHelper->getObject(
MassStatus::class,
[
'objectManager' => $objectManagerMock,
'request' => $this->requestMock,
'productBuilder' => $productBuilderMock,
'filter' => $this->filterMock,
'productPriceIndexerProcessor' => $this->priceProcessorMock,
'collectionFactory' => $collectionFactoryMock,
'resultFactory' => $resultFactory
]
);

}

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

$productIds = [3];

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

$this->action->execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ abstract class ProductTest extends \PHPUnit_Framework_TestCase
{
/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $context;

/** @var \Magento\Catalog\Controller\Product */
protected $action;

/** @var \Magento\Framework\View\Layout */
protected $layout;

/** @var \Magento\Backend\Model\Session|\PHPUnit_Framework_MockObject_MockObject */
protected $session;

/** @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject */
protected $request;

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 05619f7

Please sign in to comment.