Skip to content

Commit

Permalink
Merge pull request #2074 from magento-tsg/2.1-develop-pr45
Browse files Browse the repository at this point in the history
[TSG] Backporting for 2.1 (pr45) (2.1.13)
  • Loading branch information
Alexander Akimov authored Feb 12, 2018
2 parents c1b7710 + d90888d commit bbb6f9a
Show file tree
Hide file tree
Showing 21 changed files with 822 additions and 376 deletions.
7 changes: 4 additions & 3 deletions app/code/Magento/Catalog/Model/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ private function processLinks(\Magento\Catalog\Api\Data\ProductInterface $produc
$linksToInitialize = [];
foreach ($linksByType as $link) {
$linkDataArray = $this->extensibleDataObjectConverter
->toNestedArray($link, [], 'Magento\Catalog\Api\Data\ProductLinkInterface');
->toNestedArray($link, [], \Magento\Catalog\Api\Data\ProductLinkInterface::class);
$linkedSku = $link->getLinkedProductSku();
if (!isset($linkedProductIds[$linkedSku])) {
throw new NoSuchEntityException(
Expand Down Expand Up @@ -518,7 +518,7 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
}

$productDataArray = $this->extensibleDataObjectConverter
->toNestedArray($product, [], 'Magento\Catalog\Api\Data\ProductInterface');
->toNestedArray($product, [], \Magento\Catalog\Api\Data\ProductInterface::class);
$productDataArray = array_replace($productDataArray, $product->getData());
$ignoreLinksFlag = $product->getData('ignore_links_flag');
$productLinks = null;
Expand Down Expand Up @@ -631,6 +631,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
$collection->setCurPage($searchCriteria->getCurrentPage());
$collection->setPageSize($searchCriteria->getPageSize());
$collection->load();
$collection->addCategoryIds();

$searchResult = $this->searchResultsFactory->create();
$searchResult->setSearchCriteria($searchCriteria);
Expand Down Expand Up @@ -717,7 +718,7 @@ private function getMediaGalleryProcessor()
{
if (null === $this->mediaGalleryProcessor) {
$this->mediaGalleryProcessor = \Magento\Framework\App\ObjectManager::getInstance()
->get('Magento\Catalog\Model\Product\Gallery\Processor');
->get(\Magento\Catalog\Model\Product\Gallery\Processor::class);
}
return $this->mediaGalleryProcessor;
}
Expand Down
167 changes: 95 additions & 72 deletions app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

namespace Magento\Catalog\Test\Unit\Model;

use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Catalog\Api\Data\ProductAttributeSearchResultsInterface;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Framework\Api\Data\ImageContentInterface;
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
use Magento\Framework\Api\SortOrder;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

Expand Down Expand Up @@ -153,6 +157,11 @@ class ProductRepositoryTest extends \PHPUnit_Framework_TestCase
*/
private $optionConverterMock;

/**
* @var JoinProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $extensionAttributesJoinProcessor;

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
Expand Down Expand Up @@ -322,6 +331,9 @@ protected function setUp()
$this->optionConverterMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Converter::class)
->disableOriginalConstructor()
->getMock();
$this->extensionAttributesJoinProcessor = $this->getMockBuilder(JoinProcessorInterface::class)
->disableOriginalConstructor()
->getMock();

$this->model = $this->objectManager->getObject(
\Magento\Catalog\Model\ProductRepository::class,
Expand All @@ -347,6 +359,7 @@ protected function setUp()
'imageProcessor' => $this->imageProcessorMock,
'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessorMock,
'mediaGalleryProcessor' => $this->mediaGalleryProcessor,
'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessor,
]
);
}
Expand Down Expand Up @@ -671,85 +684,95 @@ public function testDeleteById()
*/
public function testGetList($fieldName)
{
$searchCriteriaMock = $this->getMock(\Magento\Framework\Api\SearchCriteriaInterface::class, [], [], '', false);
$attributeCode = 'attribute_code';
$collectionMock = $this->getMock(
\Magento\Catalog\Model\ResourceModel\Product\Collection::class,
[],
[],
'',
false
);
$extendedSearchCriteriaMock = $this->getMock(\Magento\Framework\Api\SearchCriteria::class, [], [], '', false);
$productAttributeSearchResultsMock = $this->getMock(
\Magento\Framework\Api\SearchResults::class,
[],
[],
'',
false
);
$productAttributeMock = $this->getMock(
\Magento\Catalog\Api\Data\ProductAttributeInterface::class,
[],
[],
'',
false
);
$filterGroupMock = $this->getMock(\Magento\Framework\Api\Search\FilterGroup::class, [], [], '', false);
$filterGroupFilterMock = $this->getMock(\Magento\Framework\Api\Filter::class, [], [], '', false);
$sortOrderMock = $this->getMock(\Magento\Framework\Api\SortOrder::class, [], [], '', false);
$itemsMock = $this->getMock(\Magento\Framework\DataObject::class, [], [], '', false);

$this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock);
$this->searchCriteriaBuilderMock
->expects($this->once())
->method('create')
->willReturn($extendedSearchCriteriaMock);
$this->metadataServiceMock
->expects($this->once())
->method('getList')
->with($extendedSearchCriteriaMock)
->willReturn($productAttributeSearchResultsMock);
$productAttributeSearchResultsMock->expects($this->once())
->method('getItems')
->willReturn([$productAttributeMock]);
$productAttributeMock->expects($this->once())->method('getAttributeCode')->willReturn($attributeCode);
$collectionMock->expects($this->once())->method('addAttributeToSelect')->with($attributeCode);
$collectionMock->expects($this->exactly(2))
->method('joinAttribute')
$filterGroupFilterMock = $this->getMockBuilder(\Magento\Framework\Api\Filter::class)
->disableOriginalConstructor()
->getMock();
$filterGroupFilterMock->expects(self::exactly(2))->method('getConditionType')->willReturn('eq');
$filterGroupFilterMock->expects(self::atLeastOnce())->method('getField')->willReturn($fieldName);
$filterGroupFilterMock->expects(self::once())->method('getValue')->willReturn('value');

$filterGroupMock = $this->getMockBuilder(\Magento\Framework\Api\Search\FilterGroup::class)
->disableOriginalConstructor()
->getMock();
$filterGroupMock->expects(self::once())->method('getFilters')->willReturn([$filterGroupFilterMock]);

$sortOrderMock = $this->getMockBuilder(\Magento\Framework\Api\SortOrder::class)
->disableOriginalConstructor()
->getMock();
$sortOrderMock->expects(self::atLeastOnce())->method('getField')->willReturn($fieldName);
$sortOrderMock->expects(self::once())->method('getDirection')->willReturn(SortOrder::SORT_ASC);

/** @var \Magento\Framework\Api\SearchCriteriaInterface|\PHPUnit_Framework_MockObject_MockObject $searchCriteriaMock */
$searchCriteriaMock = $this->getMockBuilder(\Magento\Framework\Api\SearchCriteriaInterface::class)
->disableOriginalConstructor()
->getMock();
$searchCriteriaMock->expects(self::once())->method('getFilterGroups')->willReturn([$filterGroupMock]);
$searchCriteriaMock->expects(self::once())->method('getCurrentPage')->willReturn(4);
$searchCriteriaMock->expects(self::once())->method('getPageSize')->willReturn(42);
$searchCriteriaMock->expects(self::once())->method('getSortOrders')->willReturn([$sortOrderMock]);

$itemsMock = $this->getMockBuilder(\Magento\Framework\DataObject::class)
->disableOriginalConstructor()
->getMock();

$collectionMock = $this->getMockBuilder(Collection::class)
->disableOriginalConstructor()
->getMock();
$collectionMock->expects(self::once())->method('addAttributeToSelect')->with($attributeCode);
$collectionMock->expects(self::once())->method('setPageSize')->with(42);
$collectionMock->expects(self::once())->method('load');
$collectionMock->expects(self::once())->method('addCategoryIds');
$collectionMock->expects(self::once())->method('getItems')->willReturn([$itemsMock]);
$collectionMock->expects(self::once())->method('getSize')->willReturn(128);
$collectionMock->expects(self::once())->method('addOrder')->with($fieldName, 'ASC');
$collectionMock->expects(self::once())->method('setCurPage')->with(4);
$collectionMock->expects(self::exactly(2))->method('joinAttribute')
->withConsecutive(
['status', 'catalog_product/status', 'entity_id', null, 'inner'],
['visibility', 'catalog_product/visibility', 'entity_id', null, 'inner']
);
$searchCriteriaMock->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroupMock]);
$filterGroupMock->expects($this->once())->method('getFilters')->willReturn([$filterGroupFilterMock]);
$filterGroupFilterMock->expects($this->exactly(2))->method('getConditionType')->willReturn('eq');
$filterGroupFilterMock->expects($this->atLeastOnce())->method('getField')->willReturn($fieldName);
$filterGroupFilterMock->expects($this->once())->method('getValue')->willReturn('value');
);

$productAttributeMock = $this->getMockBuilder(ProductAttributeInterface::class)
->disableOriginalConstructor()
->getMock();
$productAttributeMock->expects(self::once())->method('getAttributeCode')->willReturn($attributeCode);

$extendedSearchCriteriaMock = $this->getMockBuilder(\Magento\Framework\Api\SearchCriteria::class)
->disableOriginalConstructor()
->getMock();

$productAttributeSearchResultsMock = $this->getMockBuilder(ProductAttributeSearchResultsInterface::class)
->disableOriginalConstructor()
->setMethods(['getItems'])
->getMockForAbstractClass();
$productAttributeSearchResultsMock->expects(self::once())->method('getItems')
->willReturn([$productAttributeMock]);

$this->collectionFactoryMock->expects(self::once())
->method('create')
->willReturn($collectionMock);

$this->extensionAttributesJoinProcessor->expects(self::once())
->method('process')
->with($collectionMock);

$this->metadataServiceMock->expects(self::once())->method('getList')->with($extendedSearchCriteriaMock)
->willReturn($productAttributeSearchResultsMock);

$this->searchCriteriaBuilderMock->expects(self::once())->method('create')
->willReturn($extendedSearchCriteriaMock);

$this->expectAddToFilter($fieldName, $collectionMock);
$searchCriteriaMock->expects($this->once())->method('getSortOrders')->willReturn([$sortOrderMock]);
$sortOrderMock->expects($this->atLeastOnce())->method('getField')->willReturn($fieldName);
$sortOrderMock->expects($this->once())->method('getDirection')->willReturn(SortOrder::SORT_ASC);
$collectionMock->expects($this->once())->method('addOrder')->with($fieldName, 'ASC');
$searchCriteriaMock->expects($this->once())->method('getCurrentPage')->willReturn(4);
$collectionMock->expects($this->once())->method('setCurPage')->with(4);
$searchCriteriaMock->expects($this->once())->method('getPageSize')->willReturn(42);
$collectionMock->expects($this->once())->method('setPageSize')->with(42);
$collectionMock->expects($this->once())->method('load');
$collectionMock->expects($this->once())->method('getItems')->willReturn([$itemsMock]);
$collectionMock->expects($this->once())->method('getSize')->willReturn(128);
$searchResultsMock = $this->getMock(
\Magento\Catalog\Api\Data\ProductSearchResultsInterface::class,
[],
[],
'',
false
);
$searchResultsMock->expects($this->once())->method('setSearchCriteria')->with($searchCriteriaMock);
$searchResultsMock->expects($this->once())->method('setItems')->with([$itemsMock]);
$searchResultsMock->expects($this->once())->method('setTotalCount')->with(128);
$this->searchResultsFactoryMock->expects($this->once())->method('create')->willReturn($searchResultsMock);

$searchResultsMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductSearchResultsInterface::class)
->disableOriginalConstructor()
->getMock();
$searchResultsMock->expects(self::once())->method('setSearchCriteria')->with($searchCriteriaMock);
$searchResultsMock->expects(self::once())->method('setItems')->with([$itemsMock]);

$this->searchResultsFactoryMock->expects($this->once())->method('create')->willReturn($searchResultsMock);
$this->assertEquals($searchResultsMock, $this->model->getList($searchCriteriaMock));
}

Expand Down
16 changes: 14 additions & 2 deletions app/code/Magento/Catalog/view/adminhtml/web/catalog/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,27 @@ require([
}

function disableFieldEditMode(fieldId) {
byId(fieldId).prop('disabled', true);
var field = byId(fieldId);

field.prop('disabled', true);

if (field.next().hasClass('addafter')) {
field.parent().addClass('_update-attributes-disabled');
}

if (byId(fieldId + '_hidden').length) {
byId(fieldId + '_hidden').prop('disabled', true);
}
}

function enableFieldEditMode(fieldId) {
byId(fieldId).prop('disabled', false);
var field = byId(fieldId);

field.prop('disabled', false);

if (field.parent().hasClass('_update-attributes-disabled')) {
field.parent().removeClass('_update-attributes-disabled');
}

if (byId(fieldId + '_hidden').length) {
byId(fieldId + '_hidden').prop('disabled', false);
Expand Down
14 changes: 12 additions & 2 deletions app/code/Magento/Cms/Controller/Adminhtml/Page/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,32 @@ class Save extends \Magento\Backend\App\Action
*/
private $pageFactory;

/**
* @var \Magento\Cms\Api\PageRepositoryInterface
*/
private $pageRepository;

/**
* @param Action\Context $context
* @param PostDataProcessor $dataProcessor
* @param DataPersistorInterface $dataPersistor
* @param \Magento\Cms\Model\PageFactory $pageFactory
* @param \Magento\Cms\Api\PageRepositoryInterface $pageRepository
*/
public function __construct(
Action\Context $context,
PostDataProcessor $dataProcessor,
DataPersistorInterface $dataPersistor,
\Magento\Cms\Model\PageFactory $pageFactory = null
\Magento\Cms\Model\PageFactory $pageFactory = null,
\Magento\Cms\Api\PageRepositoryInterface $pageRepository = null
) {
$this->dataProcessor = $dataProcessor;
$this->dataPersistor = $dataPersistor;
$this->pageFactory = $pageFactory
?: \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Cms\Model\PageFactory::class);
$this->pageRepository = $pageRepository
?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Cms\Api\PageRepositoryInterface::class);

parent::__construct($context);
}
Expand Down Expand Up @@ -102,7 +112,7 @@ public function execute()
}

try {
$model->save();
$this->pageRepository->save($model);
$this->messageManager->addSuccess(__('You saved the page.'));
$this->dataPersistor->clear('cms_page');
if ($this->getRequest()->getParam('back')) {
Expand Down
Loading

0 comments on commit bbb6f9a

Please sign in to comment.