From dc4de31f3edf9c9e3d56efad36a886e6c8329eb8 Mon Sep 17 00:00:00 2001 From: Danny Verkade Date: Wed, 16 May 2018 23:55:42 +0200 Subject: [PATCH 1/8] Fix #7333 Unable to set negative custom option fixed price in admin view. --- .../Option/Validator/DefaultValidator.php | 19 +++++++++++++++---- .../Model/Product/Option/Validator/Select.php | 2 +- .../Option/Validator/DefaultValidatorTest.php | 14 +++++++------- .../Product/Option/Validator/SelectTest.php | 3 +-- .../Product/Form/Modifier/CustomOptions.php | 2 +- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php b/app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php index 1e5c7f76d829b..a1b80b1ac7c12 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php @@ -132,11 +132,11 @@ protected function validateOptionType(Option $option) */ protected function validateOptionValue(Option $option) { - return $this->isInRange($option->getPriceType(), $this->priceTypes) && !$this->isNegative($option->getPrice()); + 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 @@ -147,7 +147,7 @@ protected function isEmpty($value) } /** - * Check whether value is in range + * Check whether the value is in range * * @param string $value * @param array $range @@ -159,7 +159,7 @@ protected function isInRange($value, array $range) } /** - * Check whether value is not negative + * Check whether the value is negative * * @param string $value * @return bool @@ -168,4 +168,15 @@ protected function isNegative($value) { return intval($value) < 0; } + + /** + * Check whether the value is a number + * + * @param string $value + * @return bool + */ + protected function isNumber($value) + { + return is_numeric($value); + } } diff --git a/app/code/Magento/Catalog/Model/Product/Option/Validator/Select.php b/app/code/Magento/Catalog/Model/Product/Option/Validator/Select.php index f04ab497e1d4f..af37c16c4053e 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Validator/Select.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Validator/Select.php @@ -83,7 +83,7 @@ protected function isValidOptionPrice($priceType, $price, $storeId) if (!$priceType && !$price) { return true; } - if (!$this->isInRange($priceType, $this->priceTypes) || $this->isNegative($price)) { + if (!$this->isInRange($priceType, $this->priceTypes) || !$this->isNumber($price)) { return false; } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php index 1eb5f1a2dacd2..5e208c5d16604 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php @@ -129,11 +129,13 @@ public function testIsValidFail($product) * Data provider for testValidationNegativePrice * @return array */ - public function validationNegativePriceDataProvider() + 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])] ]; } @@ -143,9 +145,9 @@ public function validationNegativePriceDataProvider() * @param $priceType * @param $price * @param $product - * @dataProvider validationNegativePriceDataProvider + * @dataProvider validationPriceDataProvider */ - public function testValidationNegativePrice($title, $type, $priceType, $price, $product) + 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); @@ -155,10 +157,8 @@ public function testValidationNegativePrice($title, $type, $priceType, $price, $ $valueMock->expects($this->once())->method('getPrice')->will($this->returnValue($price)); $valueMock->expects($this->once())->method('getProduct')->will($this->returnValue($product)); - $messages = [ - 'option values' => 'Invalid option value', - ]; - $this->assertFalse($this->validator->isValid($valueMock)); + $messages = []; + $this->assertTrue($this->validator->isValid($valueMock)); $this->assertEquals($messages, $this->validator->getMessages()); } } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/SelectTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/SelectTest.php index 046ee703c850e..924893bce23a4 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/SelectTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/SelectTest.php @@ -87,7 +87,7 @@ public function isValidSuccessDataProvider() ] ], [ - false, + true, [ 'title' => 'Some Title', 'price_type' => 'fixed', @@ -157,7 +157,6 @@ public function testIsValidateWithInvalidData($priceType, $price, $title) public function isValidateWithInvalidDataDataProvider() { return [ - 'invalid_price' => ['fixed', -10, 'Title'], 'invalid_price_type' => ['some_value', '10', 'Title'], 'empty_title' => ['fixed', 10, null] ]; diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php index 7196a721f1d02..e557c8a377681 100755 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php @@ -923,7 +923,7 @@ protected function getPriceFieldConfig($sortOrder) 'addbeforePool' => $this->productOptionsPrice->prefixesToOptionArray(), 'sortOrder' => $sortOrder, 'validation' => [ - 'validate-zero-or-greater' => true + 'validate-number' => true ], ], ], From f7aab572bd188a002717a11f69d5bf572427dabd Mon Sep 17 00:00:00 2001 From: Danny Verkade Date: Sat, 2 Jun 2018 15:18:15 +0200 Subject: [PATCH 2/8] magento/magento2##7333: Unable to set negative custom option fixed price in admin view. - Fixed unit tests - Fixed integration tests - Changed defaultvalidator to have the locale format interface. Because a value entered in the backoffice of Magento is passed as the value like "40,000.00", which needs to be converted to a float in order to do a valid check on it. --- .../Option/Validator/DefaultValidator.php | 16 ++++++-- .../Option/Validator/DefaultValidatorTest.php | 15 +++++++- .../Product/Option/Validator/FileTest.php | 38 ++++++++++++++++++- .../Product/Option/Validator/SelectTest.php | 17 ++++++++- .../Product/Option/Validator/TextTest.php | 22 ++++++++++- 5 files changed, 101 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php b/app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php index a1b80b1ac7c12..a01bc6b3e413f 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php @@ -25,13 +25,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) { @@ -42,6 +49,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); } /** @@ -166,7 +176,7 @@ protected function isInRange($value, array $range) */ protected function isNegative($value) { - return intval($value) < 0; + return $this->localeFormat->getNumber($value) < 0; } /** @@ -177,6 +187,6 @@ protected function isNegative($value) */ protected function isNumber($value) { - return is_numeric($value); + return is_numeric($this->localeFormat->getNumber($value)); } } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php index 5e208c5d16604..40c37731c0474 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php @@ -18,11 +18,18 @@ class DefaultValidatorTest extends \PHPUnit\Framework\TestCase */ protected $valueMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $localeFormatMock; + 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', @@ -48,7 +55,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 ); } @@ -86,6 +94,9 @@ public function testIsValidTitle($title, $type, $priceType, $price, $product, $m $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)); + $this->assertEquals($result, $this->validator->isValid($valueMock)); $this->assertEquals($messages, $this->validator->getMessages()); } @@ -157,6 +168,8 @@ public function testValidationPrice($title, $type, $priceType, $price, $product) $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()); diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/FileTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/FileTest.php index 3c06db0e7ce5f..f87bcb5d9bb06 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/FileTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/FileTest.php @@ -18,11 +18,18 @@ class FileTest extends \PHPUnit\Framework\TestCase */ protected $valueMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $localeFormatMock; + 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', @@ -50,7 +57,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 ); } @@ -62,6 +70,15 @@ public function testIsValidSuccess() $this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(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)); } @@ -74,6 +91,16 @@ public function testIsValidWithNegativeImageSize() $this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(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', ]; @@ -89,6 +116,15 @@ public function testIsValidWithNegativeImageSizeY() $this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(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', ]; diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/SelectTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/SelectTest.php index 924893bce23a4..032eb624ed502 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/SelectTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/SelectTest.php @@ -18,11 +18,17 @@ class SelectTest extends \PHPUnit\Framework\TestCase */ protected $valueMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $localeFormatMock; + 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', @@ -50,7 +56,8 @@ protected function setUp() $this->valueMock = $this->createPartialMock(\Magento\Catalog\Model\Product\Option::class, $methods, []); $this->validator = new \Magento\Catalog\Model\Product\Option\Validator\Select( $configMock, - $priceConfigMock + $priceConfigMock, + $this->localeFormatMock ); } @@ -66,6 +73,12 @@ public function testIsValidSuccess($expectedResult, array $value) $this->valueMock->expects($this->never())->method('getPriceType'); $this->valueMock->expects($this->never())->method('getPrice'); $this->valueMock->expects($this->any())->method('getData')->with('values')->will($this->returnValue([$value])); + if (isset($value['price'])) { + $this->localeFormatMock + ->expects($this->once()) + ->method('getNumber') + ->will($this->returnValue($value['price'])); + } $this->assertEquals($expectedResult, $this->validator->isValid($this->valueMock)); } @@ -108,6 +121,7 @@ public function testIsValidateWithInvalidOptionValues() ->method('getData') ->with('values') ->will($this->returnValue('invalid_data')); + $messages = [ 'option values' => 'Invalid option value', ]; @@ -147,6 +161,7 @@ public function testIsValidateWithInvalidData($priceType, $price, $title) $this->valueMock->expects($this->never())->method('getPriceType'); $this->valueMock->expects($this->never())->method('getPrice'); $this->valueMock->expects($this->any())->method('getData')->with('values')->will($this->returnValue([$value])); + $this->localeFormatMock->expects($this->any())->method('getNumber')->will($this->returnValue($price)); $messages = [ 'option values' => 'Invalid option value', ]; diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/TextTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/TextTest.php index cf31d67817684..f3951081b37af 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/TextTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/TextTest.php @@ -18,11 +18,17 @@ class TextTest extends \PHPUnit\Framework\TestCase */ protected $valueMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $localeFormatMock; + 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', @@ -50,7 +56,8 @@ protected function setUp() $this->valueMock = $this->createPartialMock(\Magento\Catalog\Model\Product\Option::class, $methods); $this->validator = new \Magento\Catalog\Model\Product\Option\Validator\Text( $configMock, - $priceConfigMock + $priceConfigMock, + $this->localeFormatMock ); } @@ -61,6 +68,10 @@ public function testIsValidSuccess() $this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed')); $this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10)); $this->valueMock->expects($this->once())->method('getMaxCharacters')->will($this->returnValue(10)); + $this->localeFormatMock->expects($this->exactly(2)) + ->method('getNumber') + ->with($this->equalTo(10)) + ->will($this->returnValue(10)); $this->assertTrue($this->validator->isValid($this->valueMock)); $this->assertEmpty($this->validator->getMessages()); } @@ -72,6 +83,15 @@ public function testIsValidWithNegativeMaxCharacters() $this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed')); $this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10)); $this->valueMock->expects($this->once())->method('getMaxCharacters')->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(1)) + ->method('getNumber') + ->with($this->equalTo(-10)) + ->will($this->returnValue(-10)); $messages = [ 'option values' => 'Invalid option value', ]; From 9a8e7afa278913afffda7dacf5de3355c58965ae Mon Sep 17 00:00:00 2001 From: Danny Verkade Date: Tue, 5 Jun 2018 11:42:21 +0200 Subject: [PATCH 3/8] magento/magento2#7333: Unable to set negative custom option fixed price in admin view. - Changed validator method to public --- .../Catalog/Model/Product/Option/Validator/DefaultValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php b/app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php index a01bc6b3e413f..838d92fb5d038 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php @@ -185,7 +185,7 @@ protected function isNegative($value) * @param string $value * @return bool */ - protected function isNumber($value) + public function isNumber($value) { return is_numeric($this->localeFormat->getNumber($value)); } From 04caefa9b6c9bfe4fea6dc032b8e3cb61000f970 Mon Sep 17 00:00:00 2001 From: Danny Verkade Date: Tue, 10 Jul 2018 09:12:55 -0400 Subject: [PATCH 4/8] Fixed API test. --- .../Magento/Catalog/Api/_files/product_options.php | 12 +++++++++++- .../Catalog/Api/_files/product_options_negative.php | 11 ----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options.php index 144f3a9926fe3..955322929762d 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options.php @@ -10,7 +10,7 @@ 'type' => 'field', 'sort_order' => 1, 'is_require' => 1, - 'price' => 10, + 'price' => -10, 'price_type' => 'fixed', 'sku' => 'sku1', 'max_characters' => 10, @@ -153,4 +153,14 @@ 'price_type' => 'fixed', 'sku' => 'time option sku', ], + [ + 'title' => 'test negative price', + 'type' => 'field', + 'sort_order' => 1, + 'is_require' => 1, + 'price' => -10, + 'price_type' => 'fixed', + 'sku' => 'sku1', + 'max_characters' => 10, + ], ]; diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_negative.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_negative.php index 5d2737b3aa532..50b68a2653ed3 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_negative.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_negative.php @@ -15,17 +15,6 @@ 'sku' => 'sku1', 'max_characters' => 10, ], - 'negative_price' => [ - 'title' => 'area option', - 'type' => 'area', - 'sort_order' => 2, - 'is_require' => 0, - 'price' => -20, - 'price_type' => 'percent', - 'sku' => 'sku2', - 'max_characters' => 20, - - ], 'negative_value_of_image_size' => [ 'title' => 'file option', 'type' => 'file', From d43a52f4d919d0537a61028869f35a1f225aa324 Mon Sep 17 00:00:00 2001 From: Danny Verkade Date: Wed, 5 Sep 2018 10:33:27 +0200 Subject: [PATCH 5/8] Resolved merge conflict with merging 2.3 develop branch. --- .../Model/Product/Option/Validator/DefaultValidatorTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php index 2ac000499a220..82019db2e128f 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php @@ -137,7 +137,6 @@ public function testIsValidFail($product) $this->assertFalse($this->validator->isValid($valueMock)); $this->assertEquals($messages, $this->validator->getMessages()); } -<<<<<<< HEAD /** * Data provider for testValidationNegativePrice @@ -177,6 +176,4 @@ public function testValidationPrice($title, $type, $priceType, $price, $product) $this->assertTrue($this->validator->isValid($valueMock)); $this->assertEquals($messages, $this->validator->getMessages()); } -======= ->>>>>>> 2.3-develop } From d66329a3f49c96525b998227505be47163a7e4de Mon Sep 17 00:00:00 2001 From: Danny Verkade Date: Wed, 5 Sep 2018 10:53:10 +0200 Subject: [PATCH 6/8] Fixed DefaultValidatorTest --- .../Option/Validator/DefaultValidatorTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php index 82019db2e128f..7c2ec8abb768a 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php @@ -71,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], ]; } @@ -87,14 +87,14 @@ 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)); From 08ea73c66f41863dc5f75ec60a25e1ba517cbb6b Mon Sep 17 00:00:00 2001 From: Danny Verkade Date: Sun, 30 Sep 2018 21:28:54 +0800 Subject: [PATCH 7/8] Removed negative price from product options test file. --- .../Magento/Catalog/Api/_files/product_options.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options.php index 955322929762d..e61e6061f4fc2 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options.php @@ -153,14 +153,4 @@ 'price_type' => 'fixed', 'sku' => 'time option sku', ], - [ - 'title' => 'test negative price', - 'type' => 'field', - 'sort_order' => 1, - 'is_require' => 1, - 'price' => -10, - 'price_type' => 'fixed', - 'sku' => 'sku1', - 'max_characters' => 10, - ], -]; +]; \ No newline at end of file From 4927e565cc54f9395ba8ef4bcf3d945cd3020052 Mon Sep 17 00:00:00 2001 From: Danny Verkade Date: Wed, 3 Oct 2018 10:29:15 +0200 Subject: [PATCH 8/8] Fixed coding style errors. --- .../Magento/Catalog/Model/Product/Option/Validator/Select.php | 3 +++ .../testsuite/Magento/Catalog/Api/_files/product_options.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/Product/Option/Validator/Select.php b/app/code/Magento/Catalog/Model/Product/Option/Validator/Select.php index af37c16c4053e..209531f599811 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Validator/Select.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Validator/Select.php @@ -8,6 +8,9 @@ use Magento\Catalog\Model\Product\Option; +/** + * Select validator class + */ class Select extends DefaultValidator { /** diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options.php index e61e6061f4fc2..8a00de1be094f 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options.php @@ -153,4 +153,4 @@ 'price_type' => 'fixed', 'sku' => 'time option sku', ], -]; \ No newline at end of file +];