Skip to content

Commit

Permalink
Merge pull request #3596 from magento-engcom/2.3-develop-prs
Browse files Browse the repository at this point in the history
[EngCom] Public Pull Requests - 2.3-develop
  • Loading branch information
sivaschenko authored Jan 14, 2019
2 parents d1f9c6b + caefa5b commit b8e3a0b
Show file tree
Hide file tree
Showing 28 changed files with 737 additions and 75 deletions.
1 change: 1 addition & 0 deletions app/code/Magento/Backend/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<module name="Magento_Backend">
<sequence>
<module name="Magento_Directory"/>
<module name="Magento_Theme"/>
</sequence>
</module>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
-->
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top" />
<columns name="design_config_columns">
<column name="theme_theme_id" component="Magento_Ui/js/grid/columns/select" sortOrder="40">
<settings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@

namespace Magento\Bundle\Setup\Patch\Data;

use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchVersionInterface;
use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Eav\Setup\EavSetup;

/**
* Class UpdateBundleRelatedEntityTytpes
* Class UpdateBundleRelatedEntityTypes
*
* @package Magento\Bundle\Setup\Patch
*/
class UpdateBundleRelatedEntityTytpes implements DataPatchInterface, PatchVersionInterface
class UpdateBundleRelatedEntityTypes implements DataPatchInterface, PatchVersionInterface
{
/**
* @var ModuleDataSetupInterface
Expand All @@ -31,7 +31,7 @@ class UpdateBundleRelatedEntityTytpes implements DataPatchInterface, PatchVersio
private $eavSetupFactory;

/**
* UpdateBundleRelatedEntityTytpes constructor.
* UpdateBundleRelatedEntityTypes constructor.
* @param ModuleDataSetupInterface $moduleDataSetup
* @param EavSetupFactory $eavSetupFactory
*/
Expand All @@ -44,7 +44,7 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function apply()
{
Expand Down Expand Up @@ -177,7 +177,7 @@ private function upgradeShipmentType(EavSetup $eavSetup)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public static function getDependencies()
{
Expand All @@ -187,15 +187,15 @@ public static function getDependencies()
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public static function getVersion()
{
return '2.0.2';
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getAliases()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ class DefaultValidator extends \Magento\Framework\Validator\AbstractValidator
*/
protected $priceTypes;

/**
* @var \Magento\Framework\Locale\FormatInterface
*/
private $localeFormat;

/**
* @param \Magento\Catalog\Model\ProductOptions\ConfigInterface $productOptionConfig
* @param \Magento\Catalog\Model\Config\Source\Product\Options\Price $priceConfig
* @param \Magento\Framework\Locale\FormatInterface|null $localeFormat
*/
public function __construct(
\Magento\Catalog\Model\ProductOptions\ConfigInterface $productOptionConfig,
\Magento\Catalog\Model\Config\Source\Product\Options\Price $priceConfig
\Magento\Catalog\Model\Config\Source\Product\Options\Price $priceConfig,
\Magento\Framework\Locale\FormatInterface $localeFormat = null
) {
foreach ($productOptionConfig->getAll() as $option) {
foreach ($option['types'] as $type) {
Expand All @@ -45,6 +52,9 @@ public function __construct(
foreach ($priceConfig->toOptionArray() as $item) {
$this->priceTypes[] = $item['value'];
}

$this->localeFormat = $localeFormat ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Locale\FormatInterface::class);
}

/**
Expand Down Expand Up @@ -137,11 +147,11 @@ protected function validateOptionType(Option $option)
*/
protected function validateOptionValue(Option $option)
{
return $this->isInRange($option->getPriceType(), $this->priceTypes);
return $this->isInRange($option->getPriceType(), $this->priceTypes) && $this->isNumber($option->getPrice());
}

/**
* Check whether value is empty
* Check whether the value is empty
*
* @param mixed $value
* @return bool
Expand All @@ -152,7 +162,7 @@ protected function isEmpty($value)
}

/**
* Check whether value is in range
* Check whether the value is in range
*
* @param string $value
* @param array $range
Expand All @@ -164,13 +174,24 @@ protected function isInRange($value, array $range)
}

/**
* Check whether value is not negative
* Check whether the value is negative
*
* @param string $value
* @return bool
*/
protected function isNegative($value)
{
return (int) $value < 0;
return $this->localeFormat->getNumber($value) < 0;
}

/**
* Check whether the value is a number
*
* @param string $value
* @return bool
*/
public function isNumber($value)
{
return is_numeric($this->localeFormat->getNumber($value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

use Magento\Catalog\Model\Product\Option;

/**
* Select validator class
*/
class Select extends DefaultValidator
{
/**
Expand Down Expand Up @@ -83,7 +86,7 @@ protected function isValidOptionPrice($priceType, $price, $storeId)
if (!$priceType && !$price) {
return true;
}
if (!$this->isInRange($priceType, $this->priceTypes)) {
if (!$this->isInRange($priceType, $this->priceTypes) || !$this->isNumber($price)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class DefaultValidatorTest extends \PHPUnit\Framework\TestCase
*/
protected $valueMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $localeFormatMock;

/**
* @inheritdoc
*/
Expand All @@ -26,6 +31,8 @@ protected function setUp()
$configMock = $this->createMock(\Magento\Catalog\Model\ProductOptions\ConfigInterface::class);
$storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
$priceConfigMock = new \Magento\Catalog\Model\Config\Source\Product\Options\Price($storeManagerMock);
$this->localeFormatMock = $this->createMock(\Magento\Framework\Locale\FormatInterface::class);

$config = [
[
'label' => 'group label 1',
Expand All @@ -51,7 +58,8 @@ protected function setUp()
$configMock->expects($this->once())->method('getAll')->will($this->returnValue($config));
$this->validator = new \Magento\Catalog\Model\Product\Option\Validator\DefaultValidator(
$configMock,
$priceConfigMock
$priceConfigMock,
$this->localeFormatMock
);
}

Expand All @@ -63,10 +71,10 @@ public function isValidTitleDataProvider()
{
$mess = ['option required fields' => 'Missed values for option required fields'];
return [
['option_title', 'name 1.1', 'fixed', new \Magento\Framework\DataObject(['store_id' => 1]), [], true],
['option_title', 'name 1.1', 'fixed', new \Magento\Framework\DataObject(['store_id' => 0]), [], true],
[null, 'name 1.1', 'fixed', new \Magento\Framework\DataObject(['store_id' => 1]), [], true],
[null, 'name 1.1', 'fixed', new \Magento\Framework\DataObject(['store_id' => 0]), $mess, false],
['option_title', 'name 1.1', 'fixed', 10, new \Magento\Framework\DataObject(['store_id' => 1]), [], true],
['option_title', 'name 1.1', 'fixed', 10, new \Magento\Framework\DataObject(['store_id' => 0]), [], true],
[null, 'name 1.1', 'fixed', 10, new \Magento\Framework\DataObject(['store_id' => 1]), [], true],
[null, 'name 1.1', 'fixed', 10, new \Magento\Framework\DataObject(['store_id' => 0]), $mess, false],
];
}

Expand All @@ -79,15 +87,18 @@ public function isValidTitleDataProvider()
* @param bool $result
* @dataProvider isValidTitleDataProvider
*/
public function testIsValidTitle($title, $type, $priceType, $product, $messages, $result)
public function testIsValidTitle($title, $type, $priceType, $price, $product, $messages, $result)
{
$methods = ['getTitle', 'getType', 'getPriceType', '__wakeup', 'getProduct'];
$methods = ['getTitle', 'getType', 'getPriceType', 'getPrice', '__wakeup', 'getProduct'];
$valueMock = $this->createPartialMock(\Magento\Catalog\Model\Product\Option::class, $methods);
$valueMock->expects($this->once())->method('getTitle')->will($this->returnValue($title));
$valueMock->expects($this->any())->method('getType')->will($this->returnValue($type));
$valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue($priceType));
// $valueMock->expects($this->once())->method('getPrice')->will($this->returnValue($price));
$valueMock->expects($this->once())->method('getPrice')->will($this->returnValue($price));
$valueMock->expects($this->once())->method('getProduct')->will($this->returnValue($product));

$this->localeFormatMock->expects($this->once())->method('getNumber')->will($this->returnValue($price));

$this->assertEquals($result, $this->validator->isValid($valueMock));
$this->assertEquals($messages, $this->validator->getMessages());
}
Expand Down Expand Up @@ -126,4 +137,43 @@ public function testIsValidFail($product)
$this->assertFalse($this->validator->isValid($valueMock));
$this->assertEquals($messages, $this->validator->getMessages());
}

/**
* Data provider for testValidationNegativePrice
* @return array
*/
public function validationPriceDataProvider()
{
return [
['option_title', 'name 1.1', 'fixed', -12, new \Magento\Framework\DataObject(['store_id' => 1])],
['option_title', 'name 1.1', 'fixed', -12, new \Magento\Framework\DataObject(['store_id' => 0])],
['option_title', 'name 1.1', 'fixed', 12, new \Magento\Framework\DataObject(['store_id' => 1])],
['option_title', 'name 1.1', 'fixed', 12, new \Magento\Framework\DataObject(['store_id' => 0])]
];
}

/**
* @param $title
* @param $type
* @param $priceType
* @param $price
* @param $product
* @dataProvider validationPriceDataProvider
*/
public function testValidationPrice($title, $type, $priceType, $price, $product)
{
$methods = ['getTitle', 'getType', 'getPriceType', 'getPrice', '__wakeup', 'getProduct'];
$valueMock = $this->createPartialMock(\Magento\Catalog\Model\Product\Option::class, $methods);
$valueMock->expects($this->once())->method('getTitle')->will($this->returnValue($title));
$valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue($type));
$valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue($priceType));
$valueMock->expects($this->once())->method('getPrice')->will($this->returnValue($price));
$valueMock->expects($this->once())->method('getProduct')->will($this->returnValue($product));

$this->localeFormatMock->expects($this->once())->method('getNumber')->will($this->returnValue($price));

$messages = [];
$this->assertTrue($this->validator->isValid($valueMock));
$this->assertEquals($messages, $this->validator->getMessages());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class FileTest extends \PHPUnit\Framework\TestCase
*/
protected $valueMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $localeFormatMock;

/**
* @inheritdoc
*/
Expand All @@ -26,6 +31,8 @@ protected function setUp()
$configMock = $this->createMock(\Magento\Catalog\Model\ProductOptions\ConfigInterface::class);
$storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
$priceConfigMock = new \Magento\Catalog\Model\Config\Source\Product\Options\Price($storeManagerMock);
$this->localeFormatMock = $this->createMock(\Magento\Framework\Locale\FormatInterface::class);

$config = [
[
'label' => 'group label 1',
Expand Down Expand Up @@ -53,7 +60,8 @@ protected function setUp()
$this->valueMock = $this->createPartialMock(\Magento\Catalog\Model\Product\Option::class, $methods);
$this->validator = new \Magento\Catalog\Model\Product\Option\Validator\File(
$configMock,
$priceConfigMock
$priceConfigMock,
$this->localeFormatMock
);
}

Expand All @@ -70,6 +78,15 @@ public function testIsValidSuccess()
->willReturn(10);
$this->valueMock->expects($this->once())->method('getImageSizeX')->will($this->returnValue(10));
$this->valueMock->expects($this->once())->method('getImageSizeY')->will($this->returnValue(15));
$this->localeFormatMock->expects($this->at(0))
->method('getNumber')
->with($this->equalTo(10))
->will($this->returnValue(10));
$this->localeFormatMock
->expects($this->at(2))
->method('getNumber')
->with($this->equalTo(15))
->will($this->returnValue(15));
$this->assertEmpty($this->validator->getMessages());
$this->assertTrue($this->validator->isValid($this->valueMock));
}
Expand All @@ -87,6 +104,16 @@ public function testIsValidWithNegativeImageSize()
->willReturn(10);
$this->valueMock->expects($this->once())->method('getImageSizeX')->will($this->returnValue(-10));
$this->valueMock->expects($this->never())->method('getImageSizeY');
$this->localeFormatMock->expects($this->at(0))
->method('getNumber')
->with($this->equalTo(10))
->will($this->returnValue(10));
$this->localeFormatMock
->expects($this->at(1))
->method('getNumber')
->with($this->equalTo(-10))
->will($this->returnValue(-10));

$messages = [
'option values' => 'Invalid option value',
];
Expand All @@ -107,6 +134,15 @@ public function testIsValidWithNegativeImageSizeY()
->willReturn(10);
$this->valueMock->expects($this->once())->method('getImageSizeX')->will($this->returnValue(10));
$this->valueMock->expects($this->once())->method('getImageSizeY')->will($this->returnValue(-10));
$this->localeFormatMock->expects($this->at(0))
->method('getNumber')
->with($this->equalTo(10))
->will($this->returnValue(10));
$this->localeFormatMock
->expects($this->at(2))
->method('getNumber')
->with($this->equalTo(-10))
->will($this->returnValue(-10));
$messages = [
'option values' => 'Invalid option value',
];
Expand Down
Loading

0 comments on commit b8e3a0b

Please sign in to comment.