Skip to content

Commit

Permalink
Merge pull request #4911 from magento-mpi/MPI-PR-2019-10-18
Browse files Browse the repository at this point in the history
MPI-PR-2019-10-18
  • Loading branch information
viktym authored Oct 23, 2019
2 parents 7ad8863 + 67eb89c commit 4003975
Show file tree
Hide file tree
Showing 19 changed files with 327 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function containsValue($entityType, $entity, $attributeCode, $storeId)
if ((int)$storeId === Store::DEFAULT_STORE_ID) {
return false;
}
if ($this->attributesValues === null) {
if (!isset($this->attributesValues[$storeId])) {
$this->initAttributeValues($entityType, $entity, (int)$storeId);
}

Expand Down Expand Up @@ -110,6 +110,8 @@ public function getDefaultValues($entityType, $entity)
}

/**
* Init attribute values.
*
* @param string $entityType
* @param \Magento\Catalog\Model\AbstractModel $entity
* @param int $storeId
Expand Down Expand Up @@ -158,6 +160,8 @@ private function initAttributeValues($entityType, $entity, $storeId)
}

/**
* Returns entity attributes.
*
* @param string $entityType
* @return \Magento\Eav\Api\Data\AttributeInterface[]
*/
Expand Down
32 changes: 21 additions & 11 deletions app/code/Magento/Catalog/Model/Product/Copier.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
namespace Magento\Catalog\Model\Product;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Attribute\ScopeOverriddenValue;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ProductFactory;

/**
* Catalog product copier.
Expand All @@ -28,25 +30,32 @@ class Copier
protected $copyConstructor;

/**
* @var \Magento\Catalog\Model\ProductFactory
* @var ProductFactory
*/
protected $productFactory;

/**
* @var \Magento\Framework\EntityManager\MetadataPool
*/
protected $metadataPool;
/**
* @var ScopeOverriddenValue
*/
private $scopeOverriddenValue;

/**
* @param CopyConstructorInterface $copyConstructor
* @param \Magento\Catalog\Model\ProductFactory $productFactory
* @param ProductFactory $productFactory
* @param ScopeOverriddenValue $scopeOverriddenValue
*/
public function __construct(
CopyConstructorInterface $copyConstructor,
\Magento\Catalog\Model\ProductFactory $productFactory
ProductFactory $productFactory,
ScopeOverriddenValue $scopeOverriddenValue
) {
$this->productFactory = $productFactory;
$this->copyConstructor = $copyConstructor;
$this->scopeOverriddenValue = $scopeOverriddenValue;
}

/**
Expand Down Expand Up @@ -121,19 +130,20 @@ private function setStoresUrl(Product $product, Product $duplicate) : void
$storeIds = $duplicate->getStoreIds();
$productId = $product->getId();
$productResource = $product->getResource();
$defaultUrlKey = $productResource->getAttributeRawValue(
$productId,
'url_key',
\Magento\Store\Model\Store::DEFAULT_STORE_ID
);
$duplicate->setData('save_rewrites_history', false);
foreach ($storeIds as $storeId) {
$useDefault = !$this->scopeOverriddenValue->containsValue(
ProductInterface::class,
$product,
'url_key',
$storeId
);
if ($useDefault) {
continue;
}
$isDuplicateSaved = false;
$duplicate->setStoreId($storeId);
$urlKey = $productResource->getAttributeRawValue($productId, 'url_key', $storeId);
if ($urlKey === $defaultUrlKey) {
continue;
}
do {
$urlKey = $this->modifyUrl($urlKey);
$duplicate->setUrlKey($urlKey);
Expand Down
40 changes: 28 additions & 12 deletions app/code/Magento/Catalog/Test/Unit/Model/Product/CopierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Catalog\Test\Unit\Model\Product;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Attribute\ScopeOverriddenValue;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Copier;

Expand Down Expand Up @@ -46,6 +47,11 @@ class CopierTest extends \PHPUnit\Framework\TestCase
*/
protected $metadata;

/**
* @var ScopeOverriddenValue|\PHPUnit_Framework_MockObject_MockObject
*/
private $scopeOverriddenValue;

protected function setUp()
{
$this->copyConstructorMock = $this->createMock(\Magento\Catalog\Model\Product\CopyConstructorInterface::class);
Expand All @@ -59,6 +65,7 @@ protected function setUp()
$this->optionRepositoryMock;
$this->productMock = $this->createMock(Product::class);
$this->productMock->expects($this->any())->method('getEntityId')->willReturn(1);
$this->scopeOverriddenValue = $this->createMock(ScopeOverriddenValue::class);

$this->metadata = $this->getMockBuilder(\Magento\Framework\EntityManager\EntityMetadata::class)
->disableOriginalConstructor()
Expand All @@ -67,15 +74,20 @@ protected function setUp()
->disableOriginalConstructor()
->getMock();
$metadataPool->expects($this->any())->method('getMetadata')->willReturn($this->metadata);

$this->_model = new Copier(
$this->copyConstructorMock,
$this->productFactoryMock
$this->productFactoryMock,
$this->scopeOverriddenValue
);

$this->setProperties($this->_model, [
'optionRepository' => $this->optionRepositoryMock,
'metadataPool' => $metadataPool,
]);
$this->setProperties(
$this->_model,
[
'optionRepository' => $this->optionRepositoryMock,
'metadataPool' => $metadataPool,
]
);
}

/**
Expand Down Expand Up @@ -103,10 +115,12 @@ public function testCopy()
];
$this->productMock->expects($this->atLeastOnce())->method('getWebsiteIds');
$this->productMock->expects($this->atLeastOnce())->method('getCategoryIds');
$this->productMock->expects($this->any())->method('getData')->willReturnMap([
['', null, $productData],
['linkField', null, '1'],
]);
$this->productMock->expects($this->any())->method('getData')->willReturnMap(
[
['', null, $productData],
['linkField', null, '1'],
]
);

$entityMock = $this->getMockForAbstractClass(
\Magento\Eav\Model\Entity\AbstractEntity::class,
Expand Down Expand Up @@ -191,9 +205,11 @@ public function testCopy()

$this->metadata->expects($this->any())->method('getLinkField')->willReturn('linkField');

$duplicateMock->expects($this->any())->method('getData')->willReturnMap([
['linkField', null, '2'],
]);
$duplicateMock->expects($this->any())->method('getData')->willReturnMap(
[
['linkField', null, '2'],
]
);
$this->optionRepositoryMock->expects($this->once())
->method('duplicate')
->with($this->productMock, $duplicateMock);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogSearch\Test\Unit\Ui\DataProvider\Product;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\CatalogSearch\Model\ResourceModel\Search\Collection as SearchCollection;
use Magento\Framework\Data\Collection;
use Magento\CatalogSearch\Ui\DataProvider\Product\AddFulltextFilterToCollection;

class AddFulltextFilterToCollectionTest extends \PHPUnit\Framework\TestCase
{
/**
* @var SearchCollection|\PHPUnit_Framework_MockObject_MockObject
*/
private $searchCollection;

/**
* @var Collection|\PHPUnit_Framework_MockObject_MockObject
*/
private $collection;

/**
* @var ObjectManagerHelper
*/
private $objectManager;

/**
* @var AddFulltextFilterToCollection
*/
private $model;

protected function setUp()
{
$this->objectManager = new ObjectManagerHelper($this);

$this->searchCollection = $this->getMockBuilder(SearchCollection::class)
->setMethods(['addBackendSearchFilter', 'load', 'getAllIds'])
->disableOriginalConstructor()
->getMock();
$this->searchCollection->expects($this->any())
->method('load')
->willReturnSelf();
$this->collection = $this->getMockBuilder(Collection::class)
->setMethods(['addIdFilter'])
->disableOriginalConstructor()
->getMock();

$this->model = $this->objectManager->getObject(
AddFulltextFilterToCollection::class,
[
'searchCollection' => $this->searchCollection
]
);
}

public function testAddFilter()
{
$this->searchCollection->expects($this->once())
->method('addBackendSearchFilter')
->with('test');
$this->searchCollection->expects($this->once())
->method('getAllIds')
->willReturn([]);
$this->collection->expects($this->once())
->method('addIdFilter')
->with(-1);
$this->model->addFilter($this->collection, 'test', ['fulltext' => 'test']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function addFilter(Collection $collection, $field, $condition = null)
if (isset($condition['fulltext']) && (string)$condition['fulltext'] !== '') {
$this->searchCollection->addBackendSearchFilter($condition['fulltext']);
$productIds = $this->searchCollection->load()->getAllIds();
if (empty($productIds)) {
//add dummy id to prevent returning full unfiltered collection
$productIds = -1;
}
$collection->addIdFilter($productIds);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ define([
* @returns {Boolean} - initial visibility state.
*/
resolveInitialPasswordVisibility: function () {
if (checkoutData.getInputFieldEmailValue() !== '' && checkoutData.getCheckedEmailValue() === '') {
return true;
}

if (checkoutData.getInputFieldEmailValue() !== '') {
return checkoutData.getInputFieldEmailValue() === checkoutData.getCheckedEmailValue();
}
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/Persistent/Model/QuoteManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public function convertCustomerCartToGuest()
->setCustomerEmail(null)
->setCustomerFirstname(null)
->setCustomerLastname(null)
->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID)
->setIsPersistent(false);
$quote->getAddressesCollection()->walk('setCustomerAddressId', ['customerAddressId' => null]);
$quote->getAddressesCollection()->walk('setCustomerId', ['customerId' => null]);
Expand Down
35 changes: 21 additions & 14 deletions app/code/Magento/Persistent/Test/Unit/Model/QuoteManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,28 @@ protected function setUp()
{
$this->persistentSessionMock = $this->createMock(\Magento\Persistent\Helper\Session::class);
$this->sessionMock =
$this->createPartialMock(\Magento\Persistent\Model\Session::class, [
$this->createPartialMock(
\Magento\Persistent\Model\Session::class,
[
'setLoadInactive',
'setCustomerData',
'clearQuote',
'clearStorage',
'getQuote',
'removePersistentCookie',
'__wakeup',
]);
]
);
$this->persistentDataMock = $this->createMock(\Magento\Persistent\Helper\Data::class);
$this->checkoutSessionMock = $this->createMock(\Magento\Checkout\Model\Session::class);

$this->abstractCollectionMock =
$this->createMock(\Magento\Eav\Model\Entity\Collection\AbstractCollection::class);

$this->quoteRepositoryMock = $this->createMock(\Magento\Quote\Api\CartRepositoryInterface::class);
$this->quoteMock = $this->createPartialMock(\Magento\Quote\Model\Quote::class, [
$this->quoteMock = $this->createPartialMock(
\Magento\Quote\Model\Quote::class,
[
'getId',
'getIsPersistent',
'getPaymentsCollection',
Expand All @@ -90,7 +95,8 @@ protected function setUp()
'getIsActive',
'getCustomerId',
'__wakeup'
]);
]
);

$this->model = new QuoteManager(
$this->persistentSessionMock,
Expand Down Expand Up @@ -258,21 +264,22 @@ public function testConvertCustomerCartToGuest()
->method('setCustomerFirstname')->with(null)->willReturn($this->quoteMock);
$this->quoteMock->expects($this->once())
->method('setCustomerLastname')->with(null)->willReturn($this->quoteMock);
$this->quoteMock->expects($this->once())->method('setCustomerGroupId')
->with(\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID)
$this->quoteMock->expects($this->never())->method('setCustomerGroupId')
->willReturn($this->quoteMock);
$this->quoteMock->expects($this->once())
->method('setIsPersistent')->with(false)->willReturn($this->quoteMock);
$this->quoteMock->expects($this->exactly(3))
->method('getAddressesCollection')->willReturn($this->abstractCollectionMock);
$this->abstractCollectionMock->expects($this->exactly(3))->method('walk')->with($this->logicalOr(
$this->equalTo('setCustomerAddressId'),
$this->equalTo($addressArgs),
$this->equalTo('setCustomerId'),
$this->equalTo($customerIdArgs),
$this->equalTo('setEmail'),
$this->equalTo($emailArgs)
));
$this->abstractCollectionMock->expects($this->exactly(3))->method('walk')->with(
$this->logicalOr(
$this->equalTo('setCustomerAddressId'),
$this->equalTo($addressArgs),
$this->equalTo('setCustomerId'),
$this->equalTo($customerIdArgs),
$this->equalTo('setEmail'),
$this->equalTo($emailArgs)
)
);
$this->quoteMock->expects($this->once())->method('collectTotals')->willReturn($this->quoteMock);
$this->persistentSessionMock->expects($this->once())
->method('getSession')->willReturn($this->sessionMock);
Expand Down
Loading

0 comments on commit 4003975

Please sign in to comment.