Skip to content

Commit 259be86

Browse files
committed
Merge remote-tracking branch 'jackalopes/FearlessKiwis-MAGETWO-66480-url-key-duplicate' into pr
2 parents 41e2ddd + ede9c8f commit 259be86

File tree

54 files changed

+1668
-203
lines changed

Some content is hidden

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

54 files changed

+1668
-203
lines changed

app/code/Magento/Backend/Test/Unit/Controller/Adminhtml/Cache/CleanMediaTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,26 @@ public function testExecute()
2626
['setIsUrlNotice'],
2727
$helper->getConstructArguments(\Magento\Backend\Model\Session::class)
2828
);
29+
30+
$exceptionMessageFactory = $this->getMockBuilder(
31+
\Magento\Framework\Message\ExceptionMessageLookupFactory::class
32+
)
33+
->disableOriginalConstructor()
34+
->setMethods(
35+
['getMessageGenerator']
36+
)
37+
->getMock();
38+
39+
$messageManagerParams = $helper->getConstructArguments(\Magento\Framework\Message\Manager::class);
40+
41+
$messageManagerParams['exceptionMessageFactory'] = $exceptionMessageFactory;
42+
2943
$messageManager = $this->getMock(
3044
\Magento\Framework\Message\Manager::class,
3145
['addSuccess'],
32-
$helper->getConstructArguments(\Magento\Framework\Message\Manager::class)
46+
$messageManagerParams
3347
);
48+
3449
$context = $this->getMock(
3550
\Magento\Backend\App\Action\Context::class,
3651
['getRequest', 'getResponse', 'getMessageManager', 'getSession', 'getResultFactory'],

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Move extends \Magento\Catalog\Controller\Adminhtml\Category
2727
* @param \Magento\Backend\App\Action\Context $context
2828
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
2929
* @param \Magento\Framework\View\LayoutFactory $layoutFactory,
30-
* @param \Psr\Log\LoggerInterface $logger,
30+
* @param \Psr\Log\LoggerInterface $logger
3131
*/
3232
public function __construct(
3333
\Magento\Backend\App\Action\Context $context,
@@ -67,20 +67,17 @@ public function execute()
6767
throw new \Exception(__('Category is not available for requested store.'));
6868
}
6969
$category->move($parentNodeId, $prevNodeId);
70-
} catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
71-
$error = true;
72-
$this->messageManager->addError(__('There was a category move error. %1', $e->getMessage()));
7370
} catch (\Magento\Framework\Exception\LocalizedException $e) {
7471
$error = true;
75-
$this->messageManager->addError($e->getMessage());
72+
$this->messageManager->addExceptionMessage($e);
7673
} catch (\Exception $e) {
7774
$error = true;
78-
$this->messageManager->addError(__('There was a category move error.'));
75+
$this->messageManager->addErrorMessage(__('There was a category move error.'));
7976
$this->logger->critical($e);
8077
}
8178

8279
if (!$error) {
83-
$this->messageManager->addSuccess(__('You moved the category.'));
80+
$this->messageManager->addSuccessMessage(__('You moved the category.'));
8481
}
8582

8683
$block->setMessages($this->messageManager->getMessages(true));

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,13 @@ public function execute()
211211
$category->unsetData('use_post_data_config');
212212

213213
$category->save();
214-
$this->messageManager->addSuccess(__('You saved the category.'));
215-
} catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
216-
$this->messageManager->addError($e->getMessage());
217-
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
218-
$this->_getSession()->setCategoryData($categoryPostData);
214+
$this->messageManager->addSuccessMessage(__('You saved the category.'));
219215
} catch (\Magento\Framework\Exception\LocalizedException $e) {
220-
$this->messageManager->addError($e->getMessage());
216+
$this->messageManager->addExceptionMessage($e);
221217
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
222218
$this->_getSession()->setCategoryData($categoryPostData);
223219
} catch (\Exception $e) {
224-
$this->messageManager->addError(__('Something went wrong while saving the category.'));
220+
$this->messageManager->addErrorMessage(__('Something went wrong while saving the category.'));
225221
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
226222
$this->_getSession()->setCategoryData($categoryPostData);
227223
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ public function execute()
119119

120120
$this->copyToStores($data, $productId);
121121

122-
$this->messageManager->addSuccess(__('You saved the product.'));
122+
$this->messageManager->addSuccessMessage(__('You saved the product.'));
123123
$this->getDataPersistor()->clear('catalog_product');
124124
if ($product->getSku() != $originalSku) {
125-
$this->messageManager->addNotice(
125+
$this->messageManager->addNoticeMessage(
126126
__(
127127
'SKU for product %1 has been changed to %2.',
128128
$this->_objectManager->get(
@@ -141,22 +141,22 @@ public function execute()
141141

142142
if ($redirectBack === 'duplicate') {
143143
$newProduct = $this->productCopier->copy($product);
144-
$this->messageManager->addSuccess(__('You duplicated the product.'));
144+
$this->messageManager->addSuccessMessage(__('You duplicated the product.'));
145145
}
146146
} catch (\Magento\Framework\Exception\LocalizedException $e) {
147147
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
148-
$this->messageManager->addError($e->getMessage());
148+
$this->messageManager->addExceptionMessage($e);
149149
$this->getDataPersistor()->set('catalog_product', $data);
150150
$redirectBack = $productId ? true : 'new';
151151
} catch (\Exception $e) {
152152
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
153-
$this->messageManager->addError($e->getMessage());
153+
$this->messageManager->addErrorMessage($e->getMessage());
154154
$this->getDataPersistor()->set('catalog_product', $data);
155155
$redirectBack = $productId ? true : 'new';
156156
}
157157
} else {
158158
$resultRedirect->setPath('catalog/*/', ['store' => $storeId]);
159-
$this->messageManager->addError('No data to save');
159+
$this->messageManager->addErrorMessage('No data to save');
160160
return $resultRedirect;
161161
}
162162

@@ -202,7 +202,7 @@ private function handleImageRemoveError($postData, $productId)
202202
$expectedImagesAmount = count($postData['product']['media_gallery']['images']) - $removedImagesAmount;
203203
$product = $this->productRepository->getById($productId);
204204
if ($expectedImagesAmount != count($product->getMediaGallery('images'))) {
205-
$this->messageManager->addNotice(
205+
$this->messageManager->addNoticeMessage(
206206
__('The image cannot be removed as it has been assigned to the other image role')
207207
);
208208
}

app/code/Magento/Catalog/Test/Unit/Controller/Category/MoveTest.php renamed to app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/MoveTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\Catalog\Test\Unit\Controller\Category;
6+
namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Category;
77

88
use Magento\Catalog\Controller\Adminhtml\Category\Move;
99
use Magento\Framework\Message\ManagerInterface;
@@ -142,7 +142,7 @@ public function testExecuteWithGenericException()
142142
__('Some exception')
143143
));
144144
$this->messageManager->expects($this->once())
145-
->method('addError')
145+
->method('addErrorMessage')
146146
->with(__('There was a category move error.'));
147147
$this->messageManager->expects($this->once())
148148
->method('getMessages')
@@ -211,8 +211,7 @@ public function testExecuteWithLocaliedException()
211211
->withConsecutive([Registry::class], [Registry::class], [\Magento\Cms\Model\Wysiwyg\Config::class])
212212
->willReturnMap([[Registry::class, $registry], [\Magento\Cms\Model\Wysiwyg\Config::class, $wysiwigConfig]]);
213213
$this->messageManager->expects($this->once())
214-
->method('addError')
215-
->with($exceptionMessage);
214+
->method('addExceptionMessage');
216215
$this->messageManager->expects($this->once())
217216
->method('getMessages')
218217
->with(true)
@@ -306,7 +305,7 @@ public function testSuccessfullCategorySave()
306305
)
307306
->willReturn(true);
308307
$this->messageManager->expects($this->once())
309-
->method('addSuccess')
308+
->method('addSuccessMessage')
310309
->with(__('You moved the category.'));
311310
$categoryMock->expects($this->once())
312311
->method('move')

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/SaveTest.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,28 @@ class SaveTest extends \Magento\Catalog\Test\Unit\Controller\Adminhtml\ProductTe
1717
protected $action;
1818

1919
/** @var \Magento\Backend\Model\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject */
20-
protected $resultPage;
20+
private $resultPage;
2121

2222
/** @var \Magento\Backend\Model\View\Result\Forward|\PHPUnit_Framework_MockObject_MockObject */
23-
protected $resultForward;
23+
private $resultForward;
2424

2525
/** @var \Magento\Catalog\Controller\Adminhtml\Product\Builder|\PHPUnit_Framework_MockObject_MockObject */
26-
protected $productBuilder;
26+
private $productBuilder;
2727

2828
/** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject */
29-
protected $product;
29+
private $product;
3030

3131
/** @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject */
32-
protected $resultRedirectFactory;
32+
private $resultRedirectFactory;
3333

3434
/** @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject */
35-
protected $resultRedirect;
35+
private $resultRedirect;
3636

3737
/** @var Helper|\PHPUnit_Framework_MockObject_MockObject */
38-
protected $initializationHelper;
38+
private $initializationHelper;
39+
40+
/** @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
41+
private $messageManagerMock;
3942

4043
/**
4144
* @return void
@@ -55,6 +58,10 @@ protected function setUp()
5558
$this->product->expects($this->any())->method('getStoreId')->will($this->returnValue('1'));
5659
$this->productBuilder->expects($this->any())->method('build')->will($this->returnValue($this->product));
5760

61+
$this->messageManagerMock = $this->getMockForAbstractClass(
62+
\Magento\Framework\Message\ManagerInterface::class
63+
);
64+
5865
$this->resultPage = $this->getMockBuilder(\Magento\Backend\Model\View\Result\Page::class)
5966
->disableOriginalConstructor()
6067
->getMock();
@@ -120,21 +127,24 @@ protected function setUp()
120127
\Magento\Catalog\Controller\Adminhtml\Product\Save::class,
121128
[
122129
'context' => $this->initContext($additionalParams),
130+
'resultRedirectFactory' => $this->resultRedirectFactory,
123131
'productBuilder' => $this->productBuilder,
124132
'resultPageFactory' => $resultPageFactory,
125133
'resultForwardFactory' => $resultForwardFactory,
126134
'initializationHelper' => $this->initializationHelper,
127135
'storeManager' => $storeManagerInterfaceMock,
136+
'messageManager' => $this->messageManagerMock
128137
]
129138
);
130139
}
131140

132141
/**
133142
* @param string $exceptionType
143+
* @param string $methodExpected
134144
* @return void
135145
* @dataProvider exceptionTypeDataProvider
136146
*/
137-
public function testExecuteSetsProductDataToSessionAndRedirectsToNewActionOnError($exceptionType)
147+
public function testExecuteSetsProductDataToSessionAndRedirectsToNewActionOnError($exceptionType, $methodExpected)
138148
{
139149
$productData = ['product' => ['name' => 'test-name']];
140150

@@ -145,6 +155,9 @@ public function testExecuteSetsProductDataToSessionAndRedirectsToNewActionOnErro
145155

146156
$this->resultRedirect->expects($this->once())->method('setPath')->with('catalog/*/new');
147157

158+
$this->messageManagerMock->expects($this->once())
159+
->method($methodExpected);
160+
148161
$this->action->execute();
149162
}
150163

@@ -153,6 +166,9 @@ public function testExecuteSetsProductDataToSessionAndRedirectsToNewActionOnErro
153166
*/
154167
public function exceptionTypeDataProvider()
155168
{
156-
return [[\Magento\Framework\Exception\LocalizedException::class], ['Exception']];
169+
return [
170+
[\Magento\Framework\Exception\LocalizedException::class, 'addExceptionMessage'],
171+
['Exception', 'addErrorMessage']
172+
];
157173
}
158174
}

app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Storage.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public function __construct(
3333

3434
/**
3535
* @param \Magento\UrlRewrite\Model\StorageInterface $object
36-
* @param null $result
36+
* @param \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[] $result
3737
* @param \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[] $urls
38-
* @return void
38+
* @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
3939
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4040
*/
41-
public function afterReplace(StorageInterface $object, $result, array $urls)
41+
public function afterReplace(StorageInterface $object, array $result, array $urls)
4242
{
4343
$toSave = [];
44-
foreach ($this->filterUrls($urls) as $record) {
44+
foreach ($this->filterUrls($result) as $record) {
4545
$metadata = $record->getMetadata();
4646
$toSave[] = [
4747
'url_rewrite_id' => $record->getUrlRewriteId(),
@@ -52,6 +52,7 @@ public function afterReplace(StorageInterface $object, $result, array $urls)
5252
if ($toSave) {
5353
$this->productResource->saveMultiple($toSave);
5454
}
55+
return $result;
5556
}
5657

5758
/**

app/code/Magento/CatalogUrlRewrite/Model/Storage/DbStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DbStorage extends BaseDbStorage
1515
* @param array $data
1616
* @return \Magento\Framework\DB\Select
1717
*/
18-
protected function prepareSelect($data)
18+
protected function prepareSelect(array $data)
1919
{
2020
$select = $this->connection->select();
2121
$select->from(['url_rewrite' => $this->resource->getTableName('url_rewrite')])

0 commit comments

Comments
 (0)