Skip to content

Commit 338b958

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-73774' into 2.3-develop-pr1
2 parents 6f66e95 + 7d73804 commit 338b958

File tree

13 files changed

+111
-86
lines changed

13 files changed

+111
-86
lines changed

app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ protected function validateOptionType(Option $option)
132132
*/
133133
protected function validateOptionValue(Option $option)
134134
{
135-
return $this->isInRange($option->getPriceType(), $this->priceTypes) && !$this->isNegative($option->getPrice());
135+
return $this->isInRange($option->getPriceType(), $this->priceTypes);
136136
}
137137

138138
/**

app/code/Magento/Catalog/Model/Product/Option/Validator/Select.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected function isValidOptionPrice($priceType, $price, $storeId)
8383
if (!$priceType && !$price) {
8484
return true;
8585
}
86-
if (!$this->isInRange($priceType, $this->priceTypes) || $this->isNegative($price)) {
86+
if (!$this->isInRange($priceType, $this->priceTypes)) {
8787
return false;
8888
}
8989

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class DefaultValidatorTest extends \PHPUnit\Framework\TestCase
1818
*/
1919
protected $valueMock;
2020

21+
/**
22+
* @inheritdoc
23+
*/
2124
protected function setUp()
2225
{
2326
$configMock = $this->createMock(\Magento\Catalog\Model\ProductOptions\ConfigInterface::class);
@@ -60,31 +63,30 @@ public function isValidTitleDataProvider()
6063
{
6164
$mess = ['option required fields' => 'Missed values for option required fields'];
6265
return [
63-
['option_title', 'name 1.1', 'fixed', 10, new \Magento\Framework\DataObject(['store_id' => 1]), [], true],
64-
['option_title', 'name 1.1', 'fixed', 10, new \Magento\Framework\DataObject(['store_id' => 0]), [], true],
65-
[null, 'name 1.1', 'fixed', 10, new \Magento\Framework\DataObject(['store_id' => 1]), [], true],
66-
[null, 'name 1.1', 'fixed', 10, new \Magento\Framework\DataObject(['store_id' => 0]), $mess, false],
66+
['option_title', 'name 1.1', 'fixed', new \Magento\Framework\DataObject(['store_id' => 1]), [], true],
67+
['option_title', 'name 1.1', 'fixed', new \Magento\Framework\DataObject(['store_id' => 0]), [], true],
68+
[null, 'name 1.1', 'fixed', new \Magento\Framework\DataObject(['store_id' => 1]), [], true],
69+
[null, 'name 1.1', 'fixed', new \Magento\Framework\DataObject(['store_id' => 0]), $mess, false],
6770
];
6871
}
6972

7073
/**
71-
* @param $title
72-
* @param $type
73-
* @param $priceType
74-
* @param $price
75-
* @param $product
76-
* @param $messages
77-
* @param $result
74+
* @param string $title
75+
* @param string $type
76+
* @param string $priceType
77+
* @param \Magento\Framework\DataObject $product
78+
* @param array $messages
79+
* @param bool $result
7880
* @dataProvider isValidTitleDataProvider
7981
*/
80-
public function testIsValidTitle($title, $type, $priceType, $price, $product, $messages, $result)
82+
public function testIsValidTitle($title, $type, $priceType, $product, $messages, $result)
8183
{
82-
$methods = ['getTitle', 'getType', 'getPriceType', 'getPrice', '__wakeup', 'getProduct'];
84+
$methods = ['getTitle', 'getType', 'getPriceType', '__wakeup', 'getProduct'];
8385
$valueMock = $this->createPartialMock(\Magento\Catalog\Model\Product\Option::class, $methods);
8486
$valueMock->expects($this->once())->method('getTitle')->will($this->returnValue($title));
8587
$valueMock->expects($this->any())->method('getType')->will($this->returnValue($type));
8688
$valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue($priceType));
87-
$valueMock->expects($this->once())->method('getPrice')->will($this->returnValue($price));
89+
// $valueMock->expects($this->once())->method('getPrice')->will($this->returnValue($price));
8890
$valueMock->expects($this->once())->method('getProduct')->will($this->returnValue($product));
8991
$this->assertEquals($result, $this->validator->isValid($valueMock));
9092
$this->assertEquals($messages, $this->validator->getMessages());
@@ -104,7 +106,7 @@ public function isValidFailDataProvider()
104106
}
105107

106108
/**
107-
* @param $product
109+
* @param \Magento\Framework\DataObject $product
108110
* @dataProvider isValidFailDataProvider
109111
*/
110112
public function testIsValidFail($product)
@@ -124,41 +126,4 @@ public function testIsValidFail($product)
124126
$this->assertFalse($this->validator->isValid($valueMock));
125127
$this->assertEquals($messages, $this->validator->getMessages());
126128
}
127-
128-
/**
129-
* Data provider for testValidationNegativePrice
130-
* @return array
131-
*/
132-
public function validationNegativePriceDataProvider()
133-
{
134-
return [
135-
['option_title', 'name 1.1', 'fixed', -12, new \Magento\Framework\DataObject(['store_id' => 1])],
136-
['option_title', 'name 1.1', 'fixed', -12, new \Magento\Framework\DataObject(['store_id' => 0])],
137-
];
138-
}
139-
140-
/**
141-
* @param $title
142-
* @param $type
143-
* @param $priceType
144-
* @param $price
145-
* @param $product
146-
* @dataProvider validationNegativePriceDataProvider
147-
*/
148-
public function testValidationNegativePrice($title, $type, $priceType, $price, $product)
149-
{
150-
$methods = ['getTitle', 'getType', 'getPriceType', 'getPrice', '__wakeup', 'getProduct'];
151-
$valueMock = $this->createPartialMock(\Magento\Catalog\Model\Product\Option::class, $methods);
152-
$valueMock->expects($this->once())->method('getTitle')->will($this->returnValue($title));
153-
$valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue($type));
154-
$valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue($priceType));
155-
$valueMock->expects($this->once())->method('getPrice')->will($this->returnValue($price));
156-
$valueMock->expects($this->once())->method('getProduct')->will($this->returnValue($product));
157-
158-
$messages = [
159-
'option values' => 'Invalid option value',
160-
];
161-
$this->assertFalse($this->validator->isValid($valueMock));
162-
$this->assertEquals($messages, $this->validator->getMessages());
163-
}
164129
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/FileTest.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class FileTest extends \PHPUnit\Framework\TestCase
1818
*/
1919
protected $valueMock;
2020

21+
/**
22+
* @inheritdoc
23+
*/
2124
protected function setUp()
2225
{
2326
$configMock = $this->createMock(\Magento\Catalog\Model\ProductOptions\ConfigInterface::class);
@@ -54,24 +57,34 @@ protected function setUp()
5457
);
5558
}
5659

60+
/**
61+
* @return void
62+
*/
5763
public function testIsValidSuccess()
5864
{
5965
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
6066
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
61-
$this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed'));
62-
$this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10));
67+
$this->valueMock->method('getPriceType')
68+
->willReturn('fixed');
69+
$this->valueMock->method('getPrice')
70+
->willReturn(10);
6371
$this->valueMock->expects($this->once())->method('getImageSizeX')->will($this->returnValue(10));
6472
$this->valueMock->expects($this->once())->method('getImageSizeY')->will($this->returnValue(15));
6573
$this->assertEmpty($this->validator->getMessages());
6674
$this->assertTrue($this->validator->isValid($this->valueMock));
6775
}
6876

77+
/**
78+
* @return void
79+
*/
6980
public function testIsValidWithNegativeImageSize()
7081
{
7182
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
7283
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
73-
$this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed'));
74-
$this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10));
84+
$this->valueMock->method('getPriceType')
85+
->willReturn('fixed');
86+
$this->valueMock->method('getPrice')
87+
->willReturn(10);
7588
$this->valueMock->expects($this->once())->method('getImageSizeX')->will($this->returnValue(-10));
7689
$this->valueMock->expects($this->never())->method('getImageSizeY');
7790
$messages = [
@@ -81,12 +94,17 @@ public function testIsValidWithNegativeImageSize()
8194
$this->assertEquals($messages, $this->validator->getMessages());
8295
}
8396

97+
/**
98+
* @return void
99+
*/
84100
public function testIsValidWithNegativeImageSizeY()
85101
{
86102
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
87103
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
88-
$this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed'));
89-
$this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10));
104+
$this->valueMock->method('getPriceType')
105+
->willReturn('fixed');
106+
$this->valueMock->method('getPrice')
107+
->willReturn(10);
90108
$this->valueMock->expects($this->once())->method('getImageSizeX')->will($this->returnValue(10));
91109
$this->valueMock->expects($this->once())->method('getImageSizeY')->will($this->returnValue(-10));
92110
$messages = [

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/SelectTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class SelectTest extends \PHPUnit\Framework\TestCase
1818
*/
1919
protected $valueMock;
2020

21+
/**
22+
* @inheritdoc
23+
*/
2124
protected function setUp()
2225
{
2326
$configMock = $this->createMock(\Magento\Catalog\Model\ProductOptions\ConfigInterface::class);
@@ -90,7 +93,7 @@ public function isValidSuccessDataProvider()
9093
]
9194
],
9295
[
93-
false,
96+
true,
9497
[
9598
'title' => 'Some Title',
9699
'price_type' => 'fixed',
@@ -100,6 +103,9 @@ public function isValidSuccessDataProvider()
100103
];
101104
}
102105

106+
/**
107+
* @return void
108+
*/
103109
public function testIsValidateWithInvalidOptionValues()
104110
{
105111
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
@@ -118,6 +124,9 @@ public function testIsValidateWithInvalidOptionValues()
118124
$this->assertEquals($messages, $this->validator->getMessages());
119125
}
120126

127+
/**
128+
* @return void
129+
*/
121130
public function testIsValidateWithEmptyValues()
122131
{
123132
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
@@ -163,7 +172,6 @@ public function testIsValidateWithInvalidData($priceType, $price, $title)
163172
public function isValidateWithInvalidDataDataProvider()
164173
{
165174
return [
166-
'invalid_price' => ['fixed', -10, 'Title'],
167175
'invalid_price_type' => ['some_value', '10', 'Title'],
168176
'empty_title' => ['fixed', 10, null]
169177
];

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/TextTest.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class TextTest extends \PHPUnit\Framework\TestCase
1818
*/
1919
protected $valueMock;
2020

21+
/**
22+
* @inheritdoc
23+
*/
2124
protected function setUp()
2225
{
2326
$configMock = $this->createMock(\Magento\Catalog\Model\ProductOptions\ConfigInterface::class);
@@ -54,23 +57,33 @@ protected function setUp()
5457
);
5558
}
5659

60+
/**
61+
* @return void
62+
*/
5763
public function testIsValidSuccess()
5864
{
5965
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
6066
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
61-
$this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed'));
62-
$this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10));
67+
$this->valueMock->method('getPriceType')
68+
->willReturn('fixed');
69+
$this->valueMock->method('getPrice')
70+
->willReturn(10);
6371
$this->valueMock->expects($this->once())->method('getMaxCharacters')->will($this->returnValue(10));
6472
$this->assertTrue($this->validator->isValid($this->valueMock));
6573
$this->assertEmpty($this->validator->getMessages());
6674
}
6775

76+
/**
77+
* @return void
78+
*/
6879
public function testIsValidWithNegativeMaxCharacters()
6980
{
7081
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
7182
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
72-
$this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed'));
73-
$this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10));
83+
$this->valueMock->method('getPriceType')
84+
->willReturn('fixed');
85+
$this->valueMock->method('getPrice')
86+
->willReturn(10);
7487
$this->valueMock->expects($this->once())->method('getMaxCharacters')->will($this->returnValue(-10));
7588
$messages = [
7689
'option values' => 'Invalid option value',

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function __construct(
166166
}
167167

168168
/**
169-
* {@inheritdoc}
169+
* @inheritdoc
170170
* @since 101.0.0
171171
*/
172172
public function modifyData(array $data)
@@ -226,7 +226,7 @@ protected function formatPriceByPath($path, array $data)
226226
}
227227

228228
/**
229-
* {@inheritdoc}
229+
* @inheritdoc
230230
* @since 101.0.0
231231
*/
232232
public function modifyMeta(array $meta)
@@ -923,7 +923,7 @@ protected function getPriceFieldConfig($sortOrder)
923923
'addbeforePool' => $this->productOptionsPrice->prefixesToOptionArray(),
924924
'sortOrder' => $sortOrder,
925925
'validation' => [
926-
'validate-zero-or-greater' => true
926+
'validate-number' => true
927927
],
928928
],
929929
],

dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'type' => 'field',
1111
'sort_order' => 1,
1212
'is_require' => 1,
13-
'price' => 10,
13+
'price' => -10,
1414
'price_type' => 'fixed',
1515
'sku' => 'sku1',
1616
'max_characters' => 10,

dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_negative.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@
1515
'sku' => 'sku1',
1616
'max_characters' => 10,
1717
],
18-
'negative_price' => [
19-
'title' => 'area option',
20-
'type' => 'area',
21-
'sort_order' => 2,
22-
'is_require' => 0,
23-
'price' => -20,
24-
'price_type' => 'percent',
25-
'sku' => 'sku2',
26-
'max_characters' => 20,
27-
28-
],
2918
'negative_value_of_image_size' => [
3019
'title' => 'file option',
3120
'type' => 'file',

dev/tests/integration/testsuite/Magento/Catalog/Model/ProductPriceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ProductPriceTest extends \PHPUnit\Framework\TestCase
3030
private $productRepository;
3131

3232
/**
33-
* @return void
33+
* @inheritdoc
3434
*/
3535
protected function setUp()
3636
{
@@ -107,7 +107,7 @@ public function testGetMinPrice(): void
107107
$collection->load();
108108
/** @var \Magento\Catalog\Model\Product $product */
109109
$product = $collection->getFirstItem();
110-
$this->assertEquals(333, $product->getData('min_price'));
110+
$this->assertEquals(323, $product->getData('min_price'));
111111
}
112112

113113
/**

0 commit comments

Comments
 (0)