Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:magento/magento2ce into pr-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
andimov committed Oct 10, 2016
2 parents cba3a76 + 492f0ca commit 8dbc880
Show file tree
Hide file tree
Showing 123 changed files with 1,760 additions and 206 deletions.
3 changes: 3 additions & 0 deletions app/code/Magento/Backend/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<template>
<minify_html>0</minify_html>
</template>
<static>
<sign>1</sign>
</static>
</dev>
<system>
<media_storage_configuration>
Expand Down
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
23 changes: 21 additions & 2 deletions app/code/Magento/CatalogImportExport/Model/Export/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ protected function collectRawData()
if (is_scalar($attrValue)) {
if (!in_array($fieldName, $this->_getExportMainAttrCodes())) {
$additionalAttributes[$fieldName] = $fieldName .
ImportProduct::PAIR_NAME_VALUE_SEPARATOR . $attrValue;
ImportProduct::PAIR_NAME_VALUE_SEPARATOR . $this->wrapValue($attrValue);
}
$data[$itemId][$storeId][$fieldName] = htmlspecialchars_decode($attrValue);
}
Expand All @@ -963,7 +963,7 @@ protected function collectRawData()
$additionalAttributes[$code] = $fieldName .
ImportProduct::PAIR_NAME_VALUE_SEPARATOR . implode(
ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR,
$this->collectedMultiselectsData[$storeId][$productLinkId][$code]
$this->wrapValue($this->collectedMultiselectsData[$storeId][$productLinkId][$code])
);
}
}
Expand Down Expand Up @@ -994,6 +994,25 @@ protected function collectRawData()
return $data;
}

/**
* Wrap values with double quotes if "Fields Enclosure" option is enabled
*
* @param string|array $value
* @return string|array
*/
private function wrapValue($value)
{
if (!empty($this->_parameters[\Magento\ImportExport\Model\Export::FIELDS_ENCLOSURE])) {
$wrap = function ($value) {
return sprintf('"%s"', str_replace('"', '""', $value));
};

$value = is_array($value) ? array_map($wrap, $value) : $wrap($value);
}

return $value;
}

/**
* @return array
*/
Expand Down
Loading

0 comments on commit 8dbc880

Please sign in to comment.