Skip to content

Commit a1338c6

Browse files
author
Oleksii Korshenko
authored
MAGETWO-87062: [EngCom Team] Batch 4. Forwardports to 2.3-develop #1285
2 parents d658315 + 4921802 commit a1338c6

File tree

23 files changed

+448
-53
lines changed

23 files changed

+448
-53
lines changed

app/code/Magento/Catalog/view/adminhtml/web/js/custom-options-type.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,6 @@ define([
103103

104104
if (component) {
105105
component.visible(visible);
106-
107-
/*eslint-disable max-depth */
108-
if (_.isFunction(component.clear)) {
109-
component.clear();
110-
}
111106
}
112107
}
113108
}, this);

app/code/Magento/CatalogUrlRewrite/Model/ProductScopeRewriteGenerator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ public function generateForSpecificStoreView($storeId, $productCategories, Produ
207207
*/
208208
public function isCategoryProperForGenerating(Category $category, $storeId)
209209
{
210-
if ($category->getParentId() != \Magento\Catalog\Model\Category::TREE_ROOT_ID) {
211-
list(, $rootCategoryId) = $category->getParentIds();
210+
$parentIds = $category->getParentIds();
211+
if (count($parentIds) >= 2) {
212+
$rootCategoryId = $parentIds[1];
212213
return $rootCategoryId == $this->storeManager->getStore($storeId)->getRootCategoryId();
213214
}
214215
return false;

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/ProductScopeRewriteGeneratorTest.php

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class ProductScopeRewriteGeneratorTest extends \PHPUnit\Framework\TestCase
4747
/** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
4848
private $serializer;
4949

50+
/** @var \Magento\Catalog\Model\Category|\PHPUnit_Framework_MockObject_MockObject */
51+
private $categoryMock;
52+
5053
public function setUp()
5154
{
5255
$this->serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class);
@@ -83,6 +86,10 @@ function ($value) {
8386
$this->storeViewService = $this->getMockBuilder(\Magento\CatalogUrlRewrite\Service\V1\StoreViewService::class)
8487
->disableOriginalConstructor()->getMock();
8588
$this->storeManager = $this->createMock(StoreManagerInterface::class);
89+
$storeRootCategoryId = 2;
90+
$store = $this->getMockBuilder(\Magento\Store\Model\Store::class)->disableOriginalConstructor()->getMock();
91+
$store->expects($this->any())->method('getRootCategoryId')->will($this->returnValue($storeRootCategoryId));
92+
$this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
8693
$mergeDataProviderFactory = $this->createPartialMock(
8794
\Magento\UrlRewrite\Model\MergeDataProviderFactory::class,
8895
['create']
@@ -103,6 +110,7 @@ function ($value) {
103110
'mergeDataProviderFactory' => $mergeDataProviderFactory
104111
]
105112
);
113+
$this->categoryMock = $this->getMockBuilder(Category::class)->disableOriginalConstructor()->getMock();
106114
}
107115

108116
public function testGenerationForGlobalScope()
@@ -112,12 +120,6 @@ public function testGenerationForGlobalScope()
112120
$product->expects($this->any())->method('getStoreIds')->will($this->returnValue([1]));
113121
$this->storeViewService->expects($this->once())->method('doesEntityHaveOverriddenUrlKeyForStore')
114122
->will($this->returnValue(false));
115-
$categoryMock = $this->getMockBuilder(Category::class)
116-
->disableOriginalConstructor()
117-
->getMock();
118-
$categoryMock->expects($this->once())
119-
->method('getParentId')
120-
->willReturn(1);
121123
$this->initObjectRegistryFactory([]);
122124
$canonical = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializer);
123125
$canonical->setRequestPath('category-1')
@@ -149,25 +151,21 @@ public function testGenerationForGlobalScope()
149151
'category-3_3' => $current,
150152
'category-4_4' => $anchorCategories
151153
],
152-
$this->productScopeGenerator->generateForGlobalScope([$categoryMock], $product, 1)
154+
$this->productScopeGenerator->generateForGlobalScope([$this->categoryMock], $product, 1)
153155
);
154156
}
155157

156158
public function testGenerationForSpecificStore()
157159
{
160+
$storeRootCategoryId = 2;
161+
$category_id = 4;
158162
$product = $this->createMock(\Magento\Catalog\Model\Product::class);
159163
$product->expects($this->any())->method('getStoreId')->will($this->returnValue(1));
160164
$product->expects($this->never())->method('getStoreIds');
161-
$storeRootCategoryId = 'root-for-store-id';
162-
$category = $this->createMock(\Magento\Catalog\Model\Category::class);
163-
$category->expects($this->any())->method('getParentIds')
165+
$this->categoryMock->expects($this->any())->method('getParentIds')
164166
->will($this->returnValue(['root-id', $storeRootCategoryId]));
165-
$category->expects($this->any())->method('getParentId')->will($this->returnValue('parent_id'));
166-
$category->expects($this->any())->method('getId')->will($this->returnValue('category_id'));
167-
$store = $this->getMockBuilder(\Magento\Store\Model\Store::class)->disableOriginalConstructor()->getMock();
168-
$store->expects($this->any())->method('getRootCategoryId')->will($this->returnValue($storeRootCategoryId));
169-
$this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
170-
$this->initObjectRegistryFactory([$category]);
167+
$this->categoryMock->expects($this->any())->method('getId')->will($this->returnValue($category_id));
168+
$this->initObjectRegistryFactory([$this->categoryMock]);
171169
$canonical = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializer);
172170
$canonical->setRequestPath('category-1')
173171
->setStoreId(1);
@@ -184,7 +182,7 @@ public function testGenerationForSpecificStore()
184182

185183
$this->assertEquals(
186184
['category-1_1' => $canonical],
187-
$this->productScopeGenerator->generateForSpecificStoreView(1, [$category], $product, 1)
185+
$this->productScopeGenerator->generateForSpecificStoreView(1, [$this->categoryMock], $product, 1)
188186
);
189187
}
190188

@@ -212,4 +210,40 @@ protected function initObjectRegistryFactory($entities)
212210
->with(['entities' => $entities])
213211
->will($this->returnValue($objectRegistry));
214212
}
213+
214+
/**
215+
* Test the possibility of url rewrite generation.
216+
*
217+
* @param array $parentIds
218+
* @param bool $expectedResult
219+
* @dataProvider isCategoryProperForGeneratingDataProvider
220+
*/
221+
public function testIsCategoryProperForGenerating($parentIds, $expectedResult)
222+
{
223+
$storeId = 1;
224+
$this->categoryMock->expects(self::any())->method('getParentIds')->willReturn($parentIds);
225+
$result = $this->productScopeGenerator->isCategoryProperForGenerating(
226+
$this->categoryMock,
227+
$storeId
228+
);
229+
self::assertEquals(
230+
$expectedResult,
231+
$result
232+
);
233+
}
234+
235+
/**
236+
* Data provider for testIsCategoryProperForGenerating.
237+
*
238+
* @return array
239+
*/
240+
public function isCategoryProperForGeneratingDataProvider()
241+
{
242+
return [
243+
[['0'], false],
244+
[['1'], false],
245+
[['1', '2'], true],
246+
[['1', '3'], false],
247+
];
248+
}
215249
}

app/code/Magento/Customer/etc/webapi.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@
200200
<resource ref="anonymous"/>
201201
</resources>
202202
</route>
203+
<route url="/V1/customers/resetPassword" method="POST">
204+
<service class="Magento\Customer\Api\AccountManagementInterface" method="resetPassword"/>
205+
<resources>
206+
<resource ref="anonymous"/>
207+
</resources>
208+
</route>
203209
<route url="/V1/customers/:customerId/confirm" method="GET">
204210
<service class="Magento\Customer\Api\AccountManagementInterface" method="getConfirmationStatus"/>
205211
<resources>

app/code/Magento/ImportExport/Helper/Report.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace Magento\ImportExport\Helper;
88

99
use Magento\Framework\App\Filesystem\DirectoryList;
10-
use Magento\Framework\Stdlib\DateTime;
1110
use Magento\ImportExport\Model\Import;
1211

1312
/**
@@ -127,4 +126,14 @@ protected function getFilePath($filename)
127126
{
128127
return $this->varDirectory->getRelativePath(Import::IMPORT_HISTORY_DIR . $filename);
129128
}
129+
130+
/**
131+
* Get csv delimiter from request.
132+
*
133+
* @return string
134+
*/
135+
public function getDelimiter()
136+
{
137+
return $this->_request->getParam(Import::FIELD_FIELD_SEPARATOR, ',');
138+
}
130139
}

app/code/Magento/ImportExport/Model/Report/Csv.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ protected function createSourceCsvModel($sourceFile)
130130
return $this->sourceCsvFactory->create(
131131
[
132132
'file' => $sourceFile,
133-
'directory' => $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR)
133+
'directory' => $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR),
134+
'delimiter' => $this->reportHelper->getDelimiter(),
134135
]
135136
);
136137
}

app/code/Magento/ImportExport/Test/Unit/Helper/ReportTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,21 @@ class ReportTest extends \PHPUnit\Framework\TestCase
4444
*/
4545
protected $report;
4646

47+
/**
48+
* @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject
49+
*/
50+
private $requestMock;
51+
4752
/**
4853
* Set up
4954
*/
5055
protected function setUp()
5156
{
5257
$this->context = $this->createMock(\Magento\Framework\App\Helper\Context::class);
58+
$this->requestMock = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
59+
->disableOriginalConstructor()
60+
->getMock();
61+
$this->context->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
5362
$this->timezone = $this->createPartialMock(
5463
\Magento\Framework\Stdlib\DateTime\Timezone::class,
5564
['date', 'getConfigTimezone', 'diff', 'format']
@@ -159,4 +168,20 @@ public function testGetReportSize()
159168
$result = $this->report->getReportSize('file');
160169
$this->assertNull($result);
161170
}
171+
172+
/**
173+
* Test getDelimiter() take into consideration request param '_import_field_separator'.
174+
*/
175+
public function testGetDelimiter()
176+
{
177+
$testDelimiter = 'some delimiter';
178+
$this->requestMock->expects($this->once())
179+
->method('getParam')
180+
->with($this->identicalTo(\Magento\ImportExport\Model\Import::FIELD_FIELD_SEPARATOR))
181+
->willReturn($testDelimiter);
182+
$this->assertEquals(
183+
$testDelimiter,
184+
$this->report->getDelimiter()
185+
);
186+
}
162187
}

app/code/Magento/ImportExport/Test/Unit/Model/Report/CsvTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ class CsvTest extends \PHPUnit\Framework\TestCase
4545
protected function setUp()
4646
{
4747
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
48+
$testDelimiter = 'some_delimiter';
4849

4950
$this->reportHelperMock = $this->createMock(\Magento\ImportExport\Helper\Report::class);
51+
$this->reportHelperMock->expects($this->any())->method('getDelimiter')->willReturn($testDelimiter);
5052

5153
$this->outputCsvFactoryMock = $this->createPartialMock(
5254
\Magento\ImportExport\Model\Export\Adapter\CsvFactory::class,
@@ -65,7 +67,17 @@ protected function setUp()
6567
[23 => 'first error'],
6668
[27 => 'second error']
6769
);
68-
$this->sourceCsvFactoryMock->expects($this->any())->method('create')->willReturn($this->sourceCsvMock);
70+
$this->sourceCsvFactoryMock
71+
->expects($this->any())
72+
->method('create')
73+
->with(
74+
[
75+
'file' => 'some_file_name',
76+
'directory' => null,
77+
'delimiter' => $testDelimiter
78+
]
79+
)
80+
->willReturn($this->sourceCsvMock);
6981

7082
$this->filesystemMock = $this->createMock(\Magento\Framework\Filesystem::class);
7183

app/code/Magento/Sales/Model/Order/Config.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,14 @@ public function getStateDefaultStatus($state)
122122
*/
123123
public function getStatusLabel($code)
124124
{
125-
$code = $this->maskStatusForArea($this->state->getAreaCode(), $code);
125+
$area = $this->state->getAreaCode();
126+
$code = $this->maskStatusForArea($area, $code);
126127
$status = $this->orderStatusFactory->create()->load($code);
128+
129+
if ($area == 'adminhtml') {
130+
return $status->getLabel();
131+
}
132+
127133
return $status->getStoreLabel();
128134
}
129135

@@ -211,7 +217,7 @@ public function getStateStatuses($state, $addLabels = true)
211217
foreach ($collection as $item) {
212218
$status = $item->getData('status');
213219
if ($addLabels) {
214-
$statuses[$status] = $item->getStoreLabel();
220+
$statuses[$status] = $this->getStatusLabel($status);
215221
} else {
216222
$statuses[] = $status;
217223
}

app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,41 @@ class ConfigTest extends \PHPUnit\Framework\TestCase
2323
*/
2424
protected $orderStatusCollectionFactoryMock;
2525

26+
/**
27+
* @var \Magento\Sales\Model\Order\StatusFactory|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
protected $statusFactoryMock;
30+
31+
/**
32+
* @var \Magento\Sales\Model\Order\Status
33+
*/
34+
protected $orderStatusModel;
35+
36+
/**
37+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
protected $storeManagerMock;
40+
2641
protected function setUp()
2742
{
28-
$orderStatusFactory = $this->createMock(\Magento\Sales\Model\Order\StatusFactory::class);
43+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
44+
45+
$this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
46+
$this->orderStatusModel = $objectManager->getObject(\Magento\Sales\Model\Order\Status::class, [
47+
'storeManager' => $this->storeManagerMock,
48+
]);
49+
$this->statusFactoryMock = $this->getMockBuilder(\Magento\Sales\Model\Order\StatusFactory::class)
50+
->setMethods(['load', 'create'])
51+
->getMock();
2952
$this->orderStatusCollectionFactoryMock = $this->createPartialMock(
3053
\Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory::class,
3154
['create']
3255
);
33-
$this->salesConfig = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
56+
$this->salesConfig = $objectManager
3457
->getObject(
3558
\Magento\Sales\Model\Order\Config::class,
3659
[
37-
'orderStatusFactory' => $orderStatusFactory,
60+
'orderStatusFactory' => $this->statusFactoryMock,
3861
'orderStatusCollectionFactory' => $this->orderStatusCollectionFactoryMock
3962
]
4063
);
@@ -147,6 +170,22 @@ public function testGetStatuses($state, $joinLabels, $collectionData, $expectedR
147170
->method('joinStates')
148171
->will($this->returnValue($collectionData));
149172

173+
$this->statusFactoryMock->method('create')
174+
->willReturnSelf();
175+
176+
$this->statusFactoryMock->method('load')
177+
->willReturn($this->orderStatusModel);
178+
179+
$storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
180+
$storeMock->method('getId')
181+
->willReturn(1);
182+
183+
$this->storeManagerMock->method('getStore')
184+
->with($this->anything())
185+
->willReturn($storeMock);
186+
187+
$this->orderStatusModel->setData('store_labels', [1 => 'Pending label']);
188+
150189
$result = $this->salesConfig->getStateStatuses($state, $joinLabels);
151190
$this->assertSame($expectedResult, $result);
152191

app/code/Magento/Sales/view/adminhtml/templates/order/view/history.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
// @codingStandardsIgnoreFile
8-
8+
/** @var \Magento\Sales\Block\Adminhtml\Order\View\History $block */
99
?>
1010
<div id="order_history_block" class="edit-order-comments">
1111
<?php if ($block->canAddComment()):?>

0 commit comments

Comments
 (0)