Skip to content

Commit

Permalink
Merge branch '2.2-develop' into 10128
Browse files Browse the repository at this point in the history
  • Loading branch information
RomaKis committed Nov 14, 2017
2 parents ef165a2 + d4e666f commit f11c0db
Show file tree
Hide file tree
Showing 48 changed files with 1,070 additions and 447 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
?>
<?php
/**
* @see \Magento\Backend\Block\Template
* @see \Magento\Backend\Block\Denied
*/
?>
<hr class="access-denied-hr"/>
Expand All @@ -21,8 +21,13 @@
<li><span><?= $block->escapeHtml(__('Contact a system administrator or store owner to gain permissions.')) ?></span></li>
<li>
<span><?= $block->escapeHtml(__('Return to ')) ?>
<a href="<?= $block->escapeHtmlAttr(__('javascript:history.back()')) ?>">
<?= $block->escapeHtml(__('previous page')) ?></a><?= $block->escapeHtml(__('.')) ?>
<?php if(isset($_SERVER['HTTP_REFERER'])): ?>
<a href="<?= $block->escapeUrl(__($_SERVER['HTTP_REFERER'])) ?>">
<?= $block->escapeHtml(__('previous page')) ?></a><?= $block->escapeHtml(__('.')) ?>
<?php else: ?>
<a href="<?= $block->escapeHtmlAttr(__('javascript:history.back()')) ?>">
<?= $block->escapeHtml(__('previous page')) ?></a><?= $block->escapeHtml(__('.')) ?>
<?php endif ?>
</span>
</li>
</ul>
Expand Down
4 changes: 3 additions & 1 deletion app/code/Magento/Catalog/Model/Category/Link/SaveHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ private function mergeCategoryLinks($newCategoryPositions, $oldCategoryPositions

if ($key === false) {
$result[] = $newCategoryPosition;
} elseif ($oldCategoryPositions[$key]['position'] != $newCategoryPosition['position']) {
} elseif (isset($oldCategoryPositions[$key])
&& $oldCategoryPositions[$key]['position'] != $newCategoryPosition['position']
) {
$result[] = $newCategoryPositions[$key];
unset($oldCategoryPositions[$key]);
}
Expand Down
3 changes: 1 addition & 2 deletions app/code/Magento/Catalog/Model/ResourceModel/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ public function getAttributesUsedForSortBy()
['main_table' => $this->getTable('eav_attribute')]
)->join(
['additional_table' => $this->getTable('catalog_eav_attribute')],
'main_table.attribute_id = additional_table.attribute_id',
[]
'main_table.attribute_id = additional_table.attribute_id'
)->joinLeft(
['al' => $this->getTable('eav_attribute_label')],
'al.attribute_id = main_table.attribute_id AND al.store_id = ' . $this->getStoreId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@ public function getCategoryDataProvider()
],
[], //affected category_ids
],
[
[3], //model category_ids
[
['category_id' => 3, 'position' => 20],
['category_id' => 4, 'position' => 30],
], // dto category links
[
['category_id' => 3, 'position' => 10],
],
[
['category_id' => 3, 'position' => 20],
['category_id' => 4, 'position' => 30],
],
[3, 4], //affected category_ids
],
];
}

Expand Down
107 changes: 107 additions & 0 deletions app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/ConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Test\Unit\Model\ResourceModel;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

/**
* Test for Magento\Catalog\Model\ResourceModel\Config
*/
class ConfigTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Catalog\Model\ResourceModel\Config
*/
private $model;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $resource;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $storeManager;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $eavConfig;

protected function setUp()
{
$objectManager = new ObjectManager($this);

$this->resource = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
$this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
$this->eavConfig = $this->createMock(\Magento\Eav\Model\Config::class);

$this->model = $objectManager->getObject(
\Magento\Catalog\Model\ResourceModel\Config::class,
[
'resource' => $this->resource,
'storeManager' => $this->storeManager,
'eavConfig' => $this->eavConfig,
]
);

parent::setUp();
}

public function testGetAttributesUsedForSortBy()
{
$expression = 'someExpression';
$storeId = 1;
$entityTypeId = 4;

$connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
$selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
$storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
$entityTypeMock = $this->createMock(\Magento\Eav\Model\Entity\Type::class);

$this->resource->expects($this->atLeastOnce())->method('getConnection')->willReturn($connectionMock);

$connectionMock->expects($this->once())->method('getCheckSql')
->with('al.value IS NULL', 'main_table.frontend_label', 'al.value')
->willReturn($expression);
$connectionMock->expects($this->atLeastOnce())->method('select')->willReturn($selectMock);

$this->resource->expects($this->exactly(3))->method('getTableName')->withConsecutive(
['eav_attribute'],
['catalog_eav_attribute'],
['eav_attribute_label']
)->willReturnOnConsecutiveCalls('eav_attribute', 'catalog_eav_attribute', 'eav_attribute_label');

$this->storeManager->expects($this->once())->method('getStore')->willReturn($storeMock);
$storeMock->expects($this->once())->method('getId')->willReturn($storeId);

$this->eavConfig->expects($this->once())->method('getEntityType')->willReturn($entityTypeMock);
$entityTypeMock->expects($this->once())->method('getId')->willReturn($entityTypeId);

$selectMock->expects($this->once())->method('from')
->with(['main_table' => 'eav_attribute'])->willReturn($selectMock);
$selectMock->expects($this->once())->method('join')->with(
['additional_table' => 'catalog_eav_attribute'],
'main_table.attribute_id = additional_table.attribute_id'
)->willReturn($selectMock);
$selectMock->expects($this->once())->method('joinLeft')
->with(
['al' => 'eav_attribute_label'],
'al.attribute_id = main_table.attribute_id AND al.store_id = ' . $storeId,
['store_label' => $expression]
)->willReturn($selectMock);
$selectMock->expects($this->exactly(2))->method('where')->withConsecutive(
['main_table.entity_type_id = ?', $entityTypeId],
['additional_table.used_for_sort_by = ?', 1]
)->willReturn($selectMock);

$connectionMock->expects($this->once())->method('fetchAll')->with($selectMock);

$this->model->getAttributesUsedForSortBy();
}
}
36 changes: 24 additions & 12 deletions app/code/Magento/CatalogUrlRewrite/Model/Storage/DbStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,37 @@
class DbStorage extends BaseDbStorage
{
/**
* @param array $data
* @return \Magento\Framework\DB\Select
* {@inheritDoc}
*/
protected function prepareSelect(array $data)
{
$metadata = [];
if (array_key_exists(UrlRewrite::METADATA, $data)) {
$metadata = $data[UrlRewrite::METADATA];
unset($data[UrlRewrite::METADATA]);
}

$select = $this->connection->select();
$select->from(['url_rewrite' => $this->resource->getTableName('url_rewrite')])
->joinLeft(
['relation' => $this->resource->getTableName(Product::TABLE_NAME)],
'url_rewrite.url_rewrite_id = relation.url_rewrite_id'
)
->where('url_rewrite.entity_id IN (?)', $data['entity_id'])
->where('url_rewrite.entity_type = ?', $data['entity_type'])
->where('url_rewrite.store_id IN (?)', $data['store_id']);
if (empty($data[UrlRewrite::METADATA]['category_id'])) {
$select->from([
'url_rewrite' => $this->resource->getTableName(self::TABLE_NAME)
]);
$select->joinLeft(
['relation' => $this->resource->getTableName(Product::TABLE_NAME)],
'url_rewrite.url_rewrite_id = relation.url_rewrite_id'
);

foreach ($data as $column => $value) {
$select->where('url_rewrite.' . $column . ' IN (?)', $value);
}
if (empty($metadata['category_id'])) {
$select->where('relation.category_id IS NULL');
} else {
$select->where('relation.category_id = ?', $data[UrlRewrite::METADATA]['category_id']);
$select->where(
'relation.category_id = ?',
$metadata['category_id']
);
}

return $select;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Storage;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\CatalogUrlRewrite\Model\Storage\DbStorage;
use PHPUnit\Framework\TestCase;
use Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory;
use PHPUnit_Framework_MockObject_MockObject as Mock;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\DB\Select;
use Magento\Framework\App\ResourceConnection;
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;

class DbStorageTest extends TestCase
{
/**
* @var DbStorage
*/
private $storage;

/**
* @var UrlRewriteFactory|Mock
*/
private $urlRewriteFactory;

/**
* @var DataObjectHelper|Mock
*/
private $dataObjectHelper;

/**
* @var AdapterInterface|Mock
*/
private $connectionMock;

/**
* @var Select|Mock
*/
private $select;

/**
* @var ResourceConnection|Mock
*/
private $resource;

/**
* @inheritDoc
*
* Preparing mocks and target object.
*/
protected function setUp()
{
parent::setUp();

$this->urlRewriteFactory = $this
->getMockBuilder(UrlRewriteFactory::class)
->setMethods(['create'])
->disableOriginalConstructor()
->getMock();
$this->dataObjectHelper = $this->createMock(DataObjectHelper::class);
$this->connectionMock = $this->createMock(AdapterInterface::class);
$this->select = $this->createPartialMock(
Select::class,
['from', 'where', 'deleteFromSelect', 'joinLeft']
);
$this->resource = $this->createMock(ResourceConnection::class);

$this->resource->expects($this->any())
->method('getConnection')
->will($this->returnValue($this->connectionMock));
$this->connectionMock->expects($this->any())
->method('select')
->will($this->returnValue($this->select));

$this->storage = (new ObjectManager($this))->getObject(
DbStorage::class,
[
'urlRewriteFactory' => $this->urlRewriteFactory,
'dataObjectHelper' => $this->dataObjectHelper,
'resource' => $this->resource,
]
);
}

public function testPrepareSelect()
{
//Passing expected parameters, checking select built.
$entityType = 'custom';
$entityId= 42;
$storeId = 0;
$categoryId = 2;
$redirectType = 301;
//Expecting this methods to be called on select
$this->select
->expects($this->at(2))
->method('where')
->with('url_rewrite.entity_id IN (?)', $entityId)
->willReturn($this->select);
$this->select
->expects($this->at(3))
->method('where')
->with('url_rewrite.entity_type IN (?)', $entityType)
->willReturn($this->select);
$this->select
->expects($this->at(4))
->method('where')
->with('url_rewrite.store_id IN (?)', $storeId)
->willReturn($this->select);
$this->select
->expects($this->at(5))
->method('where')
->with('url_rewrite.redirect_type IN (?)', $redirectType)
->willReturn($this->select);
$this->select
->expects($this->at(6))
->method('where')
->with('relation.category_id = ?', $categoryId)
->willReturn($this->select);
//Preparing mocks to be used
$this->select
->expects($this->any())
->method('from')
->willReturn($this->select);
$this->select
->expects($this->any())
->method('joinLeft')
->willReturn($this->select);
//Indirectly calling prepareSelect
$this->storage->findOneByData([
UrlRewrite::ENTITY_ID => $entityId,
UrlRewrite::ENTITY_TYPE => $entityType,
UrlRewrite::STORE_ID => $storeId,
UrlRewrite::REDIRECT_TYPE => $redirectType,
UrlRewrite::METADATA => ['category_id' => $categoryId]
]);
}
}
8 changes: 6 additions & 2 deletions app/code/Magento/Customer/Model/Address/AbstractAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function setData($key, $value = null)
{
if (is_array($key)) {
$key = $this->_implodeArrayField($key);
} elseif (is_array($value) && !empty($value) && $this->isAddressMultilineAttribute($key)) {
} elseif (is_array($value) && $this->isAddressMultilineAttribute($key)) {
$value = $this->_implodeArrayValues($value);
}
return parent::setData($key, $value);
Expand Down Expand Up @@ -309,7 +309,11 @@ protected function _implodeArrayField(array $data)
*/
protected function _implodeArrayValues($value)
{
if (is_array($value) && count($value)) {
if (is_array($value)) {
if (!count($value)) {
return '';
}

$isScalar = false;
foreach ($value as $val) {
if (is_scalar($val)) {
Expand Down
Loading

0 comments on commit f11c0db

Please sign in to comment.