Skip to content

Commit 591c46a

Browse files
committed
Merge remote-tracking branch 'magento-ce/develop' into SPRINT-21-PR-sq
2 parents 2e55457 + 8ee63a1 commit 591c46a

File tree

14 files changed

+727
-89
lines changed

14 files changed

+727
-89
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/AddAttributeToTemplate.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Magento\Eav\Api\Data\AttributeInterface;
1717
use Magento\Eav\Api\Data\AttributeSetInterface;
1818
use Magento\Framework\Api\SearchCriteriaBuilder;
19-
use Magento\Framework\Api\SortOrderBuilder;
2019
use Magento\Framework\Exception\LocalizedException;
2120
use Psr\Log\LoggerInterface;
2221
use Magento\Framework\Api\ExtensionAttributesFactory;
@@ -53,11 +52,6 @@ class AddAttributeToTemplate extends \Magento\Catalog\Controller\Adminhtml\Produ
5352
*/
5453
protected $searchCriteriaBuilder;
5554

56-
/**
57-
* @var SortOrderBuilder
58-
*/
59-
protected $sortOrderBuilder;
60-
6155
/**
6256
* @var AttributeGroupInterfaceFactory
6357
*/
@@ -115,7 +109,6 @@ public function execute()
115109
$attributeGroupSearchCriteria = $this->getSearchCriteriaBuilder()
116110
->addFilter('attribute_set_id', $attributeSet->getAttributeSetId())
117111
->addFilter('attribute_group_code', $groupCode)
118-
->addSortOrder($this->getSortOrderBuilder()->setAscendingDirection()->create())
119112
->setPageSize(1)
120113
->create();
121114

@@ -252,18 +245,6 @@ private function getSearchCriteriaBuilder()
252245
return $this->searchCriteriaBuilder;
253246
}
254247

255-
/**
256-
* @return SortOrderBuilder
257-
*/
258-
private function getSortOrderBuilder()
259-
{
260-
if (null === $this->sortOrderBuilder) {
261-
$this->sortOrderBuilder = \Magento\Framework\App\ObjectManager::getInstance()
262-
->get(\Magento\Framework\Api\SortOrderBuilder::class);
263-
}
264-
return $this->sortOrderBuilder;
265-
}
266-
267248
/**
268249
* @return AttributeManagementInterface
269250
*/

app/code/Magento/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/Suffix.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class Suffix extends \Magento\Framework\App\Config\Value
4040
*/
4141
protected $resource;
4242

43+
/**
44+
* @var \Magento\Framework\App\Config\ScopePool
45+
*/
46+
private $scopePool;
47+
4348
/**
4449
* @param \Magento\Framework\Model\Context $context
4550
* @param \Magento\Framework\Registry $registry
@@ -75,6 +80,22 @@ public function __construct(
7580
$this->resource = $appResource;
7681
}
7782

83+
/**
84+
* Get instance of ScopePool
85+
*
86+
* @return \Magento\Framework\App\Config\ScopePool
87+
* @deprecated
88+
*/
89+
private function getScopePool()
90+
{
91+
if ($this->scopePool === null) {
92+
$this->scopePool = \Magento\Framework\App\ObjectManager::getInstance()->get(
93+
\Magento\Framework\App\Config\ScopePool::class
94+
);
95+
}
96+
return $this->scopePool;
97+
}
98+
7899
/**
79100
* Check url rewrite suffix - whether we can support it
80101
*
@@ -103,6 +124,24 @@ public function afterSave()
103124
return parent::afterSave();
104125
}
105126

127+
/**
128+
* {@inheritdoc}
129+
*/
130+
public function afterDeleteCommit()
131+
{
132+
if ($this->isValueChanged()) {
133+
$this->updateSuffixForUrlRewrites();
134+
if ($this->isCategorySuffixChanged()) {
135+
$this->cacheTypeList->invalidate([
136+
\Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER,
137+
\Magento\Framework\App\Cache\Type\Collection::TYPE_IDENTIFIER
138+
]);
139+
}
140+
}
141+
142+
return parent::afterDeleteCommit();
143+
}
144+
106145
/**
107146
* Check is category suffix changed
108147
*
@@ -135,7 +174,12 @@ protected function updateSuffixForUrlRewrites()
135174
}
136175
$entities = $this->urlFinder->findAllByData($dataFilter);
137176
$oldSuffixPattern = '~' . preg_quote($this->getOldValue()) . '$~';
138-
$suffix = $this->getValue();
177+
if ($this->getValue() !== null) {
178+
$suffix = $this->getValue();
179+
} else {
180+
$this->getScopePool()->clean();
181+
$suffix = $this->_config->getValue($this->getPath());
182+
}
139183
foreach ($entities as $urlRewrite) {
140184
$bind = $urlRewrite->getIsAutogenerated()
141185
? [UrlRewrite::REQUEST_PATH => preg_replace($oldSuffixPattern, $suffix, $urlRewrite->getRequestPath())]
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Product;
7+
8+
use Magento\Catalog\Controller\Adminhtml\Product\AddAttributeToTemplate;
9+
use Magento\Framework\Exception\LocalizedException;
10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
11+
use Magento\Backend\App\Action\Context;
12+
use Magento\Catalog\Controller\Adminhtml\Product\Builder as ProductBuilder;
13+
use Magento\Framework\Controller\Result\JsonFactory;
14+
use Magento\Framework\App\RequestInterface;
15+
use Magento\Catalog\Api\AttributeSetRepositoryInterface;
16+
use Magento\Eav\Api\Data\AttributeSetInterface;
17+
use Magento\Framework\Api\SearchCriteriaBuilder;
18+
use Magento\Framework\Api\SearchCriteria;
19+
use Magento\Eav\Api\AttributeGroupRepositoryInterface;
20+
use Magento\Eav\Api\Data\AttributeGroupSearchResultsInterface;
21+
use Magento\Eav\Api\Data\AttributeGroupInterfaceFactory;
22+
use Magento\Eav\Api\Data\AttributeGroupInterface;
23+
use Magento\Framework\Controller\Result\Json;
24+
25+
/**
26+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27+
*/
28+
class AddAttributeToTemplateTest extends \PHPUnit_Framework_TestCase
29+
{
30+
/**
31+
* @var ObjectManager
32+
*/
33+
private $objectManager;
34+
35+
/**
36+
* @var AddAttributeToTemplate
37+
*/
38+
private $controller;
39+
40+
/**
41+
* @var Context|\PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
private $contextMock;
44+
45+
/**
46+
* @var ProductBuilder|\PHPUnit_Framework_MockObject_MockObject
47+
*/
48+
private $productBuilderMock;
49+
50+
/**
51+
* @var JsonFactory|\PHPUnit_Framework_MockObject_MockObject
52+
*/
53+
private $resultJsonFactoryMock;
54+
55+
/**
56+
* @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject
57+
*/
58+
private $requestMock;
59+
60+
/**
61+
* @var AttributeSetRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
62+
*/
63+
private $attributeSetRepositoryMock;
64+
65+
/**
66+
* @var AttributeSetInterface|\PHPUnit_Framework_MockObject_MockObject
67+
*/
68+
private $attributeSetInterfaceMock;
69+
70+
/**
71+
* @var SearchCriteriaBuilder|\PHPUnit_Framework_MockObject_MockObject
72+
*/
73+
private $searchCriteriaBuilderMock;
74+
75+
/**
76+
* @var SearchCriteria|\PHPUnit_Framework_MockObject_MockObject
77+
*/
78+
private $searchCriteriaMock;
79+
80+
/**
81+
* @var AttributeGroupRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
82+
*/
83+
private $attributeGroupRepositoryMock;
84+
85+
/**
86+
* @var AttributeGroupSearchResultsInterface|\PHPUnit_Framework_MockObject_MockObject
87+
*/
88+
private $attributeGroupSearchResultsMock;
89+
90+
/**
91+
* @var AttributeGroupInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
92+
*/
93+
private $attributeGroupInterfaceFactoryMock;
94+
95+
/**
96+
* @var AttributeGroupInterface|\PHPUnit_Framework_MockObject_MockObject
97+
*/
98+
private $attributeGroupInterfaceMock;
99+
100+
/**
101+
* @var Json|\PHPUnit_Framework_MockObject_MockObject
102+
*/
103+
private $jsonMock;
104+
105+
protected function setUp()
106+
{
107+
$this->objectManager = new ObjectManager($this);
108+
$this->contextMock = $this->getMockBuilder(Context::class)
109+
->disableOriginalConstructor()
110+
->getMock();
111+
$this->productBuilderMock = $this->getMockBuilder(ProductBuilder::class)
112+
->disableOriginalConstructor()
113+
->getMock();
114+
$this->resultJsonFactoryMock = $this->getMockBuilder(JsonFactory::class)
115+
->disableOriginalConstructor()
116+
->setMethods(['create'])
117+
->getMock();
118+
$this->requestMock = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
119+
->setMethods(['getParam', 'setParam'])
120+
->getMockForAbstractClass();
121+
$this->contextMock->expects($this->once())
122+
->method('getRequest')
123+
->willReturn($this->requestMock);
124+
$this->attributeSetRepositoryMock = $this->getMockBuilder(AttributeSetRepositoryInterface::class)
125+
->setMethods(['get'])
126+
->getMockForAbstractClass();
127+
$this->attributeSetInterfaceMock = $this->getMockBuilder(AttributeSetInterface::class)
128+
->getMockForAbstractClass();
129+
$this->searchCriteriaBuilderMock = $this->getMockBuilder(SearchCriteriaBuilder::class)
130+
->disableOriginalConstructor()
131+
->setMethods(['addFilter', 'create', 'setPageSize'])
132+
->getMockForAbstractClass();
133+
$this->searchCriteriaMock = $this->getMockBuilder(SearchCriteria::class)
134+
->disableOriginalConstructor()
135+
->getMock();
136+
$this->attributeGroupRepositoryMock = $this->getMockBuilder(AttributeGroupRepositoryInterface::class)
137+
->setMethods(['getList'])
138+
->getMockForAbstractClass();
139+
$this->attributeGroupSearchResultsMock = $this->getMockBuilder(AttributeGroupSearchResultsInterface::class)
140+
->setMethods(['getItems'])
141+
->getMockForAbstractClass();
142+
$this->attributeGroupInterfaceFactoryMock = $this->getMockBuilder(AttributeGroupInterfaceFactory::class)
143+
->setMethods(['create'])
144+
->disableOriginalConstructor()
145+
->getMock();
146+
$this->attributeGroupInterfaceMock = $this->getMockBuilder(AttributeGroupInterface::class)
147+
->setMethods(['getExtensionAttributes'])
148+
->getMockForAbstractClass();
149+
$this->jsonMock = $this->getMockBuilder(Json::class)
150+
->disableOriginalConstructor()
151+
->getMock();
152+
153+
$this->controller = $this->objectManager->getObject(
154+
AddAttributeToTemplate::class,
155+
[
156+
'context' => $this->contextMock,
157+
'productBuilder' => $this->productBuilderMock,
158+
'resultJsonFactory' => $this->resultJsonFactoryMock,
159+
]
160+
);
161+
162+
$this->objectManager->setBackwardCompatibleProperty(
163+
$this->controller,
164+
'attributeSetRepository',
165+
$this->attributeSetRepositoryMock
166+
);
167+
$this->objectManager->setBackwardCompatibleProperty(
168+
$this->controller,
169+
'searchCriteriaBuilder',
170+
$this->searchCriteriaBuilderMock
171+
);
172+
$this->objectManager->setBackwardCompatibleProperty(
173+
$this->controller,
174+
'attributeGroupRepository',
175+
$this->attributeGroupRepositoryMock
176+
);
177+
$this->objectManager->setBackwardCompatibleProperty(
178+
$this->controller,
179+
'attributeGroupFactory',
180+
$this->attributeGroupInterfaceFactoryMock
181+
);
182+
}
183+
184+
public function testExecuteWithoutAttributeGroupItems()
185+
{
186+
$groupCode = 'attributes';
187+
$groupName = 'Attributes';
188+
$groupSortOrder = '15';
189+
$templateId = '4';
190+
$attributeIds = [
191+
'selected' => ["178"],
192+
'total' => '1'
193+
];
194+
195+
$this->requestMock
196+
->expects($this->any())
197+
->method('getParam')
198+
->willReturnMap(
199+
[
200+
['groupCode', null, $groupCode],
201+
['groupName', null, $groupName],
202+
['groupSortOrder', null, $groupSortOrder],
203+
['templateId', null, $templateId],
204+
['attributeIds', [], $attributeIds]
205+
]
206+
);
207+
208+
$this->attributeSetRepositoryMock->expects($this->once())
209+
->method('get')
210+
->willReturn($this->attributeSetInterfaceMock);
211+
212+
$this->searchCriteriaBuilderMock->expects($this->any())
213+
->method('addFilter')
214+
->willReturnSelf();
215+
$this->searchCriteriaBuilderMock->expects($this->any())
216+
->method('create')
217+
->willReturn($this->searchCriteriaMock);
218+
$this->searchCriteriaBuilderMock->expects($this->once())
219+
->method('setPageSize')
220+
->willReturnSelf();
221+
$this->searchCriteriaBuilderMock->expects($this->never())
222+
->method('addSortOrder')
223+
->willReturnSelf();
224+
225+
$this->attributeGroupRepositoryMock->expects($this->once())
226+
->method('getList')
227+
->willReturn($this->attributeGroupSearchResultsMock);
228+
$this->attributeGroupSearchResultsMock->expects($this->once())
229+
->method('getItems')
230+
->willReturn(null);
231+
232+
$this->attributeGroupInterfaceFactoryMock->expects($this->once())
233+
->method('create')
234+
->willReturn($this->attributeGroupInterfaceMock);
235+
$this->attributeGroupInterfaceMock->expects($this->once())
236+
->method('getExtensionAttributes')
237+
->willThrowException(new LocalizedException(__('Could not get extension attributes')));
238+
239+
$this->resultJsonFactoryMock->expects($this->once())
240+
->method('create')
241+
->willReturn($this->jsonMock);
242+
$this->jsonMock->expects($this->once())->method('setJsonData')
243+
->willReturnSelf();
244+
245+
$this->controller->execute();
246+
}
247+
}

0 commit comments

Comments
 (0)