Skip to content

Commit 89af9a4

Browse files
author
Oleksandr Iegorov
committed
Merge branch '2.2-develop' of github.com:magento/magento2ce into MAGETWO-92611
2 parents e7ebf15 + 178a97d commit 89af9a4

File tree

76 files changed

+2894
-318
lines changed

Some content is hidden

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

76 files changed

+2894
-318
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/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)