Skip to content

Commit

Permalink
Merge pull request #5879 from magento-tsg-csl3/2.4-develop-pr34
Browse files Browse the repository at this point in the history
[TSG-CSL3] For 2.4|2.4 (pr34)
  • Loading branch information
zakdma authored Jul 13, 2020
2 parents 1ee7e1f + e9e8ea5 commit 0516c8b
Show file tree
Hide file tree
Showing 44 changed files with 1,786 additions and 559 deletions.
19 changes: 12 additions & 7 deletions app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Bundle\Model\Product\Type;
use Magento\Bundle\Model\ResourceModel\BundleFactory;
use Magento\Bundle\Model\ResourceModel\Option\Collection;
use Magento\CatalogRule\Model\ResourceModel\Product\CollectionProcessor;
use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection;
use Magento\Bundle\Model\ResourceModel\Selection\CollectionFactory;
use Magento\Bundle\Model\Selection;
Expand Down Expand Up @@ -42,6 +43,8 @@
use PHPUnit\Framework\TestCase;

/**
* Test for bundle product type
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class TypeTest extends TestCase
Expand Down Expand Up @@ -116,6 +119,11 @@ class TypeTest extends TestCase
*/
private $arrayUtility;

/**
* @var CollectionProcessor|MockObject
*/
private $catalogRuleProcessor;

/**
* @return void
*/
Expand Down Expand Up @@ -172,20 +180,20 @@ protected function setUp(): void
->setMethods(['create'])
->disableOriginalConstructor()
->getMock();

$this->serializer = $this->getMockBuilder(Json::class)
->setMethods(null)
->disableOriginalConstructor()
->getMock();

$this->metadataPool = $this->getMockBuilder(MetadataPool::class)
->disableOriginalConstructor()
->getMock();

$this->arrayUtility = $this->getMockBuilder(ArrayUtils::class)
->setMethods(['flatten'])
->disableOriginalConstructor()
->getMock();
$this->catalogRuleProcessor = $this->getMockBuilder(CollectionProcessor::class)
->disableOriginalConstructor()
->getMock();

$objectHelper = new ObjectManager($this);
$this->model = $objectHelper->getObject(
Expand Down Expand Up @@ -1542,7 +1550,7 @@ public function testPrepareForCartAdvancedSpecifyProductOptions()

$this->parentClass($group, $option, $buyRequest, $product);

$product->expects($this->once())
$product->expects($this->any())
->method('getSkipCheckRequiredOption')
->willReturn(true);
$buyRequest->expects($this->once())
Expand Down Expand Up @@ -2424,9 +2432,6 @@ protected function parentClass($group, $option, $buyRequest, $product)
$group->expects($this->once())
->method('setProcessMode')
->willReturnSelf();
$group->expects($this->once())
->method('validateUserValue')
->willReturnSelf();
$group->expects($this->once())
->method('prepareForCart')
->willReturn('someString');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Api;

/**
* Interface to update product attribute option
*
* @api
*/
interface ProductAttributeOptionUpdateInterface
{
/**
* Update attribute option
*
* @param string $attributeCode
* @param int $optionId
* @param \Magento\Eav\Api\Data\AttributeOptionInterface $option
* @return bool
* @throws \Magento\Framework\Exception\StateException
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\InputException
*/
public function update(
string $attributeCode,
int $optionId,
\Magento\Eav\Api\Data\AttributeOptionInterface $option
): bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,39 @@
*/
namespace Magento\Catalog\Model\Product\Attribute;

use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Catalog\Api\ProductAttributeOptionManagementInterface;
use Magento\Catalog\Api\ProductAttributeOptionUpdateInterface;
use Magento\Eav\Api\AttributeOptionManagementInterface;
use Magento\Eav\Api\AttributeOptionUpdateInterface;
use Magento\Eav\Api\Data\AttributeOptionInterface;
use Magento\Framework\Exception\InputException;

/**
* Option management model for product attribute.
*/
class OptionManagement implements \Magento\Catalog\Api\ProductAttributeOptionManagementInterface
class OptionManagement implements ProductAttributeOptionManagementInterface, ProductAttributeOptionUpdateInterface
{
/**
* @var \Magento\Eav\Api\AttributeOptionManagementInterface
* @var AttributeOptionManagementInterface
*/
protected $eavOptionManagement;

/**
* @param \Magento\Eav\Api\AttributeOptionManagementInterface $eavOptionManagement
* @var AttributeOptionUpdateInterface
*/
private $eavOptionUpdate;

/**
* @param AttributeOptionManagementInterface $eavOptionManagement
* @param AttributeOptionUpdateInterface $eavOptionUpdate
*/
public function __construct(
\Magento\Eav\Api\AttributeOptionManagementInterface $eavOptionManagement
AttributeOptionManagementInterface $eavOptionManagement,
AttributeOptionUpdateInterface $eavOptionUpdate
) {
$this->eavOptionManagement = $eavOptionManagement;
$this->eavOptionUpdate = $eavOptionUpdate;
}

/**
Expand All @@ -33,7 +47,7 @@ public function __construct(
public function getItems($attributeCode)
{
return $this->eavOptionManagement->getItems(
\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE,
ProductAttributeInterface::ENTITY_TYPE_CODE,
$attributeCode
);
}
Expand All @@ -44,8 +58,21 @@ public function getItems($attributeCode)
public function add($attributeCode, $option)
{
return $this->eavOptionManagement->add(
\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE,
ProductAttributeInterface::ENTITY_TYPE_CODE,
$attributeCode,
$option
);
}

/**
* @inheritdoc
*/
public function update(string $attributeCode, int $optionId, AttributeOptionInterface $option): bool
{
return $this->eavOptionUpdate->update(
ProductAttributeInterface::ENTITY_TYPE_CODE,
$attributeCode,
$optionId,
$option
);
}
Expand All @@ -60,7 +87,7 @@ public function delete($attributeCode, $optionId)
}

return $this->eavOptionManagement->delete(
\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE,
ProductAttributeInterface::ENTITY_TYPE_CODE,
$attributeCode,
$optionId
);
Expand Down
17 changes: 12 additions & 5 deletions app/code/Magento/Catalog/Model/Product/Option/Type/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
/**
* Catalog product option file type
*
* @author Magento Core Team <[email protected]>
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType
{
Expand Down Expand Up @@ -181,6 +182,7 @@ protected function _getProcessingParams()

/**
* Returns file info array if we need to get file from already existing file.
*
* Or returns null, if we need to get file from uploaded array.
*
* @return null|array
Expand Down Expand Up @@ -262,7 +264,6 @@ public function validateUserValue($values)
. "Make sure the options are entered and try again."
)
);
break;
default:
$this->setUserValue(null);
break;
Expand Down Expand Up @@ -330,7 +331,11 @@ public function prepareForCart()
public function getFormattedOptionValue($optionValue)
{
if ($this->_formattedOptionValue === null) {
$value = $this->serializer->unserialize($optionValue);
try {
$value = $this->serializer->unserialize($optionValue);
} catch (\InvalidArgumentException $e) {
return $optionValue;
}
if ($value === null) {
return $optionValue;
}
Expand Down Expand Up @@ -476,13 +481,13 @@ public function copyQuoteToOrder()
try {
$value = $this->serializer->unserialize($quoteOption->getValue());
if (!isset($value['quote_path'])) {
throw new \Exception();
return $this;
}
$quotePath = $value['quote_path'];
$orderPath = $value['order_path'];

if (!$this->mediaDirectory->isFile($quotePath) || !$this->mediaDirectory->isReadable($quotePath)) {
throw new \Exception();
return $this;
}

if ($this->_coreFileStorageDatabase->checkDbUsage()) {
Expand Down Expand Up @@ -524,6 +529,8 @@ protected function _getOptionDownloadUrl($route, $params)
}

/**
* Prepare size
*
* @param array $value
* @return string
*/
Expand Down
Loading

0 comments on commit 0516c8b

Please sign in to comment.