Skip to content

Commit 6b3e454

Browse files
committed
Merge branch '2.2-develop' of https://github.com/magento-helix/magento2ce into MAGETWO-83755
2 parents 954d355 + d4e666f commit 6b3e454

File tree

56 files changed

+1278
-556
lines changed

Some content is hidden

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

56 files changed

+1278
-556
lines changed

app/code/Magento/Backend/view/adminhtml/templates/admin/access_denied.phtml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
?>
1010
<?php
1111
/**
12-
* @see \Magento\Backend\Block\Template
12+
* @see \Magento\Backend\Block\Denied
1313
*/
1414
?>
1515
<hr class="access-denied-hr"/>
@@ -21,8 +21,13 @@
2121
<li><span><?= $block->escapeHtml(__('Contact a system administrator or store owner to gain permissions.')) ?></span></li>
2222
<li>
2323
<span><?= $block->escapeHtml(__('Return to ')) ?>
24-
<a href="<?= $block->escapeHtmlAttr(__('javascript:history.back()')) ?>">
25-
<?= $block->escapeHtml(__('previous page')) ?></a><?= $block->escapeHtml(__('.')) ?>
24+
<?php if(isset($_SERVER['HTTP_REFERER'])): ?>
25+
<a href="<?= $block->escapeUrl(__($_SERVER['HTTP_REFERER'])) ?>">
26+
<?= $block->escapeHtml(__('previous page')) ?></a><?= $block->escapeHtml(__('.')) ?>
27+
<?php else: ?>
28+
<a href="<?= $block->escapeHtmlAttr(__('javascript:history.back()')) ?>">
29+
<?= $block->escapeHtml(__('previous page')) ?></a><?= $block->escapeHtml(__('.')) ?>
30+
<?php endif ?>
2631
</span>
2732
</li>
2833
</ul>

app/code/Magento/Catalog/Model/Category/Link/SaveHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ private function mergeCategoryLinks($newCategoryPositions, $oldCategoryPositions
119119

120120
if ($key === false) {
121121
$result[] = $newCategoryPosition;
122-
} elseif ($oldCategoryPositions[$key]['position'] != $newCategoryPosition['position']) {
122+
} elseif (isset($oldCategoryPositions[$key])
123+
&& $oldCategoryPositions[$key]['position'] != $newCategoryPosition['position']
124+
) {
123125
$result[] = $newCategoryPositions[$key];
124126
unset($oldCategoryPositions[$key]);
125127
}

app/code/Magento/Catalog/Model/ResourceModel/Config.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ public function getAttributesUsedForSortBy()
149149
['main_table' => $this->getTable('eav_attribute')]
150150
)->join(
151151
['additional_table' => $this->getTable('catalog_eav_attribute')],
152-
'main_table.attribute_id = additional_table.attribute_id',
153-
[]
152+
'main_table.attribute_id = additional_table.attribute_id'
154153
)->joinLeft(
155154
['al' => $this->getTable('eav_attribute_label')],
156155
'al.attribute_id = main_table.attribute_id AND al.store_id = ' . $this->getStoreId(),

app/code/Magento/Catalog/Test/Unit/Model/Category/Link/SaveHandlerTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,21 @@ public function getCategoryDataProvider()
197197
],
198198
[], //affected category_ids
199199
],
200+
[
201+
[3], //model category_ids
202+
[
203+
['category_id' => 3, 'position' => 20],
204+
['category_id' => 4, 'position' => 30],
205+
], // dto category links
206+
[
207+
['category_id' => 3, 'position' => 10],
208+
],
209+
[
210+
['category_id' => 3, 'position' => 20],
211+
['category_id' => 4, 'position' => 30],
212+
],
213+
[3, 4], //affected category_ids
214+
],
200215
];
201216
}
202217

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Unit\Model\ResourceModel;
8+
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
11+
/**
12+
* Test for Magento\Catalog\Model\ResourceModel\Config
13+
*/
14+
class ConfigTest extends \PHPUnit\Framework\TestCase
15+
{
16+
/**
17+
* @var \Magento\Catalog\Model\ResourceModel\Config
18+
*/
19+
private $model;
20+
21+
/**
22+
* @var \PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
private $resource;
25+
26+
/**
27+
* @var \PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
private $storeManager;
30+
31+
/**
32+
* @var \PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $eavConfig;
35+
36+
protected function setUp()
37+
{
38+
$objectManager = new ObjectManager($this);
39+
40+
$this->resource = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
41+
$this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
42+
$this->eavConfig = $this->createMock(\Magento\Eav\Model\Config::class);
43+
44+
$this->model = $objectManager->getObject(
45+
\Magento\Catalog\Model\ResourceModel\Config::class,
46+
[
47+
'resource' => $this->resource,
48+
'storeManager' => $this->storeManager,
49+
'eavConfig' => $this->eavConfig,
50+
]
51+
);
52+
53+
parent::setUp();
54+
}
55+
56+
public function testGetAttributesUsedForSortBy()
57+
{
58+
$expression = 'someExpression';
59+
$storeId = 1;
60+
$entityTypeId = 4;
61+
62+
$connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
63+
$selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
64+
$storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
65+
$entityTypeMock = $this->createMock(\Magento\Eav\Model\Entity\Type::class);
66+
67+
$this->resource->expects($this->atLeastOnce())->method('getConnection')->willReturn($connectionMock);
68+
69+
$connectionMock->expects($this->once())->method('getCheckSql')
70+
->with('al.value IS NULL', 'main_table.frontend_label', 'al.value')
71+
->willReturn($expression);
72+
$connectionMock->expects($this->atLeastOnce())->method('select')->willReturn($selectMock);
73+
74+
$this->resource->expects($this->exactly(3))->method('getTableName')->withConsecutive(
75+
['eav_attribute'],
76+
['catalog_eav_attribute'],
77+
['eav_attribute_label']
78+
)->willReturnOnConsecutiveCalls('eav_attribute', 'catalog_eav_attribute', 'eav_attribute_label');
79+
80+
$this->storeManager->expects($this->once())->method('getStore')->willReturn($storeMock);
81+
$storeMock->expects($this->once())->method('getId')->willReturn($storeId);
82+
83+
$this->eavConfig->expects($this->once())->method('getEntityType')->willReturn($entityTypeMock);
84+
$entityTypeMock->expects($this->once())->method('getId')->willReturn($entityTypeId);
85+
86+
$selectMock->expects($this->once())->method('from')
87+
->with(['main_table' => 'eav_attribute'])->willReturn($selectMock);
88+
$selectMock->expects($this->once())->method('join')->with(
89+
['additional_table' => 'catalog_eav_attribute'],
90+
'main_table.attribute_id = additional_table.attribute_id'
91+
)->willReturn($selectMock);
92+
$selectMock->expects($this->once())->method('joinLeft')
93+
->with(
94+
['al' => 'eav_attribute_label'],
95+
'al.attribute_id = main_table.attribute_id AND al.store_id = ' . $storeId,
96+
['store_label' => $expression]
97+
)->willReturn($selectMock);
98+
$selectMock->expects($this->exactly(2))->method('where')->withConsecutive(
99+
['main_table.entity_type_id = ?', $entityTypeId],
100+
['additional_table.used_for_sort_by = ?', 1]
101+
)->willReturn($selectMock);
102+
103+
$connectionMock->expects($this->once())->method('fetchAll')->with($selectMock);
104+
105+
$this->model->getAttributesUsedForSortBy();
106+
}
107+
}

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,37 @@
1212
class DbStorage extends BaseDbStorage
1313
{
1414
/**
15-
* @param array $data
16-
* @return \Magento\Framework\DB\Select
15+
* {@inheritDoc}
1716
*/
1817
protected function prepareSelect(array $data)
1918
{
19+
$metadata = [];
20+
if (array_key_exists(UrlRewrite::METADATA, $data)) {
21+
$metadata = $data[UrlRewrite::METADATA];
22+
unset($data[UrlRewrite::METADATA]);
23+
}
24+
2025
$select = $this->connection->select();
21-
$select->from(['url_rewrite' => $this->resource->getTableName('url_rewrite')])
22-
->joinLeft(
23-
['relation' => $this->resource->getTableName(Product::TABLE_NAME)],
24-
'url_rewrite.url_rewrite_id = relation.url_rewrite_id'
25-
)
26-
->where('url_rewrite.entity_id IN (?)', $data['entity_id'])
27-
->where('url_rewrite.entity_type = ?', $data['entity_type'])
28-
->where('url_rewrite.store_id IN (?)', $data['store_id']);
29-
if (empty($data[UrlRewrite::METADATA]['category_id'])) {
26+
$select->from([
27+
'url_rewrite' => $this->resource->getTableName(self::TABLE_NAME)
28+
]);
29+
$select->joinLeft(
30+
['relation' => $this->resource->getTableName(Product::TABLE_NAME)],
31+
'url_rewrite.url_rewrite_id = relation.url_rewrite_id'
32+
);
33+
34+
foreach ($data as $column => $value) {
35+
$select->where('url_rewrite.' . $column . ' IN (?)', $value);
36+
}
37+
if (empty($metadata['category_id'])) {
3038
$select->where('relation.category_id IS NULL');
3139
} else {
32-
$select->where('relation.category_id = ?', $data[UrlRewrite::METADATA]['category_id']);
40+
$select->where(
41+
'relation.category_id = ?',
42+
$metadata['category_id']
43+
);
3344
}
45+
3446
return $select;
3547
}
3648
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Storage;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9+
use Magento\CatalogUrlRewrite\Model\Storage\DbStorage;
10+
use PHPUnit\Framework\TestCase;
11+
use Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory;
12+
use PHPUnit_Framework_MockObject_MockObject as Mock;
13+
use Magento\Framework\Api\DataObjectHelper;
14+
use Magento\Framework\DB\Adapter\AdapterInterface;
15+
use Magento\Framework\DB\Select;
16+
use Magento\Framework\App\ResourceConnection;
17+
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
18+
19+
class DbStorageTest extends TestCase
20+
{
21+
/**
22+
* @var DbStorage
23+
*/
24+
private $storage;
25+
26+
/**
27+
* @var UrlRewriteFactory|Mock
28+
*/
29+
private $urlRewriteFactory;
30+
31+
/**
32+
* @var DataObjectHelper|Mock
33+
*/
34+
private $dataObjectHelper;
35+
36+
/**
37+
* @var AdapterInterface|Mock
38+
*/
39+
private $connectionMock;
40+
41+
/**
42+
* @var Select|Mock
43+
*/
44+
private $select;
45+
46+
/**
47+
* @var ResourceConnection|Mock
48+
*/
49+
private $resource;
50+
51+
/**
52+
* @inheritDoc
53+
*
54+
* Preparing mocks and target object.
55+
*/
56+
protected function setUp()
57+
{
58+
parent::setUp();
59+
60+
$this->urlRewriteFactory = $this
61+
->getMockBuilder(UrlRewriteFactory::class)
62+
->setMethods(['create'])
63+
->disableOriginalConstructor()
64+
->getMock();
65+
$this->dataObjectHelper = $this->createMock(DataObjectHelper::class);
66+
$this->connectionMock = $this->createMock(AdapterInterface::class);
67+
$this->select = $this->createPartialMock(
68+
Select::class,
69+
['from', 'where', 'deleteFromSelect', 'joinLeft']
70+
);
71+
$this->resource = $this->createMock(ResourceConnection::class);
72+
73+
$this->resource->expects($this->any())
74+
->method('getConnection')
75+
->will($this->returnValue($this->connectionMock));
76+
$this->connectionMock->expects($this->any())
77+
->method('select')
78+
->will($this->returnValue($this->select));
79+
80+
$this->storage = (new ObjectManager($this))->getObject(
81+
DbStorage::class,
82+
[
83+
'urlRewriteFactory' => $this->urlRewriteFactory,
84+
'dataObjectHelper' => $this->dataObjectHelper,
85+
'resource' => $this->resource,
86+
]
87+
);
88+
}
89+
90+
public function testPrepareSelect()
91+
{
92+
//Passing expected parameters, checking select built.
93+
$entityType = 'custom';
94+
$entityId= 42;
95+
$storeId = 0;
96+
$categoryId = 2;
97+
$redirectType = 301;
98+
//Expecting this methods to be called on select
99+
$this->select
100+
->expects($this->at(2))
101+
->method('where')
102+
->with('url_rewrite.entity_id IN (?)', $entityId)
103+
->willReturn($this->select);
104+
$this->select
105+
->expects($this->at(3))
106+
->method('where')
107+
->with('url_rewrite.entity_type IN (?)', $entityType)
108+
->willReturn($this->select);
109+
$this->select
110+
->expects($this->at(4))
111+
->method('where')
112+
->with('url_rewrite.store_id IN (?)', $storeId)
113+
->willReturn($this->select);
114+
$this->select
115+
->expects($this->at(5))
116+
->method('where')
117+
->with('url_rewrite.redirect_type IN (?)', $redirectType)
118+
->willReturn($this->select);
119+
$this->select
120+
->expects($this->at(6))
121+
->method('where')
122+
->with('relation.category_id = ?', $categoryId)
123+
->willReturn($this->select);
124+
//Preparing mocks to be used
125+
$this->select
126+
->expects($this->any())
127+
->method('from')
128+
->willReturn($this->select);
129+
$this->select
130+
->expects($this->any())
131+
->method('joinLeft')
132+
->willReturn($this->select);
133+
//Indirectly calling prepareSelect
134+
$this->storage->findOneByData([
135+
UrlRewrite::ENTITY_ID => $entityId,
136+
UrlRewrite::ENTITY_TYPE => $entityType,
137+
UrlRewrite::STORE_ID => $storeId,
138+
UrlRewrite::REDIRECT_TYPE => $redirectType,
139+
UrlRewrite::METADATA => ['category_id' => $categoryId]
140+
]);
141+
}
142+
}

app/code/Magento/Customer/Model/Address/AbstractAddress.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function setData($key, $value = null)
269269
{
270270
if (is_array($key)) {
271271
$key = $this->_implodeArrayField($key);
272-
} elseif (is_array($value) && !empty($value) && $this->isAddressMultilineAttribute($key)) {
272+
} elseif (is_array($value) && $this->isAddressMultilineAttribute($key)) {
273273
$value = $this->_implodeArrayValues($value);
274274
}
275275
return parent::setData($key, $value);
@@ -309,7 +309,11 @@ protected function _implodeArrayField(array $data)
309309
*/
310310
protected function _implodeArrayValues($value)
311311
{
312-
if (is_array($value) && count($value)) {
312+
if (is_array($value)) {
313+
if (!count($value)) {
314+
return '';
315+
}
316+
313317
$isScalar = false;
314318
foreach ($value as $val) {
315319
if (is_scalar($val)) {

0 commit comments

Comments
 (0)