Skip to content

Commit f808b51

Browse files
Merge pull request #530 from magento-falcons/MAGETWO-59974
Bug MAGETWO-56317 [GitHub] -[2.1.0] underscore in site url breaks admin redirect - The page isn't redirecting properly #5809 MAGETWO-59743 Product deleted after import with Replace behavior
2 parents f6d1b99 + 8903f8d commit f808b51

File tree

15 files changed

+746
-120
lines changed

15 files changed

+746
-120
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,7 @@ public function validateRow(array $rowData, $rowNum)
23042304

23052305
$sku = $rowData[self::COL_SKU];
23062306

2307-
if (isset($this->_oldSku[$sku])) {
2307+
if (isset($this->_oldSku[$sku]) && Import::BEHAVIOR_REPLACE !== $this->getBehavior()) {
23082308
// can we get all necessary data from existent DB product?
23092309
// check for supported type of existing product
23102310
if (isset($this->_productTypeModels[$this->_oldSku[$sku]['type_id']])) {
@@ -2356,7 +2356,7 @@ public function validateRow(array $rowData, $rowNum)
23562356
$rowAttributesValid = $productTypeValidator->isRowValid(
23572357
$rowData,
23582358
$rowNum,
2359-
!isset($this->_oldSku[$sku])
2359+
!(isset($this->_oldSku[$sku]) && Import::BEHAVIOR_REPLACE !== $this->getBehavior())
23602360
);
23612361
if (!$rowAttributesValid && self::SCOPE_DEFAULT == $rowScope) {
23622362
// mark SCOPE_DEFAULT row as invalid for future child rows if product not in DB already

app/code/Magento/Config/Model/Config/Backend/Baseurl.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55
*/
66
namespace Magento\Config\Model\Config\Backend;
77

8+
use Magento\Framework\Validator\Url as UrlValidator;
9+
use Magento\Framework\App\ObjectManager;
10+
811
class Baseurl extends \Magento\Framework\App\Config\Value
912
{
1013
/**
1114
* @var \Magento\Framework\View\Asset\MergeService
1215
*/
1316
protected $_mergeService;
1417

18+
/**
19+
* @var UrlValidator
20+
*/
21+
private $urlValidator;
22+
1523
/**
1624
* @param \Magento\Framework\Model\Context $context
1725
* @param \Magento\Framework\Registry $registry
@@ -193,8 +201,7 @@ private function _validateFullyQualifiedUrl($value)
193201
*/
194202
private function _isFullyQualifiedUrl($value)
195203
{
196-
$url = parse_url($value);
197-
return isset($url['scheme']) && isset($url['host']) && preg_match('/\/$/', $value);
204+
return preg_match('/\/$/', $value) && $this->getUrlValidator()->isValid($value, ['http', 'https']);
198205
}
199206

200207
/**
@@ -216,4 +223,18 @@ public function afterSave()
216223
}
217224
return parent::afterSave();
218225
}
226+
227+
/**
228+
* Get URL Validator
229+
*
230+
* @deprecated
231+
* @return UrlValidator
232+
*/
233+
private function getUrlValidator()
234+
{
235+
if (!$this->urlValidator) {
236+
$this->urlValidator = ObjectManager::getInstance()->get(UrlValidator::class);
237+
}
238+
return $this->urlValidator;
239+
}
219240
}

dev/tests/functional/tests/app/Magento/Install/Test/Block/WebConfiguration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class WebConfiguration extends Form
2121
*
2222
* @var string
2323
*/
24-
protected $next = "[ng-click*='next']";
24+
protected $next = "[ng-click*='validateUrl']";
2525

2626
/**
2727
* 'Advanced Options' locator.

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,4 +1431,113 @@ public function testProductWithWrappedAdditionalAttributes()
14311431
$this->assertEquals(implode(',', [$multiselectOptions[1]->getValue(), $multiselectOptions[2]->getValue()]),
14321432
$product2->getData('multiselect_attribute'));
14331433
}
1434+
1435+
/**
1436+
* @param array $row
1437+
* @param string|null $behavior
1438+
* @param bool $expectedResult
1439+
* @magentoAppArea adminhtml
1440+
* @magentoAppIsolation enabled
1441+
* @magentoDbIsolation enabled
1442+
* @magentoDataFixture Magento/Catalog/Model/ResourceModel/_files/product_simple.php
1443+
* @dataProvider validateRowDataProvider
1444+
*/
1445+
public function testValidateRow(array $row, $behavior, $expectedResult)
1446+
{
1447+
$this->_model->setParameters(['behavior' => $behavior, 'entity' => 'catalog_product']);
1448+
$this->assertSame($expectedResult, $this->_model->validateRow($row, 1));
1449+
}
1450+
1451+
/**
1452+
* @return array
1453+
*/
1454+
public function validateRowDataProvider()
1455+
{
1456+
return [
1457+
[
1458+
'row' => ['sku' => 'simple products'],
1459+
'behavior' => null,
1460+
'expectedResult' => true,
1461+
],
1462+
[
1463+
'row' => ['sku' => 'simple products absent'],
1464+
'behavior' => null,
1465+
'expectedResult' => false,
1466+
],
1467+
[
1468+
'row' => [
1469+
'sku' => 'simple products absent',
1470+
'name' => 'Test',
1471+
'product_type' => 'simple',
1472+
'_attribute_set' => 'Default',
1473+
'price' => 10.20,
1474+
],
1475+
'behavior' => null,
1476+
'expectedResult' => true,
1477+
],
1478+
[
1479+
'row' => ['sku' => 'simple products'],
1480+
'behavior' => Import::BEHAVIOR_ADD_UPDATE,
1481+
'expectedResult' => true,
1482+
],
1483+
[
1484+
'row' => ['sku' => 'simple products absent'],
1485+
'behavior' => Import::BEHAVIOR_ADD_UPDATE,
1486+
'expectedResult' => false,
1487+
],
1488+
[
1489+
'row' => [
1490+
'sku' => 'simple products absent',
1491+
'name' => 'Test',
1492+
'product_type' => 'simple',
1493+
'_attribute_set' => 'Default',
1494+
'price' => 10.20,
1495+
],
1496+
'behavior' => Import::BEHAVIOR_ADD_UPDATE,
1497+
'expectedResult' => true,
1498+
],
1499+
[
1500+
'row' => ['sku' => 'simple products'],
1501+
'behavior' => Import::BEHAVIOR_DELETE,
1502+
'expectedResult' => true,
1503+
],
1504+
[
1505+
'row' => ['sku' => 'simple products absent'],
1506+
'behavior' => Import::BEHAVIOR_DELETE,
1507+
'expectedResult' => false,
1508+
],
1509+
[
1510+
'row' => ['sku' => 'simple products'],
1511+
'behavior' => Import::BEHAVIOR_REPLACE,
1512+
'expectedResult' => false,
1513+
],
1514+
[
1515+
'row' => ['sku' => 'simple products absent'],
1516+
'behavior' => Import::BEHAVIOR_REPLACE,
1517+
'expectedResult' => false,
1518+
],
1519+
[
1520+
'row' => [
1521+
'sku' => 'simple products absent',
1522+
'name' => 'Test',
1523+
'product_type' => 'simple',
1524+
'_attribute_set' => 'Default',
1525+
'price' => 10.20,
1526+
],
1527+
'behavior' => Import::BEHAVIOR_REPLACE,
1528+
'expectedResult' => false,
1529+
],
1530+
[
1531+
'row' => [
1532+
'sku' => 'simple products',
1533+
'name' => 'Test',
1534+
'product_type' => 'simple',
1535+
'_attribute_set' => 'Default',
1536+
'price' => 10.20,
1537+
],
1538+
'behavior' => Import::BEHAVIOR_REPLACE,
1539+
'expectedResult' => true,
1540+
],
1541+
];
1542+
}
14341543
}

dev/tests/integration/testsuite/Magento/Config/Model/Config/Backend/BaseurlTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,33 +95,44 @@ public function validationExceptionDataProvider()
9595
$unsecurePlaceholder = '{{unsecure_base_url}}';
9696
$unsecureSuffix = '{{unsecure_base_url}}test/';
9797
$unsecureWrongSuffix = '{{unsecure_base_url}}test';
98+
$unsecureWrongDomainName = 'http://example.com_test/';
9899
$securePlaceholder = '{{secure_base_url}}';
99100
$secureSuffix = '{{secure_base_url}}test/';
100101
$secureWrongSuffix = '{{secure_base_url}}test';
102+
$secureWrongDomainName = 'https://example.com_test/';
101103

102104
return [
103105
['', 'not a valid URL'],
104106
['', 'example.com'],
105107
['', 'http://example.com'],
106108
['', 'http://example.com/uri'],
109+
['', $unsecureWrongDomainName],
107110
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, ''],
108111
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, $baseSuffix],
109112
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, $unsecureSuffix],
110113
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, $unsecurePlaceholder],
114+
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, $unsecureWrongDomainName],
111115
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_LINK_URL, ''],
112116
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_LINK_URL, $baseSuffix],
113117
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_LINK_URL, $unsecureWrongSuffix],
118+
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_LINK_URL, $unsecureWrongDomainName],
114119
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_MEDIA_URL, $unsecureWrongSuffix],
120+
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_MEDIA_URL, $unsecureWrongDomainName],
115121
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_STATIC_URL, $unsecureWrongSuffix],
122+
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_STATIC_URL, $unsecureWrongDomainName],
116123
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, ''],
117124
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, $baseSuffix],
118125
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, $secureSuffix],
119126
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, $securePlaceholder],
127+
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, $secureWrongDomainName],
120128
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_LINK_URL, ''],
121129
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_LINK_URL, $baseSuffix],
122130
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_LINK_URL, $secureWrongSuffix],
131+
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_LINK_URL, $secureWrongDomainName],
123132
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_MEDIA_URL, $secureWrongSuffix],
133+
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_MEDIA_URL, $secureWrongDomainName],
124134
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_STATIC_URL, $secureWrongSuffix],
135+
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_STATIC_URL, $secureWrongDomainName],
125136
];
126137
}
127138
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Setup\Controller;
7+
8+
use Magento\TestFramework\Helper\Bootstrap;
9+
use Zend\Stdlib\RequestInterface as Request;
10+
use Zend\View\Model\JsonModel;
11+
12+
class UrlCheckTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @var UrlCheck
16+
*/
17+
private $controller;
18+
19+
protected function setUp()
20+
{
21+
$this->controller = Bootstrap::getObjectManager()->create(UrlCheck::class);
22+
}
23+
24+
/**
25+
* @param array $requestContent
26+
* @param bool $successUrl
27+
* @param bool $successSecureUrl
28+
* @return void
29+
* @dataProvider indexActionDataProvider
30+
*/
31+
public function testIndexAction($requestContent, $successUrl, $successSecureUrl)
32+
{
33+
$requestMock = $this->getMockBuilder(Request::class)
34+
->getMockForAbstractClass();
35+
$requestMock->expects($this->once())
36+
->method('getContent')
37+
->willReturn(json_encode($requestContent));
38+
39+
$requestProperty = new \ReflectionProperty(get_class($this->controller), 'request');
40+
$requestProperty->setAccessible(true);
41+
$requestProperty->setValue($this->controller, $requestMock);
42+
43+
$resultModel = new JsonModel(['successUrl' => $successUrl, 'successSecureUrl' => $successSecureUrl]);
44+
45+
$this->assertEquals($resultModel, $this->controller->indexAction());
46+
}
47+
48+
/**
49+
* @return array
50+
*/
51+
public function indexActionDataProvider()
52+
{
53+
return [
54+
[
55+
'requestContent' => [
56+
'address' => [
57+
'actual_base_url' => 'http://example.com/'
58+
],
59+
'https' => [
60+
'text' => 'https://example.com/',
61+
'admin' => true,
62+
'front' => false
63+
],
64+
],
65+
'successUrl' => true,
66+
'successSecureUrl' => true
67+
],
68+
[
69+
'requestContent' => [
70+
'address' => [
71+
'actual_base_url' => 'http://example.com/folder/'
72+
],
73+
'https' => [
74+
'text' => 'https://example.com/folder_name/',
75+
'admin' => false,
76+
'front' => true
77+
],
78+
],
79+
'successUrl' => true,
80+
'successSecureUrl' => true
81+
],
82+
[
83+
'requestContent' => [
84+
'address' => [
85+
'actual_base_url' => 'ftp://example.com/'
86+
],
87+
'https' => [
88+
'text' => 'https://example.com_test/',
89+
'admin' => true,
90+
'front' => true
91+
],
92+
],
93+
'successUrl' => false,
94+
'successSecureUrl' => false
95+
],
96+
];
97+
}
98+
}

0 commit comments

Comments
 (0)