Skip to content

Commit c21a3a6

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1648 from magento-engcom/2.2-develop-prs
Public Pull Requests #11829 Fix #10682: Meta description and keywords transform to html entities by @dverkade #11732 MAGETWO-5015: Report error csv doesn't work when trying to import a csv file with semicolon delimiter. by @p-bystritsky #11397 Fix for #9566: Show the correct label in the admin by @michielgerritsen Fixed Public Issues #10682 Meta description and keywords transform to html entities for non latin/cyrilic characters in category and product pages #5015 Report error csv doesn't work when trying to import a csv file with semicolon delimiter #9566 Status label is wrong in admin
2 parents 884d717 + 0bcfc6f commit c21a3a6

File tree

13 files changed

+198
-15
lines changed

13 files changed

+198
-15
lines changed

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()):?>

dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Import/ValidateTest.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ class ValidateTest extends \Magento\TestFramework\TestCase\AbstractBackendContro
1818
* @dataProvider validationDataProvider
1919
* @param string $fileName
2020
* @param string $message
21+
* @param string $delimiter
2122
* @backupGlobals enabled
2223
* @magentoDbIsolation enabled
2324
*/
24-
public function testValidationReturn($fileName, $message)
25+
public function testValidationReturn($fileName, $message, $delimiter)
2526
{
2627
$validationStrategy = ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_STOP_ON_ERROR;
2728

@@ -36,7 +37,7 @@ public function testValidationReturn($fileName, $message)
3637
$this->getRequest()->setPostValue('behavior', 'append');
3738
$this->getRequest()->setPostValue(Import::FIELD_NAME_VALIDATION_STRATEGY, $validationStrategy);
3839
$this->getRequest()->setPostValue(Import::FIELD_NAME_ALLOWED_ERROR_COUNT, 0);
39-
$this->getRequest()->setPostValue('_import_field_separator', ',');
40+
$this->getRequest()->setPostValue('_import_field_separator', $delimiter);
4041

4142
/** @var \Magento\TestFramework\App\Filesystem $filesystem */
4243
$filesystem = $this->_objectManager->get(\Magento\Framework\Filesystem::class);
@@ -83,12 +84,24 @@ public function validationDataProvider()
8384
return [
8485
[
8586
'file_name' => 'catalog_product.csv',
86-
'message' => 'File is valid'
87+
'message' => 'File is valid',
88+
'delimiter' => ',',
8789
],
8890
[
8991
'file_name' => 'test.txt',
90-
'message' => '\'txt\' file extension is not supported'
91-
]
92+
'message' => '\'txt\' file extension is not supported',
93+
'delimiter' => ',',
94+
],
95+
[
96+
'file_name' => 'incorrect_catalog_product_comma.csv',
97+
'message' => 'Download full report',
98+
'delimiter' => ',',
99+
],
100+
[
101+
'file_name' => 'incorrect_catalog_product_semicolon.csv',
102+
'message' => 'Download full report',
103+
'delimiter' => ';',
104+
],
92105
];
93106
}
94107
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku,store_view_code,attribute_set_code,product_type,categories,product_websites,name,description,short_description,weight,product_online,tax_class_name,visibility,price,special_price,special_price_from_date,special_price_to_date,url_key,meta_title,meta_keywords,meta_description,base_image,base_image_label,small_image,small_image_label,thumbnail_image,thumbnail_image_label,swatch_image,swatch_image_label,created_at,updated_at,new_from_date,new_to_date,display_product_options_in,map_price,msrp_price,map_enabled,gift_message_available,custom_design,custom_design_from,custom_design_to,custom_layout_update,page_layout,product_options_container,msrp_display_actual_price_type,country_of_manufacture,additional_attributes,qty,out_of_stock_qty,use_config_min_qty,is_qty_decimal,allow_backorders,use_config_backorders,min_cart_qty,use_config_min_sale_qty,max_cart_qty,use_config_max_sale_qty,is_in_stock,notify_on_stock_below,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,website_id,related_skus,related_position,crosssell_skus,crosssell_position,upsell_skus,upsell_position,additional_images,additional_image_labels,hide_from_product_page,custom_options,bundle_price_type,bundle_sku_type,bundle_price_view,bundle_weight_type,bundle_values,bundle_shipment_type,configurable_variations,configurable_variation_labels,associated_skus
2+
Simple,,Default,simple,"Default Category/New",base,Simple,,,,1,"Taxable Goods","Catalo g, Search",100.0000,,,,simple,Simple,Simple,"Simple ",,,,,,,,,"10/25/17, 8:21 AM","10/25/17, 8:21 AM",,,"Block after Info Column",,,,"Use config",,,,,,,,,,100.0000,0.0000,1,0,0,1,1.0000,1,10000.0000,1,1,1.0000,1,1,1,1,1.0000,1,0,0,0,,,,,,,,,,,,,,,,,,,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku;store_view_code;attribute_set_code;product_type;categories;product_websites;name;description;short_description;weight;product_online;tax_class_name;visibility;price;special_price;special_price_from_date;special_price_to_date;url_key;meta_title;meta_keywords;meta_description;base_image;base_image_label;small_image;small_image_label;thumbnail_image;thumbnail_image_label;swatch_image;swatch_image_label;created_at;updated_at;new_from_date;new_to_date;display_product_options_in;map_price;msrp_price;map_enabled;gift_message_available;custom_design;custom_design_from;custom_design_to;custom_layout_update;page_layout;product_options_container;msrp_display_actual_price_type;country_of_manufacture;additional_attributes;qty;out_of_stock_qty;use_config_min_qty;is_qty_decimal;allow_backorders;use_config_backorders;min_cart_qty;use_config_min_sale_qty;max_cart_qty;use_config_max_sale_qty;is_in_stock;notify_on_stock_below;use_config_notify_stock_qty;manage_stock;use_config_manage_stock;use_config_qty_increments;qty_increments;use_config_enable_qty_inc;enable_qty_increments;is_decimal_divided;website_id;related_skus;related_position;crosssell_skus;crosssell_position;upsell_skus;upsell_position;additional_images;additional_image_labels;hide_from_product_page;custom_options;bundle_price_type;bundle_sku_type;bundle_price_view;bundle_weight_type;bundle_values;bundle_shipment_type;configurable_variations;configurable_variation_labels;associated_skus
2+
Simple;;Default;simple;"Default Category/New";base;Simple;;;;1;"Taxable Goods";"Catalo g, Search";100.0000;;;;simple;Simple;Simple;"Simple ";;;;;;;;;"10/25/17, 8,21 AM";"10/25/17, 8,21 AM";;;"Block after Info Column";;;;"Use config";;;;;;;;;;100.0000;0.0000;1;0;0;1;1.0000;1;10000.0000;1;1;1.0000;1;1;1;1;1.0000;1;0;0;0;;;;;;;;;;;;;;;;;;;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sales\Model\Order;
8+
9+
/**
10+
* Class ShipmentTest
11+
* @package Magento\Sales\Model\Order
12+
*/
13+
class StatusTest extends \PHPUnit\Framework\TestCase
14+
{
15+
public function theCorrectLabelIsUsedDependingOnTheAreaProvider()
16+
{
17+
return [
18+
'backend label' => [
19+
'adminhtml',
20+
'Example',
21+
],
22+
'store view label' => [
23+
'frontend',
24+
'Store view example',
25+
],
26+
];
27+
}
28+
29+
/**
30+
* In the backend the regular label must be showed.
31+
*
32+
* @param $area
33+
* @param $result
34+
*
35+
* @magentoDataFixture Magento/Sales/_files/order_status.php
36+
* @dataProvider theCorrectLabelIsUsedDependingOnTheAreaProvider
37+
*/
38+
public function testTheCorrectLabelIsUsedDependingOnTheArea($area, $result)
39+
{
40+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
41+
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode($area);
42+
43+
/** @var \Magento\Sales\Model\Order $order */
44+
$order = $objectManager->create(\Magento\Sales\Model\Order::class);
45+
$order->loadByIncrementId('100000001');
46+
47+
$this->assertEquals($result, $order->getStatusLabel());
48+
}
49+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
require __DIR__ . '/order.php';
8+
9+
$orderStatus = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
10+
\Magento\Sales\Model\Order\Status::class
11+
);
12+
13+
$data = [
14+
'status' => 'example',
15+
'label' => 'Example',
16+
'store_labels' => [
17+
1 => 'Store view example',
18+
]
19+
];
20+
21+
$orderStatus->setData($data)->setStatus('example');
22+
$orderStatus->save();
23+
24+
$order->setStatus('example');
25+
$order->save();

lib/internal/Magento/Framework/View/Page/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function getTitle()
226226
public function setMetadata($name, $content)
227227
{
228228
$this->build();
229-
$this->metadata[$name] = htmlentities($content);
229+
$this->metadata[$name] = htmlspecialchars($content);
230230
}
231231

232232
/**

0 commit comments

Comments
 (0)