Skip to content

Commit 871f524

Browse files
author
Dmytro Voskoboinikov
committed
Merge branch '2.2-develop' into 2.2.6-develop
2 parents 952eb86 + 0383b22 commit 871f524

File tree

179 files changed

+3618
-525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+3618
-525
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Category/RefreshPath.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ public function execute()
3838

3939
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
4040
$resultJson = $this->resultJsonFactory->create();
41-
return $resultJson->setData(['id' => $categoryId, 'path' => $category->getPath()]);
41+
return $resultJson->setData([
42+
'id' => $categoryId,
43+
'path' => $category->getPath(),
44+
'parentId' => $category->getParentId(),
45+
]);
4246
}
4347
}
4448
}

app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ public function execute()
138138
$parentId = isset($categoryPostData['parent']) ? $categoryPostData['parent'] : null;
139139
if ($categoryPostData) {
140140
$category->addData($categoryPostData);
141+
if ($parentId) {
142+
$category->setParentId($parentId);
143+
}
141144
if ($isNewCategory) {
142145
$parentCategory = $this->getParentCategory($parentId, $storeId);
143146
$category->setPath($parentCategory->getPath());

app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Save.php

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
*/
77
namespace Magento\Catalog\Controller\Adminhtml\Product\Set;
88

9+
use Magento\Framework\App\ObjectManager;
10+
11+
/**
12+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
13+
*/
914
class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Set
1015
{
1116
/**
@@ -17,22 +22,49 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Set
1722
* @var \Magento\Framework\Controller\Result\JsonFactory
1823
*/
1924
protected $resultJsonFactory;
20-
25+
26+
/*
27+
* @var \Magento\Eav\Model\Entity\Attribute\SetFactory
28+
*/
29+
private $attributeSetFactory;
30+
31+
/*
32+
* @var \Magento\Framework\Filter\FilterManager
33+
*/
34+
private $filterManager;
35+
36+
/*
37+
* @var \Magento\Framework\Json\Helper\Data
38+
*/
39+
private $jsonHelper;
40+
2141
/**
2242
* @param \Magento\Backend\App\Action\Context $context
2343
* @param \Magento\Framework\Registry $coreRegistry
2444
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
2545
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
46+
* @param \Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory
47+
* @param \Magento\Framework\Filter\FilterManager $filterManager
48+
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
2649
*/
2750
public function __construct(
2851
\Magento\Backend\App\Action\Context $context,
2952
\Magento\Framework\Registry $coreRegistry,
3053
\Magento\Framework\View\LayoutFactory $layoutFactory,
31-
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
54+
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
55+
\Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory = null,
56+
\Magento\Framework\Filter\FilterManager $filterManager = null,
57+
\Magento\Framework\Json\Helper\Data $jsonHelper = null
3258
) {
3359
parent::__construct($context, $coreRegistry);
3460
$this->layoutFactory = $layoutFactory;
3561
$this->resultJsonFactory = $resultJsonFactory;
62+
$this->attributeSetFactory = $attributeSetFactory ?: ObjectManager::getInstance()
63+
->get(\Magento\Eav\Model\Entity\Attribute\SetFactory::class);
64+
$this->filterManager = $filterManager ?: ObjectManager::getInstance()
65+
->get(\Magento\Framework\Filter\FilterManager::class);
66+
$this->jsonHelper = $jsonHelper ?: ObjectManager::getInstance()
67+
->get(\Magento\Framework\Json\Helper\Data::class);
3668
}
3769

3870
/**
@@ -65,16 +97,12 @@ public function execute()
6597
$isNewSet = $this->getRequest()->getParam('gotoEdit', false) == '1';
6698

6799
/* @var $model \Magento\Eav\Model\Entity\Attribute\Set */
68-
$model = $this->_objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class)
69-
->setEntityTypeId($entityTypeId);
70-
71-
/** @var $filterManager \Magento\Framework\Filter\FilterManager */
72-
$filterManager = $this->_objectManager->get(\Magento\Framework\Filter\FilterManager::class);
100+
$model = $this->attributeSetFactory->create()->setEntityTypeId($entityTypeId);
73101

74102
try {
75103
if ($isNewSet) {
76104
//filter html tags
77-
$name = $filterManager->stripTags($this->getRequest()->getParam('attribute_set_name'));
105+
$name = $this->filterManager->stripTags($this->getRequest()->getParam('attribute_set_name'));
78106
$model->setAttributeSetName(trim($name));
79107
} else {
80108
if ($attributeSetId) {
@@ -85,11 +113,10 @@ public function execute()
85113
__('This attribute set no longer exists.')
86114
);
87115
}
88-
$data = $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)
89-
->jsonDecode($this->getRequest()->getPost('data'));
116+
$data = $this->jsonHelper->jsonDecode($this->getRequest()->getPost('data'));
90117

91118
//filter html tags
92-
$data['attribute_set_name'] = $filterManager->stripTags($data['attribute_set_name']);
119+
$data['attribute_set_name'] = $this->filterManager->stripTags($data['attribute_set_name']);
93120

94121
$model->organizeData($data);
95122
}

app/code/Magento/Catalog/Model/ResourceModel/Attribute.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,13 @@ public function deleteEntity(\Magento\Framework\Model\AbstractModel $object)
141141
->getMetadata(ProductInterface::class)
142142
->getLinkField();
143143

144+
$backendLinkField = $attribute->getBackend()->getEntityIdField();
145+
144146
$select = $this->getConnection()->select()
145147
->from(['b' => $backendTable])
146148
->join(
147149
['e' => $attribute->getEntity()->getEntityTable()],
148-
"b.$linkField = e.$linkField"
150+
"b.$backendLinkField = e.$linkField"
149151
)->where('b.attribute_id = ?', $attribute->getId())
150152
->where('e.attribute_set_id = ?', $result['attribute_set_id']);
151153

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Category;
10+
11+
use Magento\Framework\Controller\Result\JsonFactory;
12+
use Magento\Catalog\Controller\Adminhtml\Category\RefreshPath;
13+
use Magento\Backend\App\Action\Context;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
15+
16+
/**
17+
* Test for class RefreshPath.
18+
*/
19+
class RefreshPathTest extends \PHPUnit\Framework\TestCase
20+
{
21+
/**
22+
* @var JsonFactory|\PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
private $resultJsonFactoryMock;
25+
26+
/**
27+
* @var Context|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
private $contextMock;
30+
31+
/**
32+
* {@inheritDoc}
33+
*/
34+
protected function setUp()
35+
{
36+
$this->resultJsonFactoryMock = $this->getMockBuilder(JsonFactory::class)
37+
->disableOriginalConstructor()
38+
->setMethods(['create', 'setData'])
39+
->getMock();
40+
41+
$this->contextMock = $this->getMockBuilder(Context::class)
42+
->disableOriginalConstructor()
43+
->setMethods(['getRequest'])
44+
->getMock();
45+
}
46+
47+
/**
48+
* Sets object non-public property.
49+
*
50+
* @param mixed $object
51+
* @param string $propertyName
52+
* @param mixed $value
53+
*
54+
* @return void
55+
*/
56+
private function setObjectProperty($object, string $propertyName, $value)
57+
{
58+
$reflectionClass = new \ReflectionClass($object);
59+
$reflectionProperty = $reflectionClass->getProperty($propertyName);
60+
$reflectionProperty->setAccessible(true);
61+
$reflectionProperty->setValue($object, $value);
62+
}
63+
64+
/**
65+
* @return void
66+
*/
67+
public function testExecute()
68+
{
69+
$value = ['id' => 3, 'path' => '1/2/3', 'parentId' => 2];
70+
$result = '{"id":3,"path":"1/2/3","parentId":"2"}';
71+
72+
$requestMock = $this->getMockForAbstractClass(\Magento\Framework\App\RequestInterface::class);
73+
74+
$refreshPath = $this->getMockBuilder(RefreshPath::class)
75+
->setMethods(['getRequest', 'create'])
76+
->setConstructorArgs([
77+
$this->contextMock,
78+
$this->resultJsonFactoryMock,
79+
])->getMock();
80+
81+
$refreshPath->expects($this->any())->method('getRequest')->willReturn($requestMock);
82+
$requestMock->expects($this->any())->method('getParam')->with('id')->willReturn($value['id']);
83+
84+
$categoryMock = $this->getMockBuilder(\Magento\Catalog\Model\Category::class)
85+
->disableOriginalConstructor()
86+
->setMethods(['getPath', 'getParentId', 'getResource'])
87+
->getMock();
88+
89+
$categoryMock->expects($this->any())->method('getPath')->willReturn($value['path']);
90+
$categoryMock->expects($this->any())->method('getParentId')->willReturn($value['parentId']);
91+
92+
$categoryResource = $this->createMock(\Magento\Catalog\Model\ResourceModel\Category::class);
93+
94+
$objectManagerMock = $this->getMockBuilder(ObjectManager::class)
95+
->disableOriginalConstructor()
96+
->setMethods(['create'])
97+
->getMock();
98+
99+
$this->setObjectProperty($refreshPath, '_objectManager', $objectManagerMock);
100+
$this->setObjectProperty($categoryMock, '_resource', $categoryResource);
101+
102+
$objectManagerMock->expects($this->once())
103+
->method('create')
104+
->with(\Magento\Catalog\Model\Category::class)
105+
->willReturn($categoryMock);
106+
107+
$this->resultJsonFactoryMock->expects($this->any())->method('create')->willReturnSelf();
108+
$this->resultJsonFactoryMock->expects($this->any())
109+
->method('setData')
110+
->with($value)
111+
->willReturn($result);
112+
113+
$this->assertEquals($result, $refreshPath->execute());
114+
}
115+
116+
/**
117+
* @return void
118+
*/
119+
public function testExecuteWithoutCategoryId()
120+
{
121+
$requestMock = $this->getMockForAbstractClass(\Magento\Framework\App\RequestInterface::class);
122+
123+
$refreshPath = $this->getMockBuilder(RefreshPath::class)
124+
->setMethods(['getRequest', 'create'])
125+
->setConstructorArgs([
126+
$this->contextMock,
127+
$this->resultJsonFactoryMock,
128+
])->getMock();
129+
130+
$refreshPath->expects($this->any())->method('getRequest')->willReturn($requestMock);
131+
$requestMock->expects($this->any())->method('getParam')->with('id')->willReturn(null);
132+
133+
$objectManagerMock = $this->getMockBuilder(ObjectManager::class)
134+
->disableOriginalConstructor()
135+
->setMethods(['create'])
136+
->getMock();
137+
138+
$this->setObjectProperty($refreshPath, '_objectManager', $objectManagerMock);
139+
140+
$objectManagerMock->expects($this->never())
141+
->method('create')
142+
->with(\Magento\Catalog\Model\Category::class)
143+
->willReturnSelf();
144+
145+
$refreshPath->execute();
146+
}
147+
}

0 commit comments

Comments
 (0)